From 6916d01731616972f4476a72c5b64fc9e883f929 Mon Sep 17 00:00:00 2001 From: koron393 Date: Mon, 16 Sep 2019 01:19:12 +0900 Subject: shinano-common: libshim_camera: Update sources to Q * Copy from Q framework sources. Change-Id: I5b1998ce1834e825dad70f09bc8f6ab3d8e059e6 Signed-off-by: koron393 --- libshims/ui/GraphicBufferAllocator.cpp | 103 ++++++++++++++++----------------- 1 file changed, 51 insertions(+), 52 deletions(-) (limited to 'libshims/ui/GraphicBufferAllocator.cpp') diff --git a/libshims/ui/GraphicBufferAllocator.cpp b/libshims/ui/GraphicBufferAllocator.cpp index 3806a8d..0861a1f 100644 --- a/libshims/ui/GraphicBufferAllocator.cpp +++ b/libshims/ui/GraphicBufferAllocator.cpp @@ -24,79 +24,82 @@ #include +#include #include #include -#include #include +#include #include +#include #include namespace android { // --------------------------------------------------------------------------- +using base::StringAppendF; + ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferAllocator ) Mutex GraphicBufferAllocator::sLock; KeyedVector GraphicBufferAllocator::sAllocList; -GraphicBufferAllocator::GraphicBufferAllocator() - : mAllocDev(0) -{ - 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) { - gralloc_open(module, &mAllocDev); +GraphicBufferAllocator::GraphicBufferAllocator() : mMapper(GraphicBufferMapper::getInstance()) { + mAllocator = std::make_unique( + reinterpret_cast(mMapper.getGrallocMapper())); + if (!mAllocator->isLoaded()) { + mAllocator = std::make_unique( + reinterpret_cast(mMapper.getGrallocMapper())); + } + + if (!mAllocator->isLoaded()) { + LOG_ALWAYS_FATAL("gralloc-allocator is missing"); } } -GraphicBufferAllocator::~GraphicBufferAllocator() -{ - gralloc_close(mAllocDev); +GraphicBufferAllocator::~GraphicBufferAllocator() {} + +size_t GraphicBufferAllocator::getTotalSize() const { + Mutex::Autolock _l(sLock); + size_t total = 0; + for (size_t i = 0; i < sAllocList.size(); ++i) { + total += sAllocList.valueAt(i).size; + } + return total; } -void GraphicBufferAllocator::dump(String8& result) const -{ +void GraphicBufferAllocator::dump(std::string& result) const { Mutex::Autolock _l(sLock); KeyedVector& list(sAllocList); size_t total = 0; - const size_t SIZE = 4096; - char buffer[SIZE]; - snprintf(buffer, SIZE, "Allocated buffers:\n"); - result.append(buffer); + result.append("Allocated buffers:\n"); const size_t c = list.size(); for (size_t i=0 ; idumpDebugInfo(); - result.append(deviceDump.c_str(), deviceDump.size()); + result.append(mAllocator->dumpDebugInfo()); } void GraphicBufferAllocator::dumpToSystemLog() { - String8 s; + std::string s; GraphicBufferAllocator::getInstance().dump(s); - ALOGD("%s", s.string()); + ALOGD("%s", s.c_str()); } status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height, @@ -115,15 +118,12 @@ status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height, if (layerCount < 1) layerCount = 1; - Gralloc2::IMapper::BufferDescriptorInfo info = {}; - info.width = width; - info.height = height; - info.layerCount = layerCount; - info.format = static_cast(format); - info.usage = usage; + // TODO(b/72323293, b/72703005): Remove these invalid bits from callers + usage &= ~static_cast((1 << 10) | (1 << 13)); - Gralloc2::Error error = mAllocator->allocate(info, stride, handle); - if (error == Gralloc2::Error::NONE) { + status_t error = + mAllocator->allocate(width, height, format, layerCount, usage, 1, stride, handle); + if (error == NO_ERROR) { Mutex::Autolock _l(sLock); KeyedVector& list(sAllocList); uint32_t bpp = bytesPerPixel(format); @@ -150,18 +150,17 @@ status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height, status_t GraphicBufferAllocator::free(buffer_handle_t handle) { - status_t err; + ATRACE_CALL(); - err = mAllocDev->free(mAllocDev, handle); + // We allocated a buffer from the allocator and imported it into the + // mapper to get the handle. We just need to free the handle now. + mMapper.freeBuffer(handle); - ALOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err)); - if (err == NO_ERROR) { - Mutex::Autolock _l(sLock); - KeyedVector& list(sAllocList); - list.removeItem(handle); - } + Mutex::Autolock _l(sLock); + KeyedVector& list(sAllocList); + list.removeItem(handle); - return err; + return NO_ERROR; } // --------------------------------------------------------------------------- -- cgit v1.2.3