OSDN Git Service

63d81304de1ebcf20a2103acfb12c5e996ac363c
[android-x86/external-drm_hwcomposer.git] / platform / platformimagination.cpp
1 #define LOG_TAG "hwc-platform-imagination"
2
3 #include "platformimagination.h"
4 #include <log/log.h>
5 #include <xf86drm.h>
6
7 #include "img_gralloc1_public.h"
8
9 namespace android {
10
11 Importer *Importer::CreateInstance(DrmDevice *drm) {
12   ImaginationImporter *importer = new ImaginationImporter(drm);
13   if (!importer)
14     return NULL;
15
16   int ret = importer->Init();
17   if (ret) {
18     ALOGE("Failed to initialize the Imagination importer %d", ret);
19     delete importer;
20     return NULL;
21   }
22   return importer;
23 }
24
25 int ImaginationImporter::ConvertBoInfo(buffer_handle_t handle,
26                                        hwc_drm_bo_t *bo) {
27   IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle;
28   if (!hnd)
29     return -EINVAL;
30
31   /* Extra bits are responsible for buffer compression and memory layout */
32   if (hnd->iFormat & ~0x10f) {
33     ALOGV("Special buffer formats are not supported");
34     return -EINVAL;
35   }
36
37   bo->width = hnd->iWidth;
38   bo->height = hnd->iHeight;
39   bo->usage = hnd->usage;
40   bo->hal_format = hnd->iFormat;
41   bo->pixel_stride = hnd->aiStride[0];
42
43   int sub = std::min(hnd->iNumSubAllocs, HWC_DRM_BO_MAX_PLANES);
44   for (int i = 0; i < sub; i++) {
45     bo->prime_fds[i] = hnd->fd[i];
46     bo->offsets[i] = hnd->aulPlaneOffset[i];
47     bo->pitches[i] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
48   }
49
50   switch (hnd->iFormat) {
51 #ifdef HAL_PIXEL_FORMAT_BGRX_8888
52     case HAL_PIXEL_FORMAT_BGRX_8888:
53       bo->format = DRM_FORMAT_XRGB8888;
54       break;
55 #endif
56     default:
57       bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
58       if (bo->format == DRM_FORMAT_INVALID) {
59         ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat);
60         return -EINVAL;
61       }
62   }
63
64   return 0;
65 }
66
67 std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
68   std::unique_ptr<Planner> planner(new Planner);
69   planner->AddStage<PlanStageGreedy>();
70   return planner;
71 }
72 }  // namespace android