diff options
author | Charlie Chen <yuchungchen@google.com> | 2021-07-27 09:48:17 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-07-27 09:48:17 +0000 |
commit | 247514f5c15d89be863b8ea0f4fbc2b2fffb0373 (patch) | |
tree | d5a88b46732a544e6581b62550b1cdaebf4a69e3 | |
parent | ce5f9e9219ec28bcdda3efd34fd8a46755840ec8 (diff) | |
parent | 2cc6407faa4b312558310c0f0fc7749158f8ed7a (diff) | |
download | gchips-247514f5c15d89be863b8ea0f4fbc2b2fffb0373.tar.gz |
Merge "VendorGraphicBuffer: Add import buffer and free buffer functions" into sc-dev am: 2cc6407faa
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/google/gchips/+/15372210
Change-Id: Ife8546a4ce41e6bc30eb674a8b9f5934ff0ca32a
3 files changed, 63 insertions, 7 deletions
diff --git a/libvendorgraphicbuffer/gralloc3/vendor_graphicbuffer_meta.cpp b/libvendorgraphicbuffer/gralloc3/vendor_graphicbuffer_meta.cpp index f6322be..16e62bf 100644 --- a/libvendorgraphicbuffer/gralloc3/vendor_graphicbuffer_meta.cpp +++ b/libvendorgraphicbuffer/gralloc3/vendor_graphicbuffer_meta.cpp @@ -230,6 +230,19 @@ void* VendorGraphicBufferMeta::get_video_metadata_roiinfo(buffer_handle_t hnd) return nullptr; } +/* This function is not used with gralloc3. return nullptr */ +buffer_handle_t VendorGraphicBufferMeta::import_buffer(buffer_handle_t hnd) +{ + UNUSED(hnd); + return nullptr; +} + +/* This function is not used with gralloc3. */ +int VendorGraphicBufferMeta::free_buffer(buffer_handle_t hnd) +{ + return 0; +} + 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/gralloc4/vendor_graphicbuffer_meta.cpp b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp index 8d88231..9034019 100644 --- a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp +++ b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp @@ -44,13 +44,13 @@ using android::hardware::graphics::mapper::V4_0::Error; // libraries and should depend upon HAL (and it's extension) to call into // Gralloc. int mali_gralloc_reference_validate(buffer_handle_t handle) { - auto hnd = static_cast<const private_handle_t *>(handle); + auto hnd = static_cast<const private_handle_t *>(handle); - if (hnd->allocating_pid != getpid() && hnd->remote_pid != getpid()) { - return -EINVAL; - } + if (hnd->allocating_pid != getpid() && hnd->remote_pid != getpid()) { + return -EINVAL; + } - return 0; + return 0; } const private_handle_t * convertNativeHandleToPrivateHandle(buffer_handle_t handle) { @@ -105,6 +105,7 @@ int VendorGraphicBufferMeta::get_dataspace(buffer_handle_t hnd) error = static_cast<Error>(decodeDataspace(tmpVec, &dataspace)); }); + if (error != Error::NONE) { ALOGE("Failed to get datasapce"); return -EINVAL; @@ -154,7 +155,7 @@ int VendorGraphicBufferMeta::is_sbwc(buffer_handle_t buffer_hnd_p) { const private_handle_t *hnd = static_cast<const private_handle_t *>(buffer_hnd_p); - return is_sbwc_format(static_cast<uint32_t>(hnd->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK)); + return is_sbwc_format(static_cast<uint32_t>(hnd->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK)); } #define GRALLOC_META_GETTER(__type__, __name__, __member__) \ @@ -166,7 +167,7 @@ __type__ VendorGraphicBufferMeta::get_##__name__(buffer_handle_t hnd) \ } \ -uint32_t VendorGraphicBufferMeta::get_format(buffer_handle_t hnd) +uint32_t VendorGraphicBufferMeta::get_format(buffer_handle_t hnd) { const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); if (!gralloc_hnd) @@ -304,6 +305,45 @@ void VendorGraphicBufferMeta::init(const buffer_handle_t handle) unique_id = gralloc_hnd->backing_store_id; } +buffer_handle_t VendorGraphicBufferMeta::import_buffer(buffer_handle_t hnd) +{ + native_handle_t* handle = const_cast<native_handle_t*>(hnd); + if (!handle) { + return nullptr; + } + + native_handle_t* bufferHandle = nullptr; + Error error = Error::NONE; + get_mapper()->importBuffer(handle, [&](const auto& tmpError, const auto& tmpBuffer) { + error = tmpError; + if (error != Error::NONE) { + return; + } + bufferHandle = static_cast<native_handle_t*>(tmpBuffer); + }); + + if (error != Error::NONE) { + ALOGE("[%s] Unable to import buffer", __FUNCTION__); + return nullptr; + } + + return bufferHandle; +} + +int VendorGraphicBufferMeta::free_buffer(buffer_handle_t hnd) +{ + native_handle_t* handle = const_cast<native_handle_t*>(hnd); + if (!handle) { + return -EINVAL; + } + Error error = get_mapper()->freeBuffer(handle); + if (error != Error::NONE) { + ALOGE("[%s] Failed to free buffer", __FUNCTION__); + return -EINVAL; + } + return 0; +} + VendorGraphicBufferMeta::VendorGraphicBufferMeta(buffer_handle_t handle) { init(handle); diff --git a/libvendorgraphicbuffer/include/VendorGraphicBuffer.h b/libvendorgraphicbuffer/include/VendorGraphicBuffer.h index cc014cb..8dfd90d 100644 --- a/libvendorgraphicbuffer/include/VendorGraphicBuffer.h +++ b/libvendorgraphicbuffer/include/VendorGraphicBuffer.h @@ -145,6 +145,9 @@ public: static int get_video_metadata_fd(buffer_handle_t); static int get_dataspace(buffer_handle_t); static int set_dataspace(buffer_handle_t hnd, android_dataspace_t dataspace); + + static buffer_handle_t import_buffer(buffer_handle_t); + static int free_buffer(buffer_handle_t); }; |