blob: 5e0335ca7ec260e9012ee171d659fc9a235a000b [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
25int ImaginationImporter::ImportBuffer(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 uint32_t gem_handle;
32 int ret = drmPrimeFDToHandle(drm_->fd(), hnd->fd[0], &gem_handle);
33 if (ret) {
34 ALOGE("failed to import prime fd %d ret=%d", hnd->fd[0], ret);
35 return ret;
36 }
37
38 /* Extra bits are responsible for buffer compression and memory layout */
39 if (hnd->iFormat & ~0x10f) {
40 ALOGE("Special buffer formats are not supported");
41 return -EINVAL;
42 }
43
44 memset(bo, 0, sizeof(hwc_drm_bo_t));
45 bo->width = hnd->iWidth;
46 bo->height = hnd->iHeight;
47 bo->usage = hnd->usage;
48 bo->gem_handles[0] = gem_handle;
49 bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
50
51 switch (hnd->iFormat) {
52#ifdef HAL_PIXEL_FORMAT_BGRX_8888
53 case HAL_PIXEL_FORMAT_BGRX_8888:
54 bo->format = DRM_FORMAT_XRGB8888;
55 break;
56#endif
57 default:
58 bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
59 if (bo->format == DRM_FORMAT_INVALID) {
60 ALOGE("Cannot convert hal format to drm format %u", hnd->iFormat);
61 return -EINVAL;
62 }
63 }
64
65 ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format,
66 bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0);
67 if (ret) {
68 ALOGE("could not create drm fb ret: %d", ret);
69 return ret;
70 }
71
Vincent Donnefortf67c3652019-08-02 11:18:35 +010072 ImportHandle(gem_handle);
73
Roman Stratiienkoe3ed48d2019-10-17 17:42:36 +030074 return 0;
75}
76
77std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
78 std::unique_ptr<Planner> planner(new Planner);
79 planner->AddStage<PlanStageGreedy>();
80 return planner;
81}
82} // namespace android