From 1ef773ff9caf9c1b9ee32b634f1c80e9a065aa6a Mon Sep 17 00:00:00 2001 From: Jamie Gennis Date: Thu, 7 Oct 2010 13:46:55 -0700 Subject: Move binder magic from the Surface class to GraphicBuffer. - Register buffers with Gralloc when unflattening a GraphicBuffer (rather than doing it in the Surface class). - Add support for a GraphicBuffer that wraps an android_native_window_t*. Change-Id: I029ac086111bbac800e5ca37eb505f558b718cd8 --- libs/ui/GraphicBuffer.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libs/ui/GraphicBuffer.cpp') diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp index 519c277c603a..436e06471624 100644 --- a/libs/ui/GraphicBuffer.cpp +++ b/libs/ui/GraphicBuffer.cpp @@ -77,6 +77,19 @@ GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h, handle = inHandle; } +GraphicBuffer::GraphicBuffer(android_native_buffer_t* buffer, bool keepOwnership) + : BASE(), mOwner(keepOwnership ? ownHandle : ownNone), + mBufferMapper(GraphicBufferMapper::get()), + mInitCheck(NO_ERROR), mIndex(-1), mWrappedBuffer(buffer) +{ + width = buffer->width; + height = buffer->height; + stride = buffer->stride; + format = buffer->format; + usage = buffer->usage; + handle = buffer->handle; +} + GraphicBuffer::~GraphicBuffer() { if (handle) { @@ -87,12 +100,14 @@ GraphicBuffer::~GraphicBuffer() void GraphicBuffer::free_handle() { if (mOwner == ownHandle) { + mBufferMapper.unregisterBuffer(handle); native_handle_close(handle); native_handle_delete(const_cast(handle)); } else if (mOwner == ownData) { GraphicBufferAllocator& allocator(GraphicBufferAllocator::get()); allocator.free(handle); } + mWrappedBuffer = 0; } status_t GraphicBuffer::initCheck() const { @@ -253,6 +268,11 @@ status_t GraphicBuffer::unflatten(void const* buffer, size_t size, } mOwner = ownHandle; + + if (handle != 0) { + mBufferMapper.registerBuffer(handle); + } + return NO_ERROR; } -- cgit v1.2.3-59-g8ed1b