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