OSDN Git Service

gralloc0: Unmask HW_VIDEO_ENCODER usage in the case of non-YUV formats
authorHirokazu Honda <hiroh@chromium.org>
Tue, 3 Dec 2019 02:01:59 +0000 (11:01 +0900)
committerCommit Bot <commit-bot@chromium.org>
Wed, 4 Dec 2019 11:50:41 +0000 (11:50 +0000)
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>
cros_gralloc/cros_gralloc_driver.cc
cros_gralloc/gralloc0/gralloc0.cc

index 8a63864..89897e0 100644 (file)
@@ -114,6 +114,15 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
        if (resolved_format == DRM_FORMAT_NV12)
                use_flags |= BO_USE_LINEAR;
 
+       /*
+        * This unmask is a backup in the case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED is resolved
+        * to non-YUV formats.
+        */
+       if (descriptor->drm_format == DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED &&
+           (resolved_format == DRM_FORMAT_XBGR8888 || resolved_format == DRM_FORMAT_ABGR8888)) {
+               use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
+       }
+
        bo = drv_bo_create(drv_, descriptor->width, descriptor->height, resolved_format, use_flags);
        if (!bo) {
                drv_log("Failed to create bo.\n");
index fcedc8e..0a302b4 100644 (file)
@@ -100,6 +100,13 @@ static uint32_t gralloc0_convert_map_usage(int map_usage)
        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 @@ static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usa
                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 @@ static int gralloc0_lock_async_ycbcr(struct gralloc_module_t const *module, buff
                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;
        }