OSDN Git Service

Always export DRM_FORMAT_YVU420_ANDROID as DRM_FORMAT_YVU420
authorRoman Stratiienko <r.stratiienko@gmail.com>
Mon, 14 Dec 2020 15:34:09 +0000 (17:34 +0200)
committerRoman Stratiienko <r.stratiienko@gmail.com>
Wed, 16 Dec 2020 12:53:30 +0000 (14:53 +0200)
Fixes video playback when gralloc0 and software video decoder are used.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: I676060021806186bb3c23928d0d54af4add5120a

cros_gralloc/gralloc0/gralloc0.cc
cros_gralloc/gralloc4/CrosGralloc4Mapper.cc
dri.c
helpers.c
helpers.h

index 4ab73f2..c00db2a 100644 (file)
@@ -4,6 +4,7 @@
  * found in the LICENSE file.
  */
 
+#include "../../helpers.h"
 #include "../../util.h"
 #include "../cros_gralloc_driver.h"
 
@@ -331,7 +332,7 @@ static int gralloc0_perform(struct gralloc_module_t const *module, int op, ...)
                break;
        case GRALLOC_DRM_GET_BUFFER_INFO:
                info = va_arg(args, struct cros_gralloc0_buffer_info *);
-               info->drm_fourcc = hnd->format;
+               info->drm_fourcc = drv_get_standard_fourcc(hnd->format);
                info->num_fds = hnd->num_planes;
                info->modifier = hnd->format_modifier;
                for (uint32_t i = 0; i < hnd->num_planes; i++) {
index 0e26156..b3a85b2 100644 (file)
@@ -469,12 +469,8 @@ Return<void> CrosGralloc4Mapper::get(cros_gralloc_handle_t crosHandle,
         PixelFormat pixelFormat = static_cast<PixelFormat>(crosHandle->droid_format);
         status = android::gralloc4::encodePixelFormatRequested(pixelFormat, &encodedMetadata);
     } else if (metadataType == android::gralloc4::MetadataType_PixelFormatFourCC) {
-        uint32_t format = crosHandle->format;
-        // Map internal fourcc codes back to standard fourcc codes.
-        if (format == DRM_FORMAT_YVU420_ANDROID) {
-            format = DRM_FORMAT_YVU420;
-        }
-        status = android::gralloc4::encodePixelFormatFourCC(format, &encodedMetadata);
+        status = android::gralloc4::encodePixelFormatFourCC(
+                drv_get_standard_fourcc(crosHandle->format), &encodedMetadata);
     } else if (metadataType == android::gralloc4::MetadataType_PixelFormatModifier) {
         status = android::gralloc4::encodePixelFormatModifier(crosHandle->format_modifier,
                                                               &encodedMetadata);
@@ -643,7 +639,8 @@ Return<void> CrosGralloc4Mapper::getFromBufferDescriptorInfo(
             hidlCb(Error::BAD_VALUE, encodedMetadata);
             return Void();
         }
-        status = android::gralloc4::encodePixelFormatFourCC(drmFormat, &encodedMetadata);
+        status = android::gralloc4::encodePixelFormatFourCC(drv_get_standard_fourcc(drmFormat),
+                                                            &encodedMetadata);
     } else if (metadataType == android::gralloc4::MetadataType_Usage) {
         status = android::gralloc4::encodeUsage(descriptor.usage, &encodedMetadata);
     } else if (metadataType == android::gralloc4::MetadataType_ProtectedContent) {
diff --git a/dri.c b/dri.c
index dfcfb60..1d4aa12 100644 (file)
--- a/dri.c
+++ b/dri.c
@@ -355,7 +355,7 @@ int dri_bo_import(struct bo *bo, struct drv_import_fd_data *data)
 
                // clang-format off
                bo->priv = dri->image_extension->createImageFromDmaBufs2(dri->device, data->width, data->height,
-                                                                        data->format,
+                                                                        drv_get_standard_fourcc(data->format),
                                                                         data->format_modifiers[0],
                                                                         data->fds,
                                                                         bo->meta.num_planes,
@@ -374,7 +374,7 @@ int dri_bo_import(struct bo *bo, struct drv_import_fd_data *data)
        } else {
                // clang-format off
                bo->priv = dri->image_extension->createImageFromFds(dri->device, data->width, data->height,
-                                                                   data->format, data->fds,
+                                                                   drv_get_standard_fourcc(data->format), data->fds,
                                                                    bo->meta.num_planes,
                                                                    (int *)data->strides,
                                                                    (int *)data->offsets, NULL);
index 7ed10ee..326dddf 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -639,3 +639,11 @@ bool drv_has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier)
 
        return false;
 }
+
+/*
+ * Map internal fourcc codes back to standard fourcc codes.
+ */
+uint32_t drv_get_standard_fourcc(uint32_t fourcc_internal)
+{
+       return (fourcc_internal == DRM_FORMAT_YVU420_ANDROID) ? DRM_FORMAT_YVU420 : fourcc_internal;
+}
index 19d0fd7..bbefed8 100644 (file)
--- a/helpers.h
+++ b/helpers.h
@@ -7,6 +7,10 @@
 #ifndef HELPERS_H
 #define HELPERS_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <stdbool.h>
 
 #include "drv.h"
@@ -42,4 +46,10 @@ int drv_modify_linear_combinations(struct driver *drv);
 uint64_t drv_pick_modifier(const uint64_t *modifiers, uint32_t count,
                           const uint64_t *modifier_order, uint32_t order_count);
 bool drv_has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier);
+uint32_t drv_get_standard_fourcc(uint32_t fourcc_internal);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif