From 209febd48d2791bffc9fb973e8b58148bfee5352 Mon Sep 17 00:00:00 2001 From: Ankit Goyal Date: Thu, 10 Aug 2023 22:14:23 -0700 Subject: libvendorgraphicbuffer: Use metadata queries for custom video metadata Bug: 289448426 Test: ag/24398869 Merged-In: I264b1a83a5d7b2d5de04db7b0f56da95f8d41873 Change-Id: I264b1a83a5d7b2d5de04db7b0f56da95f8d41873 --- libvendorgraphicbuffer/Android.bp | 1 + .../gralloc4/vendor_graphicbuffer_meta.cpp | 76 +++++++++++++++++++--- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/libvendorgraphicbuffer/Android.bp b/libvendorgraphicbuffer/Android.bp index de3721a..0230bfb 100644 --- a/libvendorgraphicbuffer/Android.bp +++ b/libvendorgraphicbuffer/Android.bp @@ -43,6 +43,7 @@ cc_library_shared { ], header_libs: [ "libgralloc_headers", + "pixel-gralloc-headers", ], include_dirs: [ "hardware/google/gchips/include", diff --git a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp index 664f130..eb8d663 100644 --- a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp +++ b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp @@ -27,6 +27,8 @@ #include "hidl_common/SharedMetadata_struct.h" #include "exynos_format.h" +#include + using namespace android; using namespace vendor::graphics; @@ -38,6 +40,7 @@ using android::gralloc4::decodePixelFormatFourCC; using android::gralloc4::decodePixelFormatModifier; using android::hardware::graphics::mapper::V4_0::IMapper; using android::hardware::graphics::mapper::V4_0::Error; +using MapperMetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; #define UNUSED(x) ((void)x) #define SZ_4k 0x1000 @@ -71,6 +74,7 @@ android::sp get_mapper() { int VendorGraphicBufferMeta::get_video_metadata_fd(buffer_handle_t /*hnd*/) { + ALOGE("%s function is obsolete and should not be used", __FUNCTION__); __builtin_trap(); } @@ -223,28 +227,80 @@ uint64_t VendorGraphicBufferMeta::get_usage(buffer_handle_t hnd) return gralloc_hnd->producer_usage | gralloc_hnd->consumer_usage; } +void* decodePointer(const android::hardware::hidl_vec& tmpVec) { + constexpr uint8_t kPtrSize = sizeof(void*); + assert(tmpVec.size() == kPtrSize); + + void* data_ptr; + std::memcpy(&data_ptr, tmpVec.data(), kPtrSize); + + return data_ptr; +} + void* VendorGraphicBufferMeta::get_video_metadata(buffer_handle_t hnd) { - const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd); + native_handle_t* handle = const_cast(hnd); + if (!handle) { + return nullptr; + } + + MapperMetadataType metadata_type{ + .name = ::pixel::graphics::kPixelMetadataTypeName, + .value = static_cast(::pixel::graphics::MetadataType::VIDEO_HDR), + }; + + Error error = Error::NONE; + void* output = nullptr; + + get_mapper()->get(handle, metadata_type, + [&](const auto& tmpError, const android::hardware::hidl_vec& tmpVec) { + error = tmpError; + if (error != Error::NONE) { + return; + } + output = decodePointer(tmpVec); + }); + - if (gralloc_hnd == nullptr) + if (error != Error::NONE) { + ALOGE("Failed to get video HDR metadata"); return nullptr; + } - return gralloc_hnd->attr_base; + return output; } void* VendorGraphicBufferMeta::get_video_metadata_roiinfo(buffer_handle_t hnd) { - const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd); - - if (gralloc_hnd == nullptr) + native_handle_t* handle = const_cast(hnd); + if (!handle) { return nullptr; + } + + MapperMetadataType metadata_type{ + .name = ::pixel::graphics::kPixelMetadataTypeName, + .value = static_cast(::pixel::graphics::MetadataType::VIDEO_ROI), + }; - if (gralloc_hnd->get_usage() & VendorGraphicBufferUsage::ROIINFO) - return static_cast(gralloc_hnd->attr_base) + - sizeof(shared_metadata) + gralloc_hnd->reserved_region_size; + Error error = Error::NONE; + void* output = nullptr; + + get_mapper()->get(handle, metadata_type, + [&](const auto& tmpError, const android::hardware::hidl_vec& tmpVec) { + error = tmpError; + if (error != Error::NONE) { + return; + } + output = decodePointer(tmpVec); + }); + + + if (error != Error::NONE) { + ALOGE("Failed to get video HDR metadata"); + return nullptr; + } - return nullptr; + return output; } uint32_t VendorGraphicBufferMeta::get_format_fourcc(buffer_handle_t hnd) { -- cgit v1.2.3