From 4755d0203e6f3c38dca577e8d8208bab9c34c9ba Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Tue, 20 Jul 2021 11:30:46 +0800 Subject: VendorGraphicBuffer: Add import buffer and free buffer functions Bug: b/187279591 Test: video playback(YouTube, Exoplayer), video recording \ 3P Apps recording Change-Id: I72f422f7500cf3a0896f4d491719f2f24da91949 Signed-off-by: Charlie Chen --- .../gralloc3/vendor_graphicbuffer_meta.cpp | 13 ++++++ .../gralloc4/vendor_graphicbuffer_meta.cpp | 54 +++++++++++++++++++--- .../include/VendorGraphicBuffer.h | 3 ++ 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(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(handle); + auto hnd = static_cast(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(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(buffer_hnd_p); - return is_sbwc_format(static_cast(hnd->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK)); + return is_sbwc_format(static_cast(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(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(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(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(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); }; -- cgit v1.2.3