aboutsummaryrefslogtreecommitdiff
path: root/libshims/ui/GraphicBufferAllocator.cpp
diff options
context:
space:
mode:
authorkoron393 <koron393@gmail.com>2019-05-07 02:49:25 +0900
committerArian <arian.kulmer@web.de>2019-10-25 22:16:13 +0200
commiteb4c130ccf05799fe7c20a4737f21dd63c0dbed5 (patch)
tree4845e3f7e06d660b0def654c9a294bd489dc2744 /libshims/ui/GraphicBufferAllocator.cpp
parentfd201d3c1df49d4af95d2c48709b5a98b6e6d8e9 (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/GraphicBufferAllocator.cpp')
-rw-r--r--libshims/ui/GraphicBufferAllocator.cpp115
1 files changed, 58 insertions, 57 deletions
diff --git a/libshims/ui/GraphicBufferAllocator.cpp b/libshims/ui/GraphicBufferAllocator.cpp
index 4f93fb6..eaba1ed 100644
--- a/libshims/ui/GraphicBufferAllocator.cpp
+++ b/libshims/ui/GraphicBufferAllocator.cpp
@@ -18,13 +18,19 @@
#define LOG_TAG "GraphicBufferAllocator"
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
-#include <cutils/log.h>
+#include <ui/GraphicBufferAllocator.h>
+
+#include <stdio.h>
+
+#include <grallocusage/GrallocUsageConversion.h>
+#include <log/log.h>
#include <utils/Singleton.h>
#include <utils/String8.h>
#include <utils/Trace.h>
-#include <ui/GraphicBufferAllocator.h>
+#include <ui/Gralloc2.h>
+#include <ui/GraphicBufferMapper.h>
namespace android {
// ---------------------------------------------------------------------------
@@ -36,20 +42,13 @@ KeyedVector<buffer_handle_t,
GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList;
GraphicBufferAllocator::GraphicBufferAllocator()
- : mAllocDev(0)
+ : mMapper(GraphicBufferMapper::getInstance()),
+ mAllocator(std::make_unique<Gralloc2::Allocator>(
+ mMapper.getGrallocMapper()))
{
- 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()
-{
- gralloc_close(mAllocDev);
-}
+GraphicBufferAllocator::~GraphicBufferAllocator() {}
void GraphicBufferAllocator::dump(String8& result) const
{
@@ -64,23 +63,26 @@ void GraphicBufferAllocator::dump(String8& result) const
for (size_t i=0 ; i<c ; i++) {
const alloc_rec_t& rec(list.valueAt(i));
if (rec.size) {
- snprintf(buffer, SIZE, "%10p: %7.2f KiB | %4u (%4u) x %4u | %8X | 0x%08x\n",
- list.keyAt(i), rec.size/1024.0f,
- rec.width, rec.stride, rec.height, rec.format, rec.usage);
+ snprintf(buffer, SIZE, "%10p: %7.2f KiB | %4u (%4u) x %4u | %4u | %8X | 0x%" PRIx64
+ " | %s\n",
+ list.keyAt(i), rec.size/1024.0,
+ rec.width, rec.stride, rec.height, rec.layerCount, rec.format,
+ rec.usage, rec.requestorName.c_str());
} else {
- snprintf(buffer, SIZE, "%10p: unknown | %4u (%4u) x %4u | %8X | 0x%08x\n",
+ snprintf(buffer, SIZE, "%10p: unknown | %4u (%4u) x %4u | %4u | %8X | 0x%" PRIx64
+ " | %s\n",
list.keyAt(i),
- rec.width, rec.stride, rec.height, rec.format, rec.usage);
+ rec.width, rec.stride, rec.height, rec.layerCount, rec.format,
+ rec.usage, rec.requestorName.c_str());
}
result.append(buffer);
total += rec.size;
}
- snprintf(buffer, SIZE, "Total allocated (estimate): %.2f KB\n", total/1024.0f);
+ snprintf(buffer, SIZE, "Total allocated (estimate): %.2f KB\n", total/1024.0);
result.append(buffer);
- if (mAllocDev->common.version >= 1 && mAllocDev->dump) {
- mAllocDev->dump(mAllocDev, buffer, SIZE);
- result.append(buffer);
- }
+
+ std::string deviceDump = mAllocator->dumpDebugInfo();
+ result.append(deviceDump.c_str(), deviceDump.size());
}
void GraphicBufferAllocator::dumpToSystemLog()
@@ -90,9 +92,10 @@ void GraphicBufferAllocator::dumpToSystemLog()
ALOGD("%s", s.string());
}
-status_t GraphicBufferAllocator::alloc(uint32_t width, uint32_t height,
- PixelFormat format, int usage, buffer_handle_t* handle,
- int32_t* stride)
+status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount, uint64_t usage,
+ buffer_handle_t* handle, uint32_t* stride,
+ uint64_t /*graphicBufferId*/, std::string requestorName)
{
ATRACE_CALL();
@@ -101,58 +104,56 @@ status_t GraphicBufferAllocator::alloc(uint32_t width, uint32_t height,
if (!width || !height)
width = height = 1;
- // we have a h/w allocator and h/w buffer is requested
- status_t err;
+ // Ensure that layerCount is valid.
+ if (layerCount < 1)
+ layerCount = 1;
- // Filter out any usage bits that should not be passed to the gralloc module
- usage &= GRALLOC_USAGE_ALLOC_MASK;
+ Gralloc2::IMapper::BufferDescriptorInfo info = {};
+ info.width = width;
+ info.height = height;
+ info.layerCount = layerCount;
+ info.format = static_cast<Gralloc2::PixelFormat>(format);
+ info.usage = usage;
- int outStride = 0;
- err = mAllocDev->alloc(mAllocDev, static_cast<int>(width),
- static_cast<int>(height), format, static_cast<int>(usage), handle,
- &outStride);
- *stride = static_cast<uint32_t>(outStride);
-
- ALOGW_IF(err, "alloc(%u, %u, %d, %08x, ...) failed %d (%s)",
- width, height, format, usage, err, strerror(-err));
-
- if (err == NO_ERROR) {
+ Gralloc2::Error error = mAllocator->allocate(info, stride, handle);
+ if (error == Gralloc2::Error::NONE) {
Mutex::Autolock _l(sLock);
KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- int bpp = bytesPerPixel(format);
- if (bpp < 0) {
- // probably a HAL custom format. in any case, we don't know
- // what its pixel size is.
- bpp = 0;
- }
+ uint32_t bpp = bytesPerPixel(format);
alloc_rec_t rec;
rec.width = width;
rec.height = height;
rec.stride = *stride;
rec.format = format;
+ rec.layerCount = layerCount;
rec.usage = usage;
rec.size = static_cast<size_t>(height * (*stride) * bpp);
+ rec.requestorName = std::move(requestorName);
list.add(*handle, rec);
- }
- return err;
+ return NO_ERROR;
+ } else {
+ ALOGE("Failed to allocate (%u x %u) layerCount %u format %d "
+ "usage %" PRIx64 ": %d",
+ width, height, layerCount, format, usage,
+ error);
+ return NO_MEMORY;
+ }
}
status_t GraphicBufferAllocator::free(buffer_handle_t handle)
{
ATRACE_CALL();
- status_t err;
- 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<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- list.removeItem(handle);
- }
+ Mutex::Autolock _l(sLock);
+ KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
+ list.removeItem(handle);
- return err;
+ return NO_ERROR;
}
// ---------------------------------------------------------------------------