summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyan Kumar Halder <ayan.halder@arm.com>2019-01-14 12:47:12 +0000
committerAyan kumar halder <ayan.halder@arm.com>2019-01-31 19:36:14 +0000
commitcc5fca4f9410b39c64900ea627841dfd9ea0dedb (patch)
tree2ee8dfb7ebc6baf91b2ba84d0fc7fc190e4c3f6f
parentdafaabd0509a501632d7bc2e5dc5412e52818281 (diff)
drm_hwcomposer: Add support for Arm Framebuffer Compression (AFBC) modifiers.
One needs to translate the Gralloc buffer flags for AFBC (eg MALI_GRALLOC_INTFMT_AFBC_BASIC) to the corresponding linux kernel drm modifiers. This gets passed to libdrm via drmModeAddFB2WithModifiers. Changes from v1:- - Moved ConvertGrallocFormatToDrmModifiers() and IsDrmFormatRgb() from 'DrmGenericImporter' to 'HisiImporter' as suggested by Sean paul - Check if the format is rgb and set AFBC_FORMAT_MOD_YTR only if any of the AFBC related Gralloc flags are set. Changes from v2:- - Changed ConvertGrallocFormatToDrmModifiers() and IsDrmFormatRgb() from 'public' to 'private' (suggested by Sean Paul) Changes from v3:- - Reordered the members of 'class HisiImporter'. Functions should go above member variables. (suggested by Sean Paul) Changes from v4:- - Rebased and some style changes (as suggested by gitlab-ci-checkcommit.sh) Signed-off-by: Ayan Kumar Halder <ayan.halder@arm.com> Reviewed-by: Sean Paul <seanpaul@chromium.org> /-- Note for reviewer I was able to get this working for hikey960 with aosp/master for kernel 4.14. The libdrm headers need to be updated as the AFBC modifiers are missing in the aosp/master's external/libdrm. --/ Change-Id: I66abaa08d19ce88169cc40522b167dfe5efc7036
-rw-r--r--platformhisi.cpp56
-rw-r--r--platformhisi.h4
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_;