blob: 63d81304de1ebcf20a2103acfb12c5e996ac363c [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 Stratiienkob2f2bae2020-01-23 18:17:41 +020040 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 }
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030049
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) {
Roman Stratiienko4163efc2019-12-06 12:30:28 +020059 ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat);
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030060 return -EINVAL;
61 }
62 }
63
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030064 return 0;
65}
66
67std::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