From 2ec6133d8eebac74715d0b861f955cdecb1dcb00 Mon Sep 17 00:00:00 2001 From: Ricardo Mendoza Date: Fri, 14 Feb 2014 12:27:24 +0100 Subject: [PATCH] Add NativeBufferAlloc interface for non-SurfaceFlinger BufferQueues Change-Id: I4e6bcb715f97b0ddef386a3302f76931a07af2f7 Signed-off-by: Ricardo Mendoza --- include/gui/BufferQueue.h | 8 +++++++- include/gui/NativeBufferAlloc.h | 34 +++++++++++++++++++++++++++++++++ libs/gui/BufferQueue.cpp | 29 ++++++++++++++++++++-------- 3 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 include/gui/NativeBufferAlloc.h diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h index cd38cfeb49dc..9ec31d24ff66 100644 --- a/include/gui/BufferQueue.h +++ b/include/gui/BufferQueue.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -118,7 +119,8 @@ class BufferQueue : public BnSurfaceTexture { // synchronous mode can be enabled by the producer. allocator is used to // allocate all the needed gralloc buffers. BufferQueue(bool allowSynchronousMode = true, - const sp& allocator = NULL); + const sp& allocator = NULL, + const sp& native_allocator = NULL); virtual ~BufferQueue(); virtual int query(int what, int* value); @@ -513,6 +515,10 @@ class BufferQueue : public BnSurfaceTexture { // allocate new GraphicBuffer objects. sp mGraphicBufferAlloc; + // mNativeBufferAlloc is an implementation-specific interface used + // to allocate GraphicBuffer objects. + sp mNativeBufferAlloc; + // mConsumerListener is used to notify the connected consumer of // asynchronous events that it may wish to react to. It is initially set // to NULL and is written by consumerConnect and consumerDisconnect. diff --git a/include/gui/NativeBufferAlloc.h b/include/gui/NativeBufferAlloc.h new file mode 100644 index 000000000000..94fd667a9628 --- /dev/null +++ b/include/gui/NativeBufferAlloc.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2013 Canonical Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authored by: Ricardo Mendoza + */ + +#ifndef NATIVE_BUFFER_ALLOC_H +#define NATIVE_BUFFER_ALLOC_H + +namespace android +{ +class NativeBufferAlloc : public RefBase +{ +public: + NativeBufferAlloc(); + virtual ~NativeBufferAlloc(); + virtual sp createGraphicBuffer(uint32_t w, uint32_t h, + PixelFormat format, uint32_t usage, status_t* error); +}; +} + +#endif /* NATIVE_BUFFER_ALLOC_H */ diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index acf6cec6c615..e8719a790da9 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -129,7 +129,8 @@ static bool isBufferGeometryUpdateRequired(sp buffer, #endif BufferQueue::BufferQueue(bool allowSynchronousMode, - const sp& allocator) : + const sp& allocator, + const sp& native_allocator) : mDefaultWidth(1), mDefaultHeight(1), mMaxAcquiredBufferCount(1), @@ -150,10 +151,15 @@ BufferQueue::BufferQueue(bool allowSynchronousMode, ST_LOGV("BufferQueue"); if (allocator == NULL) { - sp composer(ComposerService::getComposerService()); - mGraphicBufferAlloc = composer->createGraphicBufferAlloc(); - if (mGraphicBufferAlloc == 0) { - ST_LOGE("createGraphicBufferAlloc() failed in BufferQueue()"); + if (native_allocator != NULL) { + mNativeBufferAlloc = native_allocator; + mGraphicBufferAlloc = 0; + } else { + sp composer(ComposerService::getComposerService()); + mGraphicBufferAlloc = composer->createGraphicBufferAlloc(); + if (mGraphicBufferAlloc == 0) { + ST_LOGE("createGraphicBufferAlloc() failed in BufferQueue()"); + } } } else { mGraphicBufferAlloc = allocator; @@ -498,9 +504,16 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, sp& outFence, if (returnFlags & ISurfaceTexture::BUFFER_NEEDS_REALLOCATION) { status_t error; - sp graphicBuffer( - mGraphicBufferAlloc->createGraphicBuffer( - w, h, format, usage, &error)); + + sp graphicBuffer; + if (mNativeBufferAlloc != NULL) { + graphicBuffer = mNativeBufferAlloc->createGraphicBuffer( + w, h, format, usage, &error); + } else { + graphicBuffer = mGraphicBufferAlloc->createGraphicBuffer( + w, h, format, usage, &error); + } + if (graphicBuffer == 0) { ST_LOGE("dequeueBuffer: SurfaceComposer::createGraphicBuffer " "failed");