diff options
-rw-r--r-- | platformhisi.cpp | 56 | ||||
-rw-r--r-- | platformhisi.h | 4 |
2 files changed, 58 insertions, 2 deletions
diff --git a/platformhisi.cpp b/platformhisi.cpp index 76fe1e7..9413457 100644 --- a/platformhisi.cpp +++ b/platformhisi.cpp @@ -70,7 +70,52 @@ int HisiImporter::Init() { return 0; } +uint64_t HisiImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags, + bool is_rgb) { + uint64_t features = 0UL; + + if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC) + features |= AFBC_FORMAT_MOD_BLOCK_SIZE_16x16; + + if (flags & MALI_GRALLOC_INTFMT_AFBC_SPLITBLK) + features |= (AFBC_FORMAT_MOD_SPLIT | AFBC_FORMAT_MOD_SPARSE); + + if (flags & MALI_GRALLOC_INTFMT_AFBC_WIDEBLK) + features |= AFBC_FORMAT_MOD_BLOCK_SIZE_32x8; + + if (flags & MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS) + features |= AFBC_FORMAT_MOD_TILED; + + if (features) { + if (is_rgb) + features |= AFBC_FORMAT_MOD_YTR; + + return DRM_FORMAT_MOD_ARM_AFBC(features); + } + + return 0; +} + +bool HisiImporter::IsDrmFormatRgb(uint32_t drm_format) { + switch (drm_format) { + case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_ABGR8888: + case DRM_FORMAT_BGR888: + case DRM_FORMAT_BGR565: + return true; + case DRM_FORMAT_YVU420: + return false; + default: + ALOGE("Unsupported format %u assuming rgb?", drm_format); + return true; + } +} + int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) { + bool is_rgb; + uint64_t modifiers[4] = {0}; + memset(bo, 0, sizeof(hwc_drm_bo_t)); private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>( @@ -94,6 +139,10 @@ int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) { if (fmt < 0) return fmt; + is_rgb = IsDrmFormatRgb(fmt); + modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format, + is_rgb); + bo->width = hnd->width; bo->height = hnd->height; bo->hal_format = hnd->req_format; @@ -129,8 +178,11 @@ int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) { break; } - ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format, - bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0); + ret = drmModeAddFB2WithModifiers(drm_->fd(), bo->width, bo->height, + bo->format, bo->gem_handles, bo->pitches, + bo->offsets, modifiers, &bo->fb_id, + modifiers[0] ? DRM_MODE_FB_MODIFIERS : 0); + if (ret) { ALOGE("could not create drm fb %d", ret); return ret; diff --git a/platformhisi.h b/platformhisi.h index 927da17..14a58b9 100644 --- a/platformhisi.h +++ b/platformhisi.h @@ -39,6 +39,10 @@ class HisiImporter : public DrmGenericImporter { bool CanImportBuffer(buffer_handle_t handle) override; private: + uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags, bool is_rgb); + + bool IsDrmFormatRgb(uint32_t drm_format); + DrmDevice *drm_; const gralloc_module_t *gralloc_; |