Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 1 | #define LOG_TAG "hwc-platform-imagination" |
| 2 | |
| 3 | #include "platformimagination.h" |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 4 | #include <log/log.h> |
| 5 | #include <xf86drm.h> |
| 6 | |
| 7 | #include "img_gralloc1_public.h" |
| 8 | |
| 9 | namespace android { |
| 10 | |
| 11 | Importer *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 Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 25 | int ImaginationImporter::ConvertBoInfo(buffer_handle_t handle, |
| 26 | hwc_drm_bo_t *bo) { |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 27 | IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle; |
| 28 | if (!hnd) |
| 29 | return -EINVAL; |
| 30 | |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 31 | /* Extra bits are responsible for buffer compression and memory layout */ |
| 32 | if (hnd->iFormat & ~0x10f) { |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 33 | ALOGV("Special buffer formats are not supported"); |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 34 | return -EINVAL; |
| 35 | } |
| 36 | |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 37 | bo->width = hnd->iWidth; |
| 38 | bo->height = hnd->iHeight; |
| 39 | bo->usage = hnd->usage; |
John Stultz | acc1c21 | 2020-02-04 21:53:13 +0000 | [diff] [blame] | 40 | bo->prime_fds[0] = hnd->fd[0]; |
| 41 | bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3; |
Roman Stratiienko | 582cb32 | 2020-01-23 18:17:41 +0200 | [diff] [blame] | 42 | bo->hal_format = hnd->iFormat; |
| 43 | bo->pixel_stride = hnd->aiStride[0]; |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 44 | |
| 45 | switch (hnd->iFormat) { |
| 46 | #ifdef HAL_PIXEL_FORMAT_BGRX_8888 |
| 47 | case HAL_PIXEL_FORMAT_BGRX_8888: |
| 48 | bo->format = DRM_FORMAT_XRGB8888; |
| 49 | break; |
| 50 | #endif |
| 51 | default: |
| 52 | bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf); |
| 53 | if (bo->format == DRM_FORMAT_INVALID) { |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 54 | ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat); |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 55 | return -EINVAL; |
| 56 | } |
| 57 | } |
| 58 | |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) { |
| 63 | std::unique_ptr<Planner> planner(new Planner); |
| 64 | planner->AddStage<PlanStageGreedy>(); |
| 65 | return planner; |
| 66 | } |
| 67 | } // namespace android |