Skip to content

Commit

Permalink
gralloc: unify gralloc frontends to use cros_gralloc_convert_format
Browse files Browse the repository at this point in the history
Reordered the cases to align with actual enum value for the hal formats,
and added 3 more formats support to align with gralloc4 support:
1. Y8
2. Y16
3. YCBCR_P010

BUG=b:199524294
TEST=CtsNativeHardwareTestCases
TEST=gralloc4 builds in aosp

Change-Id: I7a6743524c024d46ab2a7a6d973f431ea2721c49
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3160131
Tested-by: Yiwei Zhang <[email protected]>
Auto-Submit: Yiwei Zhang <[email protected]>
Reviewed-by: Jason Macnak <[email protected]>
Reviewed-by: Gurchetan Singh <[email protected]>
Commit-Queue: Yiwei Zhang <[email protected]>
  • Loading branch information
zhangyiwei authored and chenyanxzhu committed Sep 21, 2023
1 parent 33f30e9 commit 8ebdc98
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 99 deletions.
40 changes: 24 additions & 16 deletions cros_gralloc/cros_gralloc_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,44 @@ uint32_t cros_gralloc_convert_format(int format)
*/

switch (format) {
case HAL_PIXEL_FORMAT_BGRA_8888:
return DRM_FORMAT_ARGB8888;
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
return DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
case HAL_PIXEL_FORMAT_RAW16:
return DRM_FORMAT_R16;
case HAL_PIXEL_FORMAT_RGB_565:
return DRM_FORMAT_RGB565;
case HAL_PIXEL_FORMAT_RGB_888:
return DRM_FORMAT_BGR888;
case HAL_PIXEL_FORMAT_RGBA_8888:
return DRM_FORMAT_ABGR8888;
case HAL_PIXEL_FORMAT_RGBX_8888:
return DRM_FORMAT_XBGR8888;
case HAL_PIXEL_FORMAT_YCbCr_420_888:
return DRM_FORMAT_FLEX_YCbCr_420_888;
case HAL_PIXEL_FORMAT_YV12:
return DRM_FORMAT_YVU420_ANDROID;
case HAL_PIXEL_FORMAT_RGB_888:
return DRM_FORMAT_BGR888;
case HAL_PIXEL_FORMAT_RGB_565:
return DRM_FORMAT_RGB565;
case HAL_PIXEL_FORMAT_BGRA_8888:
return DRM_FORMAT_ARGB8888;
case HAL_PIXEL_FORMAT_RAW16:
return DRM_FORMAT_R16;
/*
* Choose DRM_FORMAT_R8 because <system/graphics.h> requires the buffers
* with a format HAL_PIXEL_FORMAT_BLOB have a height of 1, and width
* equal to their size in bytes.
*/
case HAL_PIXEL_FORMAT_BLOB:
return DRM_FORMAT_R8;
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
return DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
case HAL_PIXEL_FORMAT_YCbCr_420_888:
return DRM_FORMAT_FLEX_YCbCr_420_888;
case HAL_PIXEL_FORMAT_Y8:
return DRM_FORMAT_R8;
case HAL_PIXEL_FORMAT_Y16:
return DRM_FORMAT_R16;
case HAL_PIXEL_FORMAT_YV12:
return DRM_FORMAT_YVU420_ANDROID;
#if ANDROID_API_LEVEL >= 26
case HAL_PIXEL_FORMAT_RGBA_1010102:
return DRM_FORMAT_ABGR2101010;
case HAL_PIXEL_FORMAT_RGBA_FP16:
return DRM_FORMAT_ABGR16161616F;
case HAL_PIXEL_FORMAT_RGBA_1010102:
return DRM_FORMAT_ABGR2101010;
#endif
#if ANDROID_API_LEVEL >= 30
case HAL_PIXEL_FORMAT_YCBCR_P010:
return DRM_FORMAT_P010;
#endif
}

Expand Down
90 changes: 7 additions & 83 deletions cros_gralloc/gralloc4/CrosGralloc4Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,87 +280,13 @@ std::string getUsageString(hidl_bitfield<BufferUsage> bufferUsage) {
}

int convertToDrmFormat(PixelFormat format, uint32_t* outDrmFormat) {
switch (format) {
case PixelFormat::BGRA_8888:
*outDrmFormat = DRM_FORMAT_ARGB8888;
return 0;
/**
* Choose DRM_FORMAT_R8 because <system/graphics.h> requires the buffers
* with a format HAL_PIXEL_FORMAT_BLOB have a height of 1, and width
* equal to their size in bytes.
*/
case PixelFormat::BLOB:
*outDrmFormat = DRM_FORMAT_R8;
return 0;
case PixelFormat::DEPTH_16:
return -EINVAL;
case PixelFormat::DEPTH_24:
return -EINVAL;
case PixelFormat::DEPTH_24_STENCIL_8:
return -EINVAL;
case PixelFormat::DEPTH_32F:
return -EINVAL;
case PixelFormat::DEPTH_32F_STENCIL_8:
return -EINVAL;
case PixelFormat::HSV_888:
return -EINVAL;
case PixelFormat::IMPLEMENTATION_DEFINED:
*outDrmFormat = DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
return 0;
case PixelFormat::RAW10:
return -EINVAL;
case PixelFormat::RAW12:
return -EINVAL;
case PixelFormat::RAW16:
*outDrmFormat = DRM_FORMAT_R16;
return 0;
/* TODO use blob */
case PixelFormat::RAW_OPAQUE:
return -EINVAL;
case PixelFormat::RGBA_1010102:
*outDrmFormat = DRM_FORMAT_ABGR2101010;
return 0;
case PixelFormat::RGBA_8888:
*outDrmFormat = DRM_FORMAT_ABGR8888;
return 0;
case PixelFormat::RGBA_FP16:
*outDrmFormat = DRM_FORMAT_ABGR16161616F;
return 0;
case PixelFormat::RGBX_8888:
*outDrmFormat = DRM_FORMAT_XBGR8888;
return 0;
case PixelFormat::RGB_565:
*outDrmFormat = DRM_FORMAT_RGB565;
return 0;
case PixelFormat::RGB_888:
*outDrmFormat = DRM_FORMAT_RGB888;
return 0;
case PixelFormat::STENCIL_8:
return -EINVAL;
case PixelFormat::Y16:
*outDrmFormat = DRM_FORMAT_R16;
return 0;
case PixelFormat::Y8:
*outDrmFormat = DRM_FORMAT_R8;
return 0;
case PixelFormat::YCBCR_420_888:
*outDrmFormat = DRM_FORMAT_FLEX_YCbCr_420_888;
return 0;
case PixelFormat::YCBCR_422_SP:
return -EINVAL;
case PixelFormat::YCBCR_422_I:
return -EINVAL;
case PixelFormat::YCBCR_P010:
*outDrmFormat = DRM_FORMAT_P010;
return 0;
case PixelFormat::YCRCB_420_SP:
*outDrmFormat = DRM_FORMAT_NV21;
return 0;
case PixelFormat::YV12:
*outDrmFormat = DRM_FORMAT_YVU420_ANDROID;
return 0;
};
return -EINVAL;
static_assert(std::is_same<std::underlying_type<PixelFormat>::type, int32_t>::value);

const uint32_t drmFormat = cros_gralloc_convert_format(static_cast<int32_t>(format));
if (drmFormat == DRM_FORMAT_NONE) return -EINVAL;

*outDrmFormat = drmFormat;
return 0;
}

int convertToBufferUsage(uint64_t grallocUsage, uint64_t* outBufferUsage) {
Expand Down Expand Up @@ -459,8 +385,6 @@ int convertToCrosDescriptor(const BufferDescriptorInfo& descriptor,
std::string pixelFormatString = getPixelFormatString(descriptor.format);
drv_log("Failed to convert descriptor. Unsupported fomat %s\n", pixelFormatString.c_str());
return -1;
} else {
outCrosDescriptor->drm_format = cros_gralloc_convert_format(static_cast<int32_t>(descriptor.format));
}
#else
std::string pixelFormatString = getPixelFormatString(descriptor.format);
Expand Down

0 comments on commit 8ebdc98

Please sign in to comment.