blob: ea34ecc49fd86e5056762489d670a5148bd66245 [file] [log] [blame]
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +03001#define LOG_TAG "hwc-platform-imagination"
2
3#include "platformimagination.h"
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +03004#include <log/log.h>
5#include <xf86drm.h>
6
7#include "img_gralloc1_public.h"
8
9namespace android {
10
11Importer *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
Roman Stratiienko4163efc2019-12-06 12:30:28 +020025int ImaginationImporter::ConvertBoInfo(buffer_handle_t handle,
26 hwc_drm_bo_t *bo) {
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030027 IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle;
28 if (!hnd)
29 return -EINVAL;
30
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030031 /* Extra bits are responsible for buffer compression and memory layout */
32 if (hnd->iFormat & ~0x10f) {
Roman Stratiienko4163efc2019-12-06 12:30:28 +020033 ALOGV("Special buffer formats are not supported");
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030034 return -EINVAL;
35 }
36
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030037 bo->width = hnd->iWidth;
38 bo->height = hnd->iHeight;
39 bo->usage = hnd->usage;
Roman Stratiienko4163efc2019-12-06 12:30:28 +020040 bo->prime_fds[0] = hnd->fd[0];
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030041 bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
42
43 switch (hnd->iFormat) {
44#ifdef HAL_PIXEL_FORMAT_BGRX_8888
45 case HAL_PIXEL_FORMAT_BGRX_8888:
46 bo->format = DRM_FORMAT_XRGB8888;
47 break;
48#endif
49 default:
50 bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
51 if (bo->format == DRM_FORMAT_INVALID) {
Roman Stratiienko4163efc2019-12-06 12:30:28 +020052 ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat);
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030053 return -EINVAL;
54 }
55 }
56
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030057 return 0;
58}
59
60std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
61 std::unique_ptr<Planner> planner(new Planner);
62 planner->AddStage<PlanStageGreedy>();
63 return planner;
64}
65} // namespace android