diff options
author | Ankit Goyal <layog@google.com> | 2023-09-06 22:08:22 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-09-06 22:08:22 +0000 |
commit | 91526913df9bd12632173dd7a753772ad76b20eb (patch) | |
tree | e49ab915b692e40b5084c1f34822ea2db5a56dea | |
parent | 2a04fe4559f3913086b8e7a250de93c8f285f60e (diff) | |
parent | 209febd48d2791bffc9fb973e8b58148bfee5352 (diff) | |
download | gchips-91526913df9bd12632173dd7a753772ad76b20eb.tar.gz |
libvendorgraphicbuffer: Use metadata queries for custom video metadata am: 209febd48d
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/google/gchips/+/24631782
Change-Id: I0125ffab71fce6b5043ba59196add02372980f97
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | libvendorgraphicbuffer/Android.bp | 1 | ||||
-rw-r--r-- | libvendorgraphicbuffer/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 <pixel-gralloc/metadata.h> + 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<IMapper> 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<uint8_t>& 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<native_handle_t*>(hnd); + if (!handle) { + return nullptr; + } + + MapperMetadataType metadata_type{ + .name = ::pixel::graphics::kPixelMetadataTypeName, + .value = static_cast<int64_t>(::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<uint8_t>& 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<native_handle_t*>(hnd); + if (!handle) { return nullptr; + } + + MapperMetadataType metadata_type{ + .name = ::pixel::graphics::kPixelMetadataTypeName, + .value = static_cast<int64_t>(::pixel::graphics::MetadataType::VIDEO_ROI), + }; - if (gralloc_hnd->get_usage() & VendorGraphicBufferUsage::ROIINFO) - return static_cast<char*>(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<uint8_t>& 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) { |