aboutsummaryrefslogtreecommitdiff
path: root/libshims/ui
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
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')
-rw-r--r--libshims/ui/GraphicBuffer.cpp31
-rw-r--r--libshims/ui/GraphicBufferAllocator.cpp40
-rw-r--r--libshims/ui/GraphicBufferMapper.cpp7
3 files changed, 59 insertions, 19 deletions
diff --git a/libshims/ui/GraphicBuffer.cpp b/libshims/ui/GraphicBuffer.cpp
index 325d176..d70701d 100644
--- a/libshims/ui/GraphicBuffer.cpp
+++ b/libshims/ui/GraphicBuffer.cpp
@@ -99,6 +99,37 @@ GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
{
}
+// deprecated (android-6.0)
+GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
+ PixelFormat inFormat, uint32_t inUsage)
+ : GraphicBuffer(inWidth, inHeight, inFormat, 1, static_cast<uint64_t>(inUsage), "<Unknown>")
+{
+}
+
+// deprecated (android-6.0)
+GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
+ PixelFormat inFormat, uint32_t inUsage, uint32_t inStride,
+ native_handle_t* inHandle, bool keepOwnership)
+ : GraphicBuffer(inHandle, keepOwnership ? TAKE_HANDLE : WRAP_HANDLE,
+ inWidth, inHeight, inFormat, 1, static_cast<uint64_t>(inUsage), inStride)
+{
+}
+
+// deprecated (android-6.0)
+GraphicBuffer::GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership)
+ : BASE(), mOwner(keepOwnership ? ownHandle : ownNone),
+ mBufferMapper(GraphicBufferMapper::get()),
+ mInitCheck(NO_ERROR), mWrappedBuffer(buffer), mId(getUniqueId()),
+ mGenerationNumber(0)
+{
+ width = buffer->width;
+ height = buffer->height;
+ stride = buffer->stride;
+ format = buffer->format;
+ usage = buffer->usage;
+ handle = buffer->handle;
+}
+
GraphicBuffer::GraphicBuffer(const native_handle_t* inHandle, HandleWrapMethod method,
uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
uint32_t inLayerCount, uint64_t inUsage, uint32_t inStride)
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;
}
// ---------------------------------------------------------------------------
diff --git a/libshims/ui/GraphicBufferMapper.cpp b/libshims/ui/GraphicBufferMapper.cpp
index 25b7247..1efad90 100644
--- a/libshims/ui/GraphicBufferMapper.cpp
+++ b/libshims/ui/GraphicBufferMapper.cpp
@@ -111,6 +111,13 @@ status_t GraphicBufferMapper::lock(buffer_handle_t handle, uint32_t usage, const
return lockAsync(handle, usage, bounds, vaddr, -1, outBytesPerPixel, outBytesPerStride);
}
+// for old devices
+status_t GraphicBufferMapper::lock(buffer_handle_t handle, uint32_t usage,
+ const Rect& bounds, void** vaddr)
+{
+ return lock(handle, usage, bounds, vaddr, 0, 0);
+}
+
status_t GraphicBufferMapper::lockYCbCr(buffer_handle_t handle, uint32_t usage,
const Rect& bounds, android_ycbcr *ycbcr)
{