From 8f938a53385a3c6d1c6aa24b3f38437bb2cc47ae Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 12 Jul 2013 22:06:26 -0700 Subject: [PATCH] always pass the BufferQueue explicitely to consumers Change-Id: I883b0a7b19d8e722f9ab714ba6f49e658b02ca86 --- cmds/flatland/GLHelper.cpp | 4 ++-- include/gui/BufferItemConsumer.h | 4 +++- include/gui/CpuConsumer.h | 5 ++++- include/gui/GLConsumer.h | 6 +++--- libs/gui/BufferItemConsumer.cpp | 6 +++--- libs/gui/CpuConsumer.cpp | 5 +++-- libs/gui/GLConsumer.cpp | 6 +++--- libs/gui/SurfaceComposerClient.cpp | 3 ++- libs/gui/tests/CpuConsumer_test.cpp | 3 ++- libs/gui/tests/SurfaceTextureClient_test.cpp | 6 ++++-- libs/gui/tests/SurfaceTexture_test.cpp | 6 ++++-- services/surfaceflinger/Layer.cpp | 4 ++-- services/surfaceflinger/SurfaceFlingerConsumer.h | 9 ++++----- 13 files changed, 39 insertions(+), 28 deletions(-) diff --git a/cmds/flatland/GLHelper.cpp b/cmds/flatland/GLHelper.cpp index 4f7697f4a..89eb95fd9 100644 --- a/cmds/flatland/GLHelper.cpp +++ b/cmds/flatland/GLHelper.cpp @@ -199,8 +199,8 @@ bool GLHelper::getShaderProgram(const char* name, GLuint* outPgm) { bool GLHelper::createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h, sp* glConsumer, EGLSurface* surface) { sp bq = new BufferQueue(true, mGraphicBufferAlloc); - sp glc = new GLConsumer(name, true, - GL_TEXTURE_EXTERNAL_OES, false, bq); + sp glc = new GLConsumer(bq, name, + GL_TEXTURE_EXTERNAL_OES, false); glc->setDefaultBufferSize(w, h); glc->setDefaultMaxBufferCount(3); glc->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER); diff --git a/include/gui/BufferItemConsumer.h b/include/gui/BufferItemConsumer.h index 5bf9acbe1..0af6f8ea8 100644 --- a/include/gui/BufferItemConsumer.h +++ b/include/gui/BufferItemConsumer.h @@ -29,6 +29,8 @@ namespace android { +class BufferQueue; + /** * BufferItemConsumer is a BufferQueue consumer endpoint that allows clients * access to the whole BufferItem entry from BufferQueue. Multiple buffers may @@ -49,7 +51,7 @@ class BufferItemConsumer: public ConsumerBase // the consumer usage flags passed to the graphics allocator. The // bufferCount parameter specifies how many buffers can be locked for user // access at the same time. - BufferItemConsumer(uint32_t consumerUsage, + BufferItemConsumer(const sp& bq, uint32_t consumerUsage, int bufferCount = BufferQueue::MIN_UNDEQUEUED_BUFFERS, bool synchronousMode = false); diff --git a/include/gui/CpuConsumer.h b/include/gui/CpuConsumer.h index 3c178ef47..5f1e36993 100644 --- a/include/gui/CpuConsumer.h +++ b/include/gui/CpuConsumer.h @@ -28,6 +28,8 @@ namespace android { +class BufferQueue; + /** * CpuConsumer is a BufferQueue consumer endpoint that allows direct CPU * access to the underlying gralloc buffers provided by BufferQueue. Multiple @@ -64,7 +66,8 @@ class CpuConsumer : public ConsumerBase // Create a new CPU consumer. The maxLockedBuffers parameter specifies // how many buffers can be locked for user access at the same time. - CpuConsumer(uint32_t maxLockedBuffers, bool synchronousMode = true); + CpuConsumer(const sp& bq, + uint32_t maxLockedBuffers, bool synchronousMode = true); virtual ~CpuConsumer(); diff --git a/include/gui/GLConsumer.h b/include/gui/GLConsumer.h index fbc884071..65544bd1d 100644 --- a/include/gui/GLConsumer.h +++ b/include/gui/GLConsumer.h @@ -85,9 +85,9 @@ public: // purely to allow a GLConsumer to be transferred from one consumer // context to another. If such a transfer is not needed there is no // requirement that either of these methods be called. - GLConsumer(GLuint tex, bool allowSynchronousMode = true, - GLenum texTarget = GL_TEXTURE_EXTERNAL_OES, bool useFenceSync = true, - const sp &bufferQueue = 0); + GLConsumer(const sp& bq, + GLuint tex, GLenum texTarget = GL_TEXTURE_EXTERNAL_OES, + bool useFenceSync = true); // updateTexImage acquires the most recently queued buffer, and sets the // image contents of the target texture to it. diff --git a/libs/gui/BufferItemConsumer.cpp b/libs/gui/BufferItemConsumer.cpp index 8d86c5906..f5b2c7eb3 100644 --- a/libs/gui/BufferItemConsumer.cpp +++ b/libs/gui/BufferItemConsumer.cpp @@ -29,9 +29,9 @@ namespace android { -BufferItemConsumer::BufferItemConsumer(uint32_t consumerUsage, - int bufferCount, bool synchronousMode) : - ConsumerBase(new BufferQueue(true) ) +BufferItemConsumer::BufferItemConsumer(const sp& bq, + uint32_t consumerUsage, int bufferCount, bool synchronousMode) : + ConsumerBase(bq) { mBufferQueue->setConsumerUsageBits(consumerUsage); mBufferQueue->setSynchronousMode(synchronousMode); diff --git a/libs/gui/CpuConsumer.cpp b/libs/gui/CpuConsumer.cpp index 56bc7c66e..adddfc2c6 100644 --- a/libs/gui/CpuConsumer.cpp +++ b/libs/gui/CpuConsumer.cpp @@ -30,8 +30,9 @@ namespace android { -CpuConsumer::CpuConsumer(uint32_t maxLockedBuffers, bool synchronousMode) : - ConsumerBase(new BufferQueue(true) ), +CpuConsumer::CpuConsumer(const sp& bq, + uint32_t maxLockedBuffers, bool synchronousMode) : + ConsumerBase(bq), mMaxLockedBuffers(maxLockedBuffers), mCurrentLockedBuffers(0) { diff --git a/libs/gui/GLConsumer.cpp b/libs/gui/GLConsumer.cpp index d12083fcb..07f27c3aa 100644 --- a/libs/gui/GLConsumer.cpp +++ b/libs/gui/GLConsumer.cpp @@ -78,9 +78,9 @@ static float mtxRot90[16] = { static void mtxMul(float out[16], const float a[16], const float b[16]); -GLConsumer::GLConsumer(GLuint tex, bool allowSynchronousMode, - GLenum texTarget, bool useFenceSync, const sp &bufferQueue) : - ConsumerBase(bufferQueue == 0 ? new BufferQueue(allowSynchronousMode) : bufferQueue), +GLConsumer::GLConsumer(const sp& bq, GLuint tex, + GLenum texTarget, bool useFenceSync) : + ConsumerBase(bq), mCurrentTransform(0), mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), mCurrentFence(Fence::NO_FENCE), diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index f345df88b..94f21b645 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -633,7 +633,8 @@ ScreenshotClient::~ScreenshotClient() { sp ScreenshotClient::getCpuConsumer() const { if (mCpuConsumer == NULL) { - mCpuConsumer = new CpuConsumer(1); + sp bq = new BufferQueue(); + mCpuConsumer = new CpuConsumer(bq, 1); mCpuConsumer->setName(String8("ScreenshotClient")); } return mCpuConsumer; diff --git a/libs/gui/tests/CpuConsumer_test.cpp b/libs/gui/tests/CpuConsumer_test.cpp index 73fdd046c..f8a35b49e 100644 --- a/libs/gui/tests/CpuConsumer_test.cpp +++ b/libs/gui/tests/CpuConsumer_test.cpp @@ -66,7 +66,8 @@ protected: test_info->name(), params.width, params.height, params.maxLockedBuffers, params.format); - mCC = new CpuConsumer(params.maxLockedBuffers); + sp bq = new BufferQueue(); + mCC = new CpuConsumer(bq, params.maxLockedBuffers); String8 name("CpuConsumer_Under_Test"); mCC->setName(name); mSTC = new Surface(mCC->getProducerInterface()); diff --git a/libs/gui/tests/SurfaceTextureClient_test.cpp b/libs/gui/tests/SurfaceTextureClient_test.cpp index 7376b4ce8..46bcb2263 100644 --- a/libs/gui/tests/SurfaceTextureClient_test.cpp +++ b/libs/gui/tests/SurfaceTextureClient_test.cpp @@ -40,7 +40,8 @@ protected: ALOGV("Begin test: %s.%s", testInfo->test_case_name(), testInfo->name()); - mST = new GLConsumer(123); + sp bq = new BufferQueue(); + mST = new GLConsumer(bq, 123); mSTC = new Surface(mST->getBufferQueue()); mANW = mSTC; @@ -715,7 +716,8 @@ protected: ASSERT_NE(EGL_NO_CONTEXT, mEglContext); for (int i = 0; i < NUM_SURFACE_TEXTURES; i++) { - sp st(new GLConsumer(i)); + sp bq = new BufferQueue(); + sp st(new GLConsumer(bq, i)); sp stc(new Surface(st->getBufferQueue())); mEglSurfaces[i] = eglCreateWindowSurface(mEglDisplay, myConfig, static_cast(stc.get()), NULL); diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp index dd6c43551..d97521aea 100644 --- a/libs/gui/tests/SurfaceTexture_test.cpp +++ b/libs/gui/tests/SurfaceTexture_test.cpp @@ -385,7 +385,8 @@ protected: virtual void SetUp() { GLTest::SetUp(); - mGlConsumer = new GLConsumer(TEX_ID); + sp bq = new BufferQueue(); + mGlConsumer = new GLConsumer(bq, TEX_ID); mSurface = new Surface(mGlConsumer->getBufferQueue()); mANW = mSurface.get(); @@ -479,7 +480,8 @@ protected: virtual void SetUp() { GLTest::SetUp(); - mST = new GLConsumer(TEX_ID); + sp bq = new BufferQueue(); + mST = new GLConsumer(bq, TEX_ID); mSTC = new Surface(mST->getBufferQueue()); mANW = mSTC; mTextureRenderer = new TextureRenderer(TEX_ID, mST); diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index f31d6508b..2962115bd 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -110,8 +110,8 @@ void Layer::onFirstRef() { // Creates a custom BufferQueue for SurfaceFlingerConsumer to use sp bq = new SurfaceTextureLayer(mFlinger); - mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(mTextureName, true, - GL_TEXTURE_EXTERNAL_OES, false, bq); + mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(bq, mTextureName, + GL_TEXTURE_EXTERNAL_OES, false); mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0)); mSurfaceFlingerConsumer->setFrameAvailableListener(this); diff --git a/services/surfaceflinger/SurfaceFlingerConsumer.h b/services/surfaceflinger/SurfaceFlingerConsumer.h index d774c339d..5de6d129c 100644 --- a/services/surfaceflinger/SurfaceFlingerConsumer.h +++ b/services/surfaceflinger/SurfaceFlingerConsumer.h @@ -27,11 +27,10 @@ namespace android { */ class SurfaceFlingerConsumer : public GLConsumer { public: - SurfaceFlingerConsumer(GLuint tex, bool allowSynchronousMode = true, - GLenum texTarget = GL_TEXTURE_EXTERNAL_OES, bool useFenceSync = true, - const sp &bufferQueue = 0) - : GLConsumer(tex, allowSynchronousMode, texTarget, useFenceSync, - bufferQueue) + SurfaceFlingerConsumer(const sp& bq, GLuint tex, + GLenum texTarget = GL_TEXTURE_EXTERNAL_OES, + bool useFenceSync = true) + : GLConsumer(bq, tex, texTarget, useFenceSync) {} class BufferRejecter {