From 1a29f8b3daaf016529caa62d2e544fbe255b2ef3 Mon Sep 17 00:00:00 2001 From: Dominik Behr Date: Fri, 18 Apr 2025 14:11:16 -0700 Subject: [PATCH] cros_gralloc: AIDL fixes for pixelformats and getMetadata - fix return values for getArmMetadata - add some understanding of new AIDL pixelformats Bug: b/388092228, b/397712115, b/377616165 Test: boot corsola with AIDL gralloc/stable c mapper Flag: EXEMPT desktop-only Change-Id: I66b2ec6af7227cfb4c92e9459aeeee00aaa14b8f --- cros_gralloc/cros_gralloc_helpers.cc | 14 ++++++++++++++ cros_gralloc/mapper_stablec/Mapper.cpp | 14 ++++++-------- drv_helpers.c | 2 ++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cros_gralloc/cros_gralloc_helpers.cc b/cros_gralloc/cros_gralloc_helpers.cc index 9495778..90bb6a1 100644 --- a/cros_gralloc/cros_gralloc_helpers.cc +++ b/cros_gralloc/cros_gralloc_helpers.cc @@ -21,6 +21,12 @@ /* Define to match AIDL PixelFormat::R_8. */ #define HAL_PIXEL_FORMAT_R8 0x38 +/* New formats from hardware/interfaces/graphics/common/aidl/android/hardware/graphics/common/PixelFormat.aidl */ +#define HAL_PIXEL_FORMAT_R16_UINT 57 +#define HAL_PIXEL_FORMAT_R16G16_UINT 58 +#define HAL_PIXEL_FORMAT_RGBA_10101010 59 + + uint32_t cros_gralloc_convert_format(int format) { /* @@ -88,6 +94,14 @@ uint32_t cros_gralloc_convert_format(int format) return DRM_FORMAT_DEPTH32; case HAL_PIXEL_FORMAT_DEPTH_32F_STENCIL_8: return DRM_FORMAT_DEPTH32_STENCIL8; +#if ANDROID_API_LEVEL >= 34 + case HAL_PIXEL_FORMAT_R16_UINT: + return DRM_FORMAT_R16; + case HAL_PIXEL_FORMAT_R16G16_UINT: + return DRM_FORMAT_GR1616; + case HAL_PIXEL_FORMAT_RGBA_10101010: + return DRM_FORMAT_AXBXGXRX106106106106; +#endif } return DRM_FORMAT_NONE; diff --git a/cros_gralloc/mapper_stablec/Mapper.cpp b/cros_gralloc/mapper_stablec/Mapper.cpp index 68b3680..a5aa795 100644 --- a/cros_gralloc/mapper_stablec/Mapper.cpp +++ b/cros_gralloc/mapper_stablec/Mapper.cpp @@ -305,9 +305,8 @@ int32_t CrosGrallocMapperV5::getArmMetadata(buffer_handle_t _Nonnull buffer, mDriver->with_buffer(crosHandle, [&](cros_gralloc_buffer* crosBuffer) { uint32_t num_planes = crosBuffer->get_num_planes(); - if (outDataSize < sizeof(int64_t) * (1 + num_planes)) { - retValue = sizeof(int64_t) * (1 + num_planes); - } else { + retValue = sizeof(int64_t) * (1 + num_planes); + if (outDataSize >= retValue) { int64_t plane_fds[DRV_MAX_PLANES + 1]; plane_fds[0] = num_planes; @@ -317,7 +316,7 @@ int32_t CrosGrallocMapperV5::getArmMetadata(buffer_handle_t _Nonnull buffer, memcpy(outData, plane_fds, sizeof(uint64_t) * (1 + num_planes)); - retValue = -AIMAPPER_ERROR_NONE; + retValue = sizeof(uint64_t) * (1 + num_planes); } }); break; @@ -327,11 +326,10 @@ int32_t CrosGrallocMapperV5::getArmMetadata(buffer_handle_t _Nonnull buffer, uint32_t pf = crosBuffer->get_format(); int64_t fdt = static_cast(DataTypeFromDrmPixelFormat(pf)); - if (outDataSize < sizeof(fdt)) { - retValue = sizeof(fdt); - } else { + retValue = sizeof(fdt); + if (outDataSize >= retValue) { memcpy(outData, &fdt, sizeof(fdt)); - retValue = -AIMAPPER_ERROR_NONE; + retValue = sizeof(fdt); } }); break; diff --git a/drv_helpers.c b/drv_helpers.c index 12b671a..b0979d1 100644 --- a/drv_helpers.c +++ b/drv_helpers.c @@ -165,10 +165,12 @@ static const struct planar_layout *layout_from_format(uint32_t format) case DRM_FORMAT_XBGR8888: case DRM_FORMAT_XRGB2101010: case DRM_FORMAT_XRGB8888: + case DRM_FORMAT_GR1616: return &packed_4bpp_layout; case DRM_FORMAT_DEPTH32_STENCIL8: case DRM_FORMAT_ABGR16161616F: + case DRM_FORMAT_AXBXGXRX106106106106: return &packed_8bpp_layout; default: