aboutsummaryrefslogtreecommitdiff
path: root/libshims/ui/GraphicBufferAllocator.cpp
diff options
context:
space:
mode:
authorkoron393 <koron393@gmail.com>2019-09-16 01:32:35 +0900
committerArian <arian.kulmer@web.de>2020-02-07 20:09:45 +0100
commitde5416ca15c27aa1b204e540a5510f54b67cb3f6 (patch)
tree3300830b4fd0ee739afb124603bf8bb633f7f5e5 /libshims/ui/GraphicBufferAllocator.cpp
parent4d957a736845635f75cc8281d850c49d82b41275 (diff)
shinano-common: libshim_camera: Add pre N method to GraphicBuffer
* Add Marshmallow method to GraphicBuffer and Mapper. * Apply module loading changes to Allocator. Signed-off-by: koron393 <koron393@gmail.com> Change-Id: I906fa4f123afd9b9e1b62f6e53c1a2f753a027c3
Diffstat (limited to 'libshims/ui/GraphicBufferAllocator.cpp')
-rw-r--r--libshims/ui/GraphicBufferAllocator.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/libshims/ui/GraphicBufferAllocator.cpp b/libshims/ui/GraphicBufferAllocator.cpp
index 0861a1f..9543fd7 100644
--- a/libshims/ui/GraphicBufferAllocator.cpp
+++ b/libshims/ui/GraphicBufferAllocator.cpp
@@ -45,20 +45,21 @@ Mutex GraphicBufferAllocator::sLock;
KeyedVector<buffer_handle_t,
GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList;
-GraphicBufferAllocator::GraphicBufferAllocator() : mMapper(GraphicBufferMapper::getInstance()) {
- mAllocator = std::make_unique<const Gralloc3Allocator>(
- reinterpret_cast<const Gralloc3Mapper&>(mMapper.getGrallocMapper()));
- if (!mAllocator->isLoaded()) {
- mAllocator = std::make_unique<const Gralloc2Allocator>(
- reinterpret_cast<const Gralloc2Mapper&>(mMapper.getGrallocMapper()));
- }
-
- if (!mAllocator->isLoaded()) {
- LOG_ALWAYS_FATAL("gralloc-allocator is missing");
+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() {}
+GraphicBufferAllocator::~GraphicBufferAllocator()
+{
+ gralloc_close(mAllocDev);
+}
size_t GraphicBufferAllocator::getTotalSize() const {
Mutex::Autolock _l(sLock);
@@ -150,17 +151,18 @@ status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height,
status_t GraphicBufferAllocator::free(buffer_handle_t handle)
{
- ATRACE_CALL();
+ status_t err;
- // 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);
+ err = mAllocDev->free(mAllocDev, handle);
- Mutex::Autolock _l(sLock);
- KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- list.removeItem(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);
+ }
- return NO_ERROR;
+ return err;
}
// ---------------------------------------------------------------------------