From 80ab273a2a1911b19d5f9be6f065bd58569b2fe0 Mon Sep 17 00:00:00 2001 From: Roman Stratiienko Date: Mon, 14 Dec 2020 17:34:09 +0200 Subject: [PATCH] Always export DRM_FORMAT_YVU420_ANDROID as DRM_FORMAT_YVU420 Fixes video playback when gralloc0 and software video decoder are used. Signed-off-by: Roman Stratiienko Change-Id: I676060021806186bb3c23928d0d54af4add5120a --- cros_gralloc/gralloc0/gralloc0.cc | 3 ++- cros_gralloc/gralloc4/CrosGralloc4Mapper.cc | 11 ++++------- dri.c | 4 ++-- helpers.c | 8 ++++++++ helpers.h | 10 ++++++++++ 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cros_gralloc/gralloc0/gralloc0.cc b/cros_gralloc/gralloc0/gralloc0.cc index 4ab73f2..c00db2a 100644 --- a/cros_gralloc/gralloc0/gralloc0.cc +++ b/cros_gralloc/gralloc0/gralloc0.cc @@ -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++) { diff --git a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc index 0e26156..b3a85b2 100644 --- a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc +++ b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc @@ -469,12 +469,8 @@ Return CrosGralloc4Mapper::get(cros_gralloc_handle_t crosHandle, PixelFormat pixelFormat = static_cast(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 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 --- 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); diff --git a/helpers.c b/helpers.c index 7ed10ee..326dddf 100644 --- 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; +} diff --git a/helpers.h b/helpers.h index 19d0fd7..bbefed8 100644 --- a/helpers.h +++ b/helpers.h @@ -7,6 +7,10 @@ #ifndef HELPERS_H #define HELPERS_H +#ifdef __cplusplus +extern "C" { +#endif + #include #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 -- 2.11.0