diff --git a/cmds/flatland/GLHelper.cpp b/cmds/flatland/GLHelper.cpp index 1a1c9a3027..ddf3aa8686 100644 --- a/cmds/flatland/GLHelper.cpp +++ b/cmds/flatland/GLHelper.cpp @@ -25,6 +25,7 @@ namespace android { GLHelper::GLHelper() : + mGraphicBufferAlloc(new GraphicBufferAlloc()), mDisplay(EGL_NO_DISPLAY), mContext(EGL_NO_CONTEXT), mDummySurface(EGL_NO_SURFACE), @@ -202,7 +203,7 @@ bool GLHelper::createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h, sp* glConsumer, EGLSurface* surface) { sp producer; sp consumer; - BufferQueue::createBufferQueue(&producer, &consumer); + BufferQueue::createBufferQueue(&producer, &consumer, mGraphicBufferAlloc); sp glc = new GLConsumer(consumer, name, GL_TEXTURE_EXTERNAL_OES, false, true); glc->setDefaultBufferSize(w, h); diff --git a/cmds/flatland/GLHelper.h b/cmds/flatland/GLHelper.h index d09463a9b8..7a9e9e3ea2 100644 --- a/cmds/flatland/GLHelper.h +++ b/cmds/flatland/GLHelper.h @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -74,6 +75,8 @@ private: bool setUpShaders(const ShaderDesc* shaderDescs, size_t numShaders); + sp mGraphicBufferAlloc; + EGLDisplay mDisplay; EGLContext mContext; EGLSurface mDummySurface; diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h index c48ffb4eb2..09300a20c9 100644 --- a/include/gui/BufferQueue.h +++ b/include/gui/BufferQueue.h @@ -76,7 +76,8 @@ public: // producers and consumers. allocator is used to allocate all the // needed gralloc buffers. static void createBufferQueue(sp* outProducer, - sp* outConsumer); + sp* outConsumer, + const sp& allocator = NULL); private: BufferQueue(); // Create through createBufferQueue diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h index 4a6471e2e6..fbd5114c1d 100644 --- a/include/gui/BufferQueueCore.h +++ b/include/gui/BufferQueueCore.h @@ -75,7 +75,7 @@ public: // BufferQueueCore manages a pool of gralloc memory slots to be used by // producers and consumers. allocator is used to allocate all the needed // gralloc buffers. - BufferQueueCore(); + BufferQueueCore(const sp& allocator = NULL); virtual ~BufferQueueCore(); private: diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index 61da85f77c..ccbb5a25f3 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -62,13 +62,14 @@ void BufferQueue::ProxyConsumerListener::onSidebandStreamChanged() { } void BufferQueue::createBufferQueue(sp* outProducer, - sp* outConsumer) { + sp* outConsumer, + const sp& allocator) { LOG_ALWAYS_FATAL_IF(outProducer == NULL, "BufferQueue: outProducer must not be NULL"); LOG_ALWAYS_FATAL_IF(outConsumer == NULL, "BufferQueue: outConsumer must not be NULL"); - sp core(new BufferQueueCore()); + sp core(new BufferQueueCore(allocator)); LOG_ALWAYS_FATAL_IF(core == NULL, "BufferQueue: failed to create BufferQueueCore"); diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp index d005d5000e..c24ad19897 100644 --- a/libs/gui/BufferQueueCore.cpp +++ b/libs/gui/BufferQueueCore.cpp @@ -38,8 +38,8 @@ static String8 getUniqueName() { android_atomic_inc(&counter)); } -BufferQueueCore::BufferQueueCore() : - mAllocator(), +BufferQueueCore::BufferQueueCore(const sp& allocator) : + mAllocator(allocator), mMutex(), mIsAbandoned(false), mConsumerControlledByApp(false), @@ -75,12 +75,13 @@ BufferQueueCore::BufferQueueCore() : mSingleBufferCache(Rect::INVALID_RECT, 0, NATIVE_WINDOW_SCALING_MODE_FREEZE, HAL_DATASPACE_UNKNOWN) { - sp composer(ComposerService::getComposerService()); - mAllocator = composer->createGraphicBufferAlloc(); - if (mAllocator == NULL) { - BQ_LOGE("createGraphicBufferAlloc failed"); + if (allocator == NULL) { + sp composer(ComposerService::getComposerService()); + mAllocator = composer->createGraphicBufferAlloc(); + if (mAllocator == NULL) { + BQ_LOGE("createGraphicBufferAlloc failed"); + } } - for (int slot = 0; slot < BufferQueueDefs::NUM_BUFFER_SLOTS; ++slot) { mFreeSlots.insert(slot); } diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 66c2251c80..1e33847406 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -483,7 +483,8 @@ void SurfaceFlinger::init() { sp producer; sp consumer; - BufferQueue::createBufferQueue(&producer, &consumer); + BufferQueue::createBufferQueue(&producer, &consumer, + new GraphicBufferAlloc()); sp fbs = new FramebufferSurface(*mHwc, i, consumer); @@ -1435,7 +1436,8 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) sp producer; sp bqProducer; sp bqConsumer; - BufferQueue::createBufferQueue(&bqProducer, &bqConsumer); + BufferQueue::createBufferQueue(&bqProducer, &bqConsumer, + new GraphicBufferAlloc()); int32_t hwcDisplayId = -1; if (state.isVirtualDisplay()) {