gralloc0: Unmask HW_VIDEO_ENCODER usage in the case of non-YUV formats
Non-yuv formats are allocated with HW_VIDEO_ENCODER usage as an
intermediate buffers, for example, camera fills. They are converted to
YUV formats finally when they are fed to a hw encoder. So there is no
need of allocating the buffers with HW_VIDEO_ENCODER.
TEST=Recording with GCA
TEST=android.media.cts.EncodeVirtualDisplayTest#testEncodeVirtualDisplay on kevin
Cq-Depend: chromium:1947685
Change-Id: Ic5c09823de1f53ffb6117d07327779e46f32a3f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/1940034
Tested-by: Hirokazu Honda <hiroh@chromium.org>
Auto-Submit: Hirokazu Honda <hiroh@chromium.org>
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
diff --git a/cros_gralloc/gralloc0/gralloc0.cc b/cros_gralloc/gralloc0/gralloc0.cc
index fcedc8e..0a302b4 100644
--- a/cros_gralloc/gralloc0/gralloc0.cc
+++ b/cros_gralloc/gralloc0/gralloc0.cc
@@ -100,6 +100,13 @@
return map_flags;
}
+static int gralloc0_droid_yuv_format(int droid_format)
+{
+
+ return (droid_format == HAL_PIXEL_FORMAT_YCbCr_420_888 ||
+ droid_format == HAL_PIXEL_FORMAT_YV12);
+}
+
static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usage,
buffer_handle_t *handle, int *stride)
{
@@ -120,6 +127,14 @@
descriptor.use_flags &= ~BO_USE_SCANOUT;
supported = mod->driver->is_supported(&descriptor);
}
+ if (!supported && (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) &&
+ !gralloc0_droid_yuv_format(format)) {
+ // Unmask BO_USE_HW_VIDEO_ENCODER in the case of non-yuv formats
+ // because they are not input to a hw encoder but used as an
+ // intermediate format (e.g. camera).
+ descriptor.use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
+ supported = mod->driver->is_supported(&descriptor);
+ }
if (!supported) {
drv_log("Unsupported combination -- HAL format: %u, HAL usage: %u, "
@@ -362,9 +377,8 @@
return -EINVAL;
}
- if ((hnd->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) &&
- (hnd->droid_format != HAL_PIXEL_FORMAT_YV12) &&
- (hnd->droid_format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED)) {
+ if (!gralloc0_droid_yuv_format(hnd->droid_format) &&
+ hnd->droid_format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
drv_log("Non-YUV format not compatible.\n");
return -EINVAL;
}