diff options
author | koron393 <koron393@gmail.com> | 2019-05-07 02:49:25 +0900 |
---|---|---|
committer | Arian <arian.kulmer@web.de> | 2019-10-25 22:16:13 +0200 |
commit | eb4c130ccf05799fe7c20a4737f21dd63c0dbed5 (patch) | |
tree | 4845e3f7e06d660b0def654c9a294bd489dc2744 /libshims/ui/GraphicBufferMapper.cpp | |
parent | fd201d3c1df49d4af95d2c48709b5a98b6e6d8e9 (diff) |
shinano-common: libshim_camera: Update GraphicBuffer sources to Pie
* Copy from Pie framework sources.
Change-Id: I903eb0c3c80a752d4a8da44dec47e348c7dd23fc
Signed-off-by: Nikhil Punathil <nikhilpe@gmail.com>
Diffstat (limited to 'libshims/ui/GraphicBufferMapper.cpp')
-rw-r--r-- | libshims/ui/GraphicBufferMapper.cpp | 169 |
1 files changed, 119 insertions, 50 deletions
diff --git a/libshims/ui/GraphicBufferMapper.cpp b/libshims/ui/GraphicBufferMapper.cpp index 18be8ae..2d8e582 100644 --- a/libshims/ui/GraphicBufferMapper.cpp +++ b/libshims/ui/GraphicBufferMapper.cpp @@ -16,103 +16,172 @@ #define LOG_TAG "GraphicBufferMapper" #define ATRACE_TAG ATRACE_TAG_GRAPHICS +//#define LOG_NDEBUG 0 -#include <stdint.h> -#include <errno.h> +#include <ui/GraphicBufferMapper.h> + +#include <grallocusage/GrallocUsageConversion.h> +// We would eliminate the non-conforming zero-length array, but we can't since +// this is effectively included from the Linux kernel +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wzero-length-array" #include <sync/sync.h> +#pragma clang diagnostic pop -#include <utils/Errors.h> #include <utils/Log.h> #include <utils/Trace.h> -#include <ui/GraphicBufferMapper.h> -#include <ui/Rect.h> - -#include <hardware/gralloc.h> +#include <ui/Gralloc2.h> +#include <ui/GraphicBuffer.h> +#include <system/graphics.h> namespace android { // --------------------------------------------------------------------------- ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper ) +void GraphicBufferMapper::preloadHal() { + Gralloc2::Mapper::preload(); +} + GraphicBufferMapper::GraphicBufferMapper() - : mAllocMod(0) + : mMapper(std::make_unique<const Gralloc2::Mapper>()) { - hw_module_t const* module; - int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); - ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID); - if (err == 0) { - mAllocMod = reinterpret_cast<gralloc_module_t const *>(module); - } } -status_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle) +status_t GraphicBufferMapper::importBuffer(buffer_handle_t rawHandle, + uint32_t width, uint32_t height, uint32_t layerCount, + PixelFormat format, uint64_t usage, uint32_t stride, + buffer_handle_t* outHandle) { ATRACE_CALL(); - status_t err; - err = mAllocMod->registerBuffer(mAllocMod, handle); + buffer_handle_t bufferHandle; + Gralloc2::Error error = mMapper->importBuffer( + hardware::hidl_handle(rawHandle), &bufferHandle); + if (error != Gralloc2::Error::NONE) { + ALOGW("importBuffer(%p) failed: %d", rawHandle, error); + return static_cast<status_t>(error); + } - ALOGW_IF(err, "registerBuffer(%p) failed %d (%s)", - handle, err, strerror(-err)); - return err; + Gralloc2::IMapper::BufferDescriptorInfo info = {}; + info.width = width; + info.height = height; + info.layerCount = layerCount; + info.format = static_cast<Gralloc2::PixelFormat>(format); + info.usage = usage; + + error = mMapper->validateBufferSize(bufferHandle, info, stride); + if (error != Gralloc2::Error::NONE) { + ALOGE("validateBufferSize(%p) failed: %d", rawHandle, error); + freeBuffer(bufferHandle); + return static_cast<status_t>(error); + } + + *outHandle = bufferHandle; + + return NO_ERROR; +} + +void GraphicBufferMapper::getTransportSize(buffer_handle_t handle, + uint32_t* outTransportNumFds, uint32_t* outTransportNumInts) +{ + mMapper->getTransportSize(handle, outTransportNumFds, outTransportNumInts); } -status_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle) +status_t GraphicBufferMapper::freeBuffer(buffer_handle_t handle) { ATRACE_CALL(); - status_t err; - err = mAllocMod->unregisterBuffer(mAllocMod, handle); + mMapper->freeBuffer(handle); + + return NO_ERROR; +} - ALOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)", - handle, err, strerror(-err)); - return err; +static inline Gralloc2::IMapper::Rect asGralloc2Rect(const Rect& rect) { + Gralloc2::IMapper::Rect outRect{}; + outRect.left = rect.left; + outRect.top = rect.top; + outRect.width = rect.width(); + outRect.height = rect.height(); + return outRect; } -status_t GraphicBufferMapper::lock(buffer_handle_t handle, - int usage, const Rect& bounds, void** vaddr) +status_t GraphicBufferMapper::lock(buffer_handle_t handle, uint32_t usage, + const Rect& bounds, void** vaddr) +{ + return lockAsync(handle, usage, bounds, vaddr, -1); +} + +status_t GraphicBufferMapper::lockYCbCr(buffer_handle_t handle, uint32_t usage, + const Rect& bounds, android_ycbcr *ycbcr) +{ + return lockAsyncYCbCr(handle, usage, bounds, ycbcr, -1); +} + +status_t GraphicBufferMapper::unlock(buffer_handle_t handle) +{ + int32_t fenceFd = -1; + status_t error = unlockAsync(handle, &fenceFd); + if (error == NO_ERROR && fenceFd >= 0) { + sync_wait(fenceFd, -1); + close(fenceFd); + } + return error; +} + +status_t GraphicBufferMapper::lockAsync(buffer_handle_t handle, + uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd) +{ + return lockAsync(handle, usage, usage, bounds, vaddr, fenceFd); +} + +status_t GraphicBufferMapper::lockAsync(buffer_handle_t handle, + uint64_t producerUsage, uint64_t consumerUsage, const Rect& bounds, + void** vaddr, int fenceFd) { ATRACE_CALL(); - status_t err; - err = mAllocMod->lock(mAllocMod, handle, static_cast<int>(usage), - bounds.left, bounds.top, bounds.width(), bounds.height(), - vaddr); + const uint64_t usage = static_cast<uint64_t>( + android_convertGralloc1To0Usage(producerUsage, consumerUsage)); + Gralloc2::Error error = mMapper->lock(handle, usage, + asGralloc2Rect(bounds), fenceFd, vaddr); + + ALOGW_IF(error != Gralloc2::Error::NONE, "lock(%p, ...) failed: %d", + handle, error); - ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err)); - return err; + return static_cast<status_t>(error); } -status_t GraphicBufferMapper::lockYCbCr(buffer_handle_t handle, - int usage, const Rect& bounds, android_ycbcr *ycbcr) +status_t GraphicBufferMapper::lockAsyncYCbCr(buffer_handle_t handle, + uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr, int fenceFd) { ATRACE_CALL(); - status_t err; - if (mAllocMod->lock_ycbcr == NULL) { - return -EINVAL; // do not log failure + Gralloc2::YCbCrLayout layout; + Gralloc2::Error error = mMapper->lock(handle, usage, + asGralloc2Rect(bounds), fenceFd, &layout); + if (error == Gralloc2::Error::NONE) { + ycbcr->y = layout.y; + ycbcr->cb = layout.cb; + ycbcr->cr = layout.cr; + ycbcr->ystride = static_cast<size_t>(layout.yStride); + ycbcr->cstride = static_cast<size_t>(layout.cStride); + ycbcr->chroma_step = static_cast<size_t>(layout.chromaStep); } - err = mAllocMod->lock_ycbcr(mAllocMod, handle, static_cast<int>(usage), - bounds.left, bounds.top, bounds.width(), bounds.height(), - ycbcr); - - ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err)); - return err; + return static_cast<status_t>(error); } -status_t GraphicBufferMapper::unlock(buffer_handle_t handle) +status_t GraphicBufferMapper::unlockAsync(buffer_handle_t handle, int *fenceFd) { ATRACE_CALL(); - status_t err; - err = mAllocMod->unlock(mAllocMod, handle); + *fenceFd = mMapper->unlock(handle); - ALOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err)); - return err; + return NO_ERROR; } // --------------------------------------------------------------------------- |