diff options
author | Ankit Goyal <layog@google.com> | 2021-06-25 21:19:00 +0800 |
---|---|---|
committer | Ankit Goyal <layog@google.com> | 2021-07-01 23:20:42 +0800 |
commit | 27d4aa1db7cb69ef1b38a4cf61df57236d31ad5c (patch) | |
tree | 34e5ee51558af6b806c5d7d9a3019d967687eec8 /libvendorgraphicbuffer | |
parent | 2877762dd5e6693448db63d3cff2709bd8a755b1 (diff) |
Decouple metadata operations from implementation
Bug: 191912915
Test: Full-range video playback with known calls to set_dataspace
Change-Id: I9ee1419922a316f3ce0e303ab46c2e46d1b72fec
Diffstat (limited to 'libvendorgraphicbuffer')
-rw-r--r-- | libvendorgraphicbuffer/Android.bp | 3 | ||||
-rw-r--r-- | libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp | 78 |
2 files changed, 56 insertions, 25 deletions
diff --git a/libvendorgraphicbuffer/Android.bp b/libvendorgraphicbuffer/Android.bp index b1e2a3f..8c1a71d 100644 --- a/libvendorgraphicbuffer/Android.bp +++ b/libvendorgraphicbuffer/Android.bp @@ -58,7 +58,6 @@ vendorgraphicbuffer_cc_defaults { srcs: [ "gralloc4/vendor_graphicbuffer_mapper.cpp", "gralloc4/vendor_graphicbuffer_meta.cpp", - ":libgralloc_hidl_common_shared_metadata", ], shared_libs: [ "libdrm", @@ -74,7 +73,7 @@ cc_library_shared { "vendorgraphicbuffer_defaults", ], shared_libs: [ - "libcutils", + "libutils", "libui", "liblog", "libhardware", diff --git a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp index 1b84627..8d88231 100644 --- a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp +++ b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp @@ -17,6 +17,9 @@ #define LOG_TAG "VendorGraphicBuffer" #include <log/log.h> +#include <gralloctypes/Gralloc4.h> +#include <android/hardware/graphics/mapper/4.0/IMapper.h> + #include "VendorGraphicBuffer.h" #include "mali_gralloc_buffer.h" #include "mali_gralloc_formats.h" @@ -28,6 +31,10 @@ using namespace vendor::graphics; using arm::mapper::common::shared_metadata; using aidl::android::hardware::graphics::common::Dataspace; +using android::gralloc4::encodeDataspace; +using android::gralloc4::decodeDataspace; +using android::hardware::graphics::mapper::V4_0::IMapper; +using android::hardware::graphics::mapper::V4_0::Error; #define UNUSED(x) ((void)x) #define SZ_4k 0x1000 @@ -53,6 +60,18 @@ const private_handle_t * convertNativeHandleToPrivateHandle(buffer_handle_t hand return static_cast<const private_handle_t *>(handle); } +android::sp<IMapper> get_mapper() { + static android::sp<IMapper> mapper = []() { + auto mapper = IMapper::getService(); + if (!mapper) { + ALOGE("Failed to get mapper service"); + } + return mapper; + }(); + + return mapper; +} + int VendorGraphicBufferMeta::get_video_metadata_fd(buffer_handle_t hnd) { const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); @@ -70,37 +89,50 @@ int VendorGraphicBufferMeta::get_video_metadata_fd(buffer_handle_t hnd) int VendorGraphicBufferMeta::get_dataspace(buffer_handle_t hnd) { - const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); - - if (!gralloc_hnd) - return -1; - - if (mali_gralloc_reference_validate(hnd) < 0) - ALOGW("VendorGraphicBufferMeta: get_dataspace from unimported buffer %p", hnd); - - int attr_fd = gralloc_hnd->get_share_attr_fd(); - - if(attr_fd < 0) - return -1; - - shared_metadata *metadata = (shared_metadata *)mmap(0, sizeof(shared_metadata), PROT_READ, MAP_SHARED, attr_fd, 0); - std::optional<Dataspace> dataspace = metadata->dataspace.to_std_optional(); - - int32_t ret = static_cast<int32_t>(dataspace.value_or(Dataspace::UNKNOWN)); + native_handle_t* handle = const_cast<native_handle_t*>(hnd); + if (!handle) { + return -EINVAL; + } - munmap(metadata, sizeof(shared_metadata)); + Error error = Error::NONE; + Dataspace dataspace; + get_mapper()->get(handle, android::gralloc4::MetadataType_Dataspace, + [&](const auto& tmpError, const android::hardware::hidl_vec<uint8_t>& tmpVec) { + error = tmpError; + if (error != Error::NONE) { + return; + } + error = static_cast<Error>(decodeDataspace(tmpVec, &dataspace)); + }); + + if (error != Error::NONE) { + ALOGE("Failed to get datasapce"); + return -EINVAL; + } - return ret; + return static_cast<int>(dataspace); } int VendorGraphicBufferMeta::set_dataspace(buffer_handle_t hnd, android_dataspace_t dataspace) { - const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd); + native_handle_t* handle = const_cast<native_handle_t*>(hnd); + if (!handle) { + return -EINVAL; + } - if (gralloc_hnd == nullptr) - return -1; + Error error = Error::NONE; + android::hardware::hidl_vec<uint8_t> vec; + error = static_cast<Error>(encodeDataspace(static_cast<Dataspace>(dataspace), &vec)); + if (error != Error::NONE) { + ALOGE("Error encoding dataspace"); + return -EINVAL; + } + error = get_mapper()->set(handle, android::gralloc4::MetadataType_Dataspace, vec); - arm::mapper::common::set_dataspace(gralloc_hnd, static_cast<Dataspace>(dataspace)); + if (error != Error::NONE) { + ALOGE("Failed to set datasapce"); + return -EINVAL; + } return 0; } |