diff options
author | Ankit Goyal <layog@google.com> | 2022-10-12 18:17:38 -0700 |
---|---|---|
committer | Ankit Goyal <layog@google.com> | 2022-10-17 22:29:35 +0000 |
commit | a98049ad38bbafa7bd7f0ce9f1db8cb0d6cfe086 (patch) | |
tree | d408de905a3adf06e488ea7a29ff629543c64348 /libvendorgraphicbuffer | |
parent | 507a51085214fb9b2c54f242c4cd65b88e7e0283 (diff) |
libvendorgraphicbuffer: Add accessors for fourcc and modifier
Fix: 253120214
Test: Validated by ruofeim@
Change-Id: I7c7f034a03661faa030b5206fee8da5fc13c820f
Diffstat (limited to 'libvendorgraphicbuffer')
-rw-r--r-- | libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp | 54 | ||||
-rw-r--r-- | libvendorgraphicbuffer/include/VendorGraphicBuffer.h | 3 |
2 files changed, 57 insertions, 0 deletions
diff --git a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp index a155519..60d0b37 100644 --- a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp +++ b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp @@ -34,6 +34,8 @@ using arm::mapper::common::shared_metadata; using aidl::android::hardware::graphics::common::Dataspace; using android::gralloc4::encodeDataspace; using android::gralloc4::decodeDataspace; +using android::gralloc4::decodePixelFormatFourCC; +using android::gralloc4::decodePixelFormatModifier; using android::hardware::graphics::mapper::V4_0::IMapper; using android::hardware::graphics::mapper::V4_0::Error; @@ -255,6 +257,58 @@ void* VendorGraphicBufferMeta::get_video_metadata_roiinfo(buffer_handle_t hnd) return nullptr; } +uint32_t VendorGraphicBufferMeta::get_format_fourcc(buffer_handle_t hnd) { + native_handle_t* handle = const_cast<native_handle_t*>(hnd); + if (!handle) { + return DRM_FORMAT_INVALID; + } + + Error error = Error::NONE; + uint32_t fourcc; + get_mapper()->get(handle, android::gralloc4::MetadataType_PixelFormatFourCC, + [&](const auto& tmpError, const android::hardware::hidl_vec<uint8_t>& tmpVec) { + error = tmpError; + if (error != Error::NONE) { + return; + } + error = static_cast<Error>(decodePixelFormatFourCC(tmpVec, &fourcc)); + }); + + + if (error != Error::NONE) { + ALOGE("Failed to get fourcc"); + return DRM_FORMAT_INVALID; + } + + return fourcc; +} + +uint64_t VendorGraphicBufferMeta::get_format_modifier(buffer_handle_t hnd) { + native_handle_t* handle = const_cast<native_handle_t*>(hnd); + if (!handle) { + return DRM_FORMAT_MOD_INVALID; + } + + Error error = Error::NONE; + uint64_t modifier; + get_mapper()->get(handle, android::gralloc4::MetadataType_PixelFormatModifier, + [&](const auto& tmpError, const android::hardware::hidl_vec<uint8_t>& tmpVec) { + error = tmpError; + if (error != Error::NONE) { + return; + } + error = static_cast<Error>(decodePixelFormatModifier(tmpVec, &modifier)); + }); + + + if (error != Error::NONE) { + ALOGE("Failed to get format modifier"); + return DRM_FORMAT_MOD_INVALID; + } + + return modifier; +} + void VendorGraphicBufferMeta::init(const buffer_handle_t handle) { const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(handle); diff --git a/libvendorgraphicbuffer/include/VendorGraphicBuffer.h b/libvendorgraphicbuffer/include/VendorGraphicBuffer.h index 8dfd90d..db5fecf 100644 --- a/libvendorgraphicbuffer/include/VendorGraphicBuffer.h +++ b/libvendorgraphicbuffer/include/VendorGraphicBuffer.h @@ -138,6 +138,9 @@ public: static int is_sbwc(buffer_handle_t); static void* get_video_metadata(buffer_handle_t); + static uint32_t get_format_fourcc(buffer_handle_t); + static uint64_t get_format_modifier(buffer_handle_t); + /* get_video_metadata_roiinfo is only supported with gralloc4 * When gralloc3 is used, will always return nullptr */ |