Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gralloc: unify gralloc frontends to use cros_gralloc_convert_format #72

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ cc_defaults {
],
cppflags: ["-std=c++14"],

product_variables: {
platform_sdk_version: {
cflags: ["-DANDROID_API_LEVEL=%d"],
},
},

vendor: true,

header_libs: [
Expand Down
42 changes: 25 additions & 17 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;
#if ANDROID_VERSION >= 0x0a00
case HAL_PIXEL_FORMAT_RGBA_1010102:
return DRM_FORMAT_ABGR2101010;
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_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
88 changes: 7 additions & 81 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
Loading