diff options
author | Ankit Goyal <layog@google.com> | 2021-07-01 18:19:02 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-07-01 18:19:02 +0000 |
commit | cce479b8bc11fd986c8b1d72db6acaaa1702afda (patch) | |
tree | 34e5ee51558af6b806c5d7d9a3019d967687eec8 | |
parent | b6f8c05434bd7463c77fe1747c8e011b798823eb (diff) | |
parent | 27d4aa1db7cb69ef1b38a4cf61df57236d31ad5c (diff) | |
download | gchips-cce479b8bc11fd986c8b1d72db6acaaa1702afda.tar.gz |
Decouple metadata operations from implementation am: 27d4aa1db7
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/google/gchips/+/15109450
Change-Id: Iff9d2311b6de1b5b0bde77e657ade342ab69a0c8
-rw-r--r-- | gralloc4/src/hidl_common/Mapper.cpp | 15 | ||||
-rw-r--r-- | libvendorgraphicbuffer/Android.bp | 3 | ||||
-rw-r--r-- | libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp | 78 |
3 files changed, 71 insertions, 25 deletions
diff --git a/gralloc4/src/hidl_common/Mapper.cpp b/gralloc4/src/hidl_common/Mapper.cpp index bfe632d..80ea7e1 100644 --- a/gralloc4/src/hidl_common/Mapper.cpp +++ b/gralloc4/src/hidl_common/Mapper.cpp @@ -623,6 +623,14 @@ void get(void *buffer, const IMapper::MetadataType &metadataType, IMapper::get_c hidl_cb(Error::BAD_BUFFER, hidl_vec<uint8_t>()); return; } + + if (mali_gralloc_reference_validate((buffer_handle_t)handle) < 0) + { + MALI_GRALLOC_LOGE("Buffer: %p is not imported", handle); + hidl_cb(Error::BAD_VALUE, hidl_vec<uint8_t>()); + return; + } + get_metadata(handle, metadataType, hidl_cb); } @@ -635,6 +643,13 @@ Error set(void *buffer, const IMapper::MetadataType &metadataType, const hidl_ve MALI_GRALLOC_LOGE("Buffer: %p has not been registered with Gralloc", buffer); return Error::BAD_BUFFER; } + + if (mali_gralloc_reference_validate((buffer_handle_t)handle) < 0) + { + MALI_GRALLOC_LOGE("Buffer: %p is not imported", handle); + return Error::BAD_VALUE; + } + return set_metadata(handle, metadataType, metadata); } 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; } |