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 | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 4 | |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 5 | #include <log/log.h> |
| 6 | #include <xf86drm.h> |
| 7 | |
| 8 | #include "img_gralloc1_public.h" |
| 9 | |
| 10 | namespace android { |
| 11 | |
| 12 | Importer *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 Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 26 | int ImaginationImporter::ConvertBoInfo(buffer_handle_t handle, |
| 27 | hwc_drm_bo_t *bo) { |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 28 | IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle; |
| 29 | if (!hnd) |
| 30 | return -EINVAL; |
| 31 | |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 32 | /* Extra bits are responsible for buffer compression and memory layout */ |
| 33 | if (hnd->iFormat & ~0x10f) { |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 34 | ALOGV("Special buffer formats are not supported"); |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 35 | return -EINVAL; |
| 36 | } |
| 37 | |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 38 | bo->width = hnd->iWidth; |
| 39 | bo->height = hnd->iHeight; |
| 40 | bo->usage = hnd->usage; |
John Stultz | acc1c21 | 2020-02-04 21:53:13 +0000 | [diff] [blame] | 41 | bo->prime_fds[0] = hnd->fd[0]; |
| 42 | bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3; |
Roman Stratiienko | 582cb32 | 2020-01-23 18:17:41 +0200 | [diff] [blame] | 43 | bo->hal_format = hnd->iFormat; |
| 44 | bo->pixel_stride = hnd->aiStride[0]; |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 45 | |
| 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 Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 55 | ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat); |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 56 | return -EINVAL; |
| 57 | } |
| 58 | } |
| 59 | |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 60 | return 0; |
| 61 | } |
| 62 | |
Roman Stratiienko | e3ed48d | 2019-10-17 17:42:36 +0300 | [diff] [blame] | 63 | } // namespace android |