Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/gui/BufferQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <gui/IGraphicBufferAlloc.h>
#include <gui/ISurfaceTexture.h>
#include <gui/NativeBufferAlloc.h>

#include <ui/Fence.h>
#include <ui/GraphicBuffer.h>
Expand Down Expand Up @@ -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<IGraphicBufferAlloc>& allocator = NULL);
const sp<IGraphicBufferAlloc>& allocator = NULL,
const sp<NativeBufferAlloc>& native_allocator = NULL);
virtual ~BufferQueue();

virtual int query(int what, int* value);
Expand Down Expand Up @@ -513,6 +515,10 @@ class BufferQueue : public BnSurfaceTexture {
// allocate new GraphicBuffer objects.
sp<IGraphicBufferAlloc> mGraphicBufferAlloc;

// mNativeBufferAlloc is an implementation-specific interface used
// to allocate GraphicBuffer objects.
sp<NativeBufferAlloc> 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.
Expand Down
34 changes: 34 additions & 0 deletions include/gui/NativeBufferAlloc.h
Original file line number Diff line number Diff line change
@@ -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 <ricardo.mendoza@canonical.com>
*/

#ifndef NATIVE_BUFFER_ALLOC_H
#define NATIVE_BUFFER_ALLOC_H

namespace android
{
class NativeBufferAlloc : public RefBase
{
public:
NativeBufferAlloc();
virtual ~NativeBufferAlloc();
virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
PixelFormat format, uint32_t usage, status_t* error);
};
}

#endif /* NATIVE_BUFFER_ALLOC_H */
29 changes: 21 additions & 8 deletions libs/gui/BufferQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ static bool isBufferGeometryUpdateRequired(sp<GraphicBuffer> buffer,
#endif

BufferQueue::BufferQueue(bool allowSynchronousMode,
const sp<IGraphicBufferAlloc>& allocator) :
const sp<IGraphicBufferAlloc>& allocator,
const sp<NativeBufferAlloc>& native_allocator) :
mDefaultWidth(1),
mDefaultHeight(1),
mMaxAcquiredBufferCount(1),
Expand All @@ -150,10 +151,15 @@ BufferQueue::BufferQueue(bool allowSynchronousMode,

ST_LOGV("BufferQueue");
if (allocator == NULL) {
sp<ISurfaceComposer> 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<ISurfaceComposer> composer(ComposerService::getComposerService());
mGraphicBufferAlloc = composer->createGraphicBufferAlloc();
if (mGraphicBufferAlloc == 0) {
ST_LOGE("createGraphicBufferAlloc() failed in BufferQueue()");
}
}
} else {
mGraphicBufferAlloc = allocator;
Expand Down Expand Up @@ -498,9 +504,16 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, sp<Fence>& outFence,

if (returnFlags & ISurfaceTexture::BUFFER_NEEDS_REALLOCATION) {
status_t error;
sp<GraphicBuffer> graphicBuffer(
mGraphicBufferAlloc->createGraphicBuffer(
w, h, format, usage, &error));

sp<GraphicBuffer> 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");
Expand Down