blob: 7001d64cea4ec2673bae4c7a915e612f73ab6392 [file] [log] [blame]
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +03001#define LOG_TAG "hwc-platform-imagination"
2
3#include "platformimagination.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +03004
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +03005#include <log/log.h>
6#include <xf86drm.h>
7
8#include "img_gralloc1_public.h"
9
10namespace android {
11
12Importer *Importer::CreateInstance(DrmDevice *drm) {
13 ImaginationImporter *importer = new ImaginationImporter(drm);
14 if (!importer)
15 return NULL;
16
17 int ret = importer->Init();
18 if (ret) {
19 ALOGE("Failed to initialize the Imagination importer %d", ret);
20 delete importer;
21 return NULL;
22 }
23 return importer;
24}
25
Roman Stratiienko4163efc2019-12-06 12:30:28 +020026int ImaginationImporter::ConvertBoInfo(buffer_handle_t handle,
27 hwc_drm_bo_t *bo) {
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030028 IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle;
29 if (!hnd)
30 return -EINVAL;
31
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030032 /* Extra bits are responsible for buffer compression and memory layout */
33 if (hnd->iFormat & ~0x10f) {
Roman Stratiienko4163efc2019-12-06 12:30:28 +020034 ALOGV("Special buffer formats are not supported");
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030035 return -EINVAL;
36 }
37
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030038 bo->width = hnd->iWidth;
39 bo->height = hnd->iHeight;
40 bo->usage = hnd->usage;
John Stultzacc1c212020-02-04 21:53:13 +000041 bo->prime_fds[0] = hnd->fd[0];
42 bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
Roman Stratiienko582cb322020-01-23 18:17:41 +020043 bo->hal_format = hnd->iFormat;
44 bo->pixel_stride = hnd->aiStride[0];
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030045
46 switch (hnd->iFormat) {
47#ifdef HAL_PIXEL_FORMAT_BGRX_8888
48 case HAL_PIXEL_FORMAT_BGRX_8888:
49 bo->format = DRM_FORMAT_XRGB8888;
50 break;
51#endif
52 default:
53 bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
54 if (bo->format == DRM_FORMAT_INVALID) {
Roman Stratiienko4163efc2019-12-06 12:30:28 +020055 ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat);
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030056 return -EINVAL;
57 }
58 }
59
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030060 return 0;
61}
62
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030063} // namespace android