From 3e4cb46146a75cbb809ba62d7062e5c112794f49 Mon Sep 17 00:00:00 2001 From: zhangyichix Date: Wed, 19 Jul 2023 11:05:49 +0800 Subject: [PATCH] Fixed the issue that sw codec fails to validate 10-bit type buffer The function validateBufferSize fails when sw codec allocates buffer with HAL_PIXEL_FORMAT_YCBCR_P010. The reason is that the pixel format will be converted to drm format for allocating buffer, then the format of the handle is assigned to HAL_PIXEL_ format type with i915_private_invert_format, but the descriptor.format is still the pixel format, they must be different when checked in validateBufferSize. So we check the format type after uniformly converting the pixel/HAL format to drm format. Tracked-On: OAM-111243 Signed-off-by: zhangyichix --- cros_gralloc/gralloc4/CrosGralloc4Mapper.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc index 81379e22..2127f02b 100644 --- a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc +++ b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc @@ -150,7 +150,14 @@ Return CrosGralloc4Mapper::validateBufferSize(void* rawHandle, } PixelFormat crosHandleFormat = static_cast(crosHandle->droid_format); - if (descriptor.format != crosHandleFormat && + + uint32_t descriptor_drmFormat = 0, handle_drmFormat = 0; + handle_drmFormat = cros_gralloc_convert_format(static_cast(crosHandleFormat)); + if (convertToDrmFormat(descriptor.format, &descriptor_drmFormat)) { + descriptor_drmFormat = cros_gralloc_convert_format(static_cast(descriptor.format)); + } + + if (descriptor_drmFormat != handle_drmFormat && !flex_format_match((uint32_t)descriptor.format, (uint32_t)crosHandleFormat, descriptor.usage)) { drv_log("Failed to validateBufferSize. Format mismatch.\n"); return Error::BAD_BUFFER;