diff --git a/include/gui/BufferItemConsumer.h b/include/gui/BufferItemConsumer.h index 9370e81e3..52edf17fe 100644 --- a/include/gui/BufferItemConsumer.h +++ b/include/gui/BufferItemConsumer.h @@ -87,8 +87,6 @@ class BufferItemConsumer: public ConsumerBase status_t releaseBuffer(const BufferItem &item, const sp& releaseFence = Fence::NO_FENCE); - sp getProducerInterface() const { return getBufferQueue(); } - // setDefaultBufferSize is used to set the size of buffers returned by // requestBuffers when a with and height of zero is requested. status_t setDefaultBufferSize(uint32_t w, uint32_t h); diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h index 1fbfc2b4e..7e404fe84 100644 --- a/include/gui/BufferQueue.h +++ b/include/gui/BufferQueue.h @@ -78,10 +78,6 @@ public: BufferQueue(const sp& allocator = NULL); virtual ~BufferQueue(); - // dump our state in a String - virtual void dump(String8& result) const; - virtual void dump(String8& result, const char* prefix) const; - /* * IGraphicBufferProducer interface */ @@ -302,6 +298,9 @@ public: // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). virtual status_t setTransformHint(uint32_t hint); + // dump our state in a String + virtual void dump(String8& result, const char* prefix) const; + private: // freeBufferLocked frees the GraphicBuffer and sync resources for the diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h index daad75709..fb21185fd 100644 --- a/include/gui/ConsumerBase.h +++ b/include/gui/ConsumerBase.h @@ -66,10 +66,6 @@ public: // log messages. void setName(const String8& name); - // getBufferQueue returns the BufferQueue object to which this - // ConsumerBase is connected. - sp getBufferQueue() const; - // dump writes the current state to a string. Child classes should add // their state to the dump by overriding the dumpLocked method, which is // called by these methods after locking the mutex. @@ -85,12 +81,11 @@ private: void operator=(const ConsumerBase&); protected: - // ConsumerBase constructs a new ConsumerBase object to consume image - // buffers from the given BufferQueue. + // buffers from the given IGraphicBufferConsumer. // The controlledByApp flag indicates that this consumer is under the application's // control. - ConsumerBase(const sp &bufferQueue, bool controlledByApp = false); + ConsumerBase(const sp& consumer, bool controlledByApp = false); // onLastStrongRef gets called by RefBase just before the dtor of the most // derived class. It is used to clean up the buffers so that ConsumerBase @@ -104,7 +99,7 @@ protected: // from the derived class. virtual void onLastStrongRef(const void* id); - // Implementation of the BufferQueue::ConsumerListener interface. These + // Implementation of the IConsumerListener interface. These // calls are used to notify the ConsumerBase of asynchronous events in the // BufferQueue. These methods should not need to be overridden by derived // classes, but if they are overridden the ConsumerBase implementation @@ -155,7 +150,7 @@ protected: // initialization that must take place the first time a buffer is assigned // to a slot. If it is overridden the derived class's implementation must // call ConsumerBase::acquireBufferLocked. - virtual status_t acquireBufferLocked(BufferQueue::BufferItem *item, + virtual status_t acquireBufferLocked(IGraphicBufferConsumer::BufferItem *item, nsecs_t presentWhen); // releaseBufferLocked relinquishes control over a buffer, returning that @@ -226,7 +221,7 @@ protected: // The ConsumerBase has-a BufferQueue and is responsible for creating this object // if none is supplied - sp mBufferQueue; + sp mConsumer; // mMutex is the mutex used to prevent concurrent access to the member // variables of ConsumerBase objects. It must be locked whenever the diff --git a/include/gui/CpuConsumer.h b/include/gui/CpuConsumer.h index 28903508b..9290676ca 100644 --- a/include/gui/CpuConsumer.h +++ b/include/gui/CpuConsumer.h @@ -66,7 +66,7 @@ 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(const sp& bq, + CpuConsumer(const sp& bq, uint32_t maxLockedBuffers, bool controlledByApp = false); virtual ~CpuConsumer(); @@ -104,8 +104,6 @@ class CpuConsumer : public ConsumerBase // lockNextBuffer. status_t unlockBuffer(const LockedBuffer &nativeBuffer); - sp getProducerInterface() const { return getBufferQueue(); } - private: // Maximum number of buffers that can be locked at a time uint32_t mMaxLockedBuffers; diff --git a/include/gui/GLConsumer.h b/include/gui/GLConsumer.h index ac4a8328b..4c9aa8751 100644 --- a/include/gui/GLConsumer.h +++ b/include/gui/GLConsumer.h @@ -32,10 +32,6 @@ #include #include -#define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture" -#define ANDROID_GRAPHICS_FRAMEAVAILABLELISTENER_JNI_ID \ - "mFrameAvailableListener" - namespace android { // ---------------------------------------------------------------------------- @@ -85,7 +81,7 @@ 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(const sp& bq, + GLConsumer(const sp& bq, GLuint tex, GLenum texTarget = GL_TEXTURE_EXTERNAL_OES, bool useFenceSync = true, bool isControlledByApp = false); @@ -194,12 +190,6 @@ public: status_t setConsumerUsageBits(uint32_t usage); status_t setTransformHint(uint32_t hint); - // getBufferQueue returns the BufferQueue object to which this - // GLConsumer is connected. - sp getBufferQueue() const { - return mBufferQueue; - } - // detachFromContext detaches the GLConsumer from the calling thread's // current OpenGL ES context. This context must be the same as the context // that was current for previous calls to updateTexImage. diff --git a/include/gui/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h index 82b50c8ab..2ad302f48 100644 --- a/include/gui/IGraphicBufferConsumer.h +++ b/include/gui/IGraphicBufferConsumer.h @@ -188,6 +188,9 @@ public: // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). virtual status_t setTransformHint(uint32_t hint) = 0; + // dump state into a string + virtual void dump(String8& result, const char* prefix) const = 0; + public: DECLARE_META_INTERFACE(GraphicBufferConsumer); }; diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h index 6bf5b47f9..643d7cff7 100644 --- a/include/gui/SurfaceComposerClient.h +++ b/include/gui/SurfaceComposerClient.h @@ -165,6 +165,7 @@ public: private: mutable sp mCpuConsumer; + mutable sp mBufferQueue; CpuConsumer::LockedBuffer mBuffer; bool mHaveBuffer; diff --git a/libs/gui/BufferItemConsumer.cpp b/libs/gui/BufferItemConsumer.cpp index 0f818b76f..350887a1f 100644 --- a/libs/gui/BufferItemConsumer.cpp +++ b/libs/gui/BufferItemConsumer.cpp @@ -33,8 +33,8 @@ BufferItemConsumer::BufferItemConsumer(const sp& bq, uint32_t consumerUsage, int bufferCount, bool controlledByApp) : ConsumerBase(bq, controlledByApp) { - mBufferQueue->setConsumerUsageBits(consumerUsage); - mBufferQueue->setMaxAcquiredBufferCount(bufferCount); + mConsumer->setConsumerUsageBits(consumerUsage); + mConsumer->setMaxAcquiredBufferCount(bufferCount); } BufferItemConsumer::~BufferItemConsumer() { @@ -43,7 +43,7 @@ BufferItemConsumer::~BufferItemConsumer() { void BufferItemConsumer::setName(const String8& name) { Mutex::Autolock _l(mMutex); mName = name; - mBufferQueue->setConsumerName(name); + mConsumer->setConsumerName(name); } status_t BufferItemConsumer::acquireBuffer(BufferItem *item, @@ -95,12 +95,12 @@ status_t BufferItemConsumer::releaseBuffer(const BufferItem &item, status_t BufferItemConsumer::setDefaultBufferSize(uint32_t w, uint32_t h) { Mutex::Autolock _l(mMutex); - return mBufferQueue->setDefaultBufferSize(w, h); + return mConsumer->setDefaultBufferSize(w, h); } status_t BufferItemConsumer::setDefaultBufferFormat(uint32_t defaultFormat) { Mutex::Autolock _l(mMutex); - return mBufferQueue->setDefaultBufferFormat(defaultFormat); + return mConsumer->setDefaultBufferFormat(defaultFormat); } } // namespace android diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index 07c2d943a..033c2a6c4 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -720,10 +720,6 @@ status_t BufferQueue::disconnect(int api) { return err; } -void BufferQueue::dump(String8& result) const { - BufferQueue::dump(result, ""); -} - void BufferQueue::dump(String8& result, const char* prefix) const { Mutex::Autolock _l(mMutex); diff --git a/libs/gui/ConsumerBase.cpp b/libs/gui/ConsumerBase.cpp index d748786d9..c4ec8578a 100644 --- a/libs/gui/ConsumerBase.cpp +++ b/libs/gui/ConsumerBase.cpp @@ -51,9 +51,9 @@ static int32_t createProcessUniqueId() { return android_atomic_inc(&globalCounter); } -ConsumerBase::ConsumerBase(const sp& bufferQueue, bool controlledByApp) : +ConsumerBase::ConsumerBase(const sp& bufferQueue, bool controlledByApp) : mAbandoned(false), - mBufferQueue(bufferQueue) { + mConsumer(bufferQueue) { // Choose a name using the PID and a process-unique ID. mName = String8::format("unnamed-%d-%d", getpid(), createProcessUniqueId()); @@ -64,12 +64,12 @@ ConsumerBase::ConsumerBase(const sp& bufferQueue, bool controlledBy wp listener = static_cast(this); sp proxy = new BufferQueue::ProxyConsumerListener(listener); - status_t err = mBufferQueue->consumerConnect(proxy, controlledByApp); + status_t err = mConsumer->consumerConnect(proxy, controlledByApp); if (err != NO_ERROR) { CB_LOGE("ConsumerBase: error connecting to BufferQueue: %s (%d)", strerror(-err), err); } else { - mBufferQueue->setConsumerName(mName); + mConsumer->setConsumerName(mName); } } @@ -96,12 +96,6 @@ void ConsumerBase::freeBufferLocked(int slotIndex) { mSlots[slotIndex].mFrameNumber = 0; } -// Used for refactoring, should not be in final interface -sp ConsumerBase::getBufferQueue() const { - Mutex::Autolock lock(mMutex); - return mBufferQueue; -} - void ConsumerBase::onFrameAvailable() { CB_LOGV("onFrameAvailable"); @@ -128,7 +122,7 @@ void ConsumerBase::onBuffersReleased() { } uint32_t mask = 0; - mBufferQueue->getReleasedBuffers(&mask); + mConsumer->getReleasedBuffers(&mask); for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) { if (mask & (1 << i)) { freeBufferLocked(i); @@ -152,8 +146,8 @@ void ConsumerBase::abandonLocked() { freeBufferLocked(i); } // disconnect from the BufferQueue - mBufferQueue->consumerDisconnect(); - mBufferQueue.clear(); + mConsumer->consumerDisconnect(); + mConsumer.clear(); } void ConsumerBase::setFrameAvailableListener( @@ -176,13 +170,13 @@ void ConsumerBase::dumpLocked(String8& result, const char* prefix) const { result.appendFormat("%smAbandoned=%d\n", prefix, int(mAbandoned)); if (!mAbandoned) { - mBufferQueue->dump(result, prefix); + mConsumer->dump(result, prefix); } } status_t ConsumerBase::acquireBufferLocked(BufferQueue::BufferItem *item, nsecs_t presentWhen) { - status_t err = mBufferQueue->acquireBuffer(item, presentWhen); + status_t err = mConsumer->acquireBuffer(item, presentWhen); if (err != NO_ERROR) { return err; } @@ -247,7 +241,7 @@ status_t ConsumerBase::releaseBufferLocked( CB_LOGV("releaseBufferLocked: slot=%d/%llu", slot, mSlots[slot].mFrameNumber); - status_t err = mBufferQueue->releaseBuffer(slot, mSlots[slot].mFrameNumber, + status_t err = mConsumer->releaseBuffer(slot, mSlots[slot].mFrameNumber, display, eglFence, mSlots[slot].mFence); if (err == BufferQueue::STALE_BUFFER_SLOT) { freeBufferLocked(slot); diff --git a/libs/gui/CpuConsumer.cpp b/libs/gui/CpuConsumer.cpp index b8c00af0a..3db46bceb 100644 --- a/libs/gui/CpuConsumer.cpp +++ b/libs/gui/CpuConsumer.cpp @@ -30,7 +30,7 @@ namespace android { -CpuConsumer::CpuConsumer(const sp& bq, +CpuConsumer::CpuConsumer(const sp& bq, uint32_t maxLockedBuffers, bool controlledByApp) : ConsumerBase(bq, controlledByApp), mMaxLockedBuffers(maxLockedBuffers), @@ -39,8 +39,8 @@ CpuConsumer::CpuConsumer(const sp& bq, // Create tracking entries for locked buffers mAcquiredBuffers.insertAt(0, maxLockedBuffers); - mBufferQueue->setConsumerUsageBits(GRALLOC_USAGE_SW_READ_OFTEN); - mBufferQueue->setMaxAcquiredBufferCount(maxLockedBuffers); + mConsumer->setConsumerUsageBits(GRALLOC_USAGE_SW_READ_OFTEN); + mConsumer->setMaxAcquiredBufferCount(maxLockedBuffers); } CpuConsumer::~CpuConsumer() { @@ -52,19 +52,19 @@ CpuConsumer::~CpuConsumer() { void CpuConsumer::setName(const String8& name) { Mutex::Autolock _l(mMutex); mName = name; - mBufferQueue->setConsumerName(name); + mConsumer->setConsumerName(name); } status_t CpuConsumer::setDefaultBufferSize(uint32_t width, uint32_t height) { Mutex::Autolock _l(mMutex); - return mBufferQueue->setDefaultBufferSize(width, height); + return mConsumer->setDefaultBufferSize(width, height); } status_t CpuConsumer::setDefaultBufferFormat(uint32_t defaultFormat) { Mutex::Autolock _l(mMutex); - return mBufferQueue->setDefaultBufferFormat(defaultFormat); + return mConsumer->setDefaultBufferFormat(defaultFormat); } status_t CpuConsumer::lockNextBuffer(LockedBuffer *nativeBuffer) { diff --git a/libs/gui/GLConsumer.cpp b/libs/gui/GLConsumer.cpp index b8a3d286f..363e25a16 100644 --- a/libs/gui/GLConsumer.cpp +++ b/libs/gui/GLConsumer.cpp @@ -85,7 +85,7 @@ static float mtxRot90[16] = { static void mtxMul(float out[16], const float a[16], const float b[16]); -GLConsumer::GLConsumer(const sp& bq, GLuint tex, +GLConsumer::GLConsumer(const sp& bq, GLuint tex, GLenum texTarget, bool useFenceSync, bool isControlledByApp) : ConsumerBase(bq, isControlledByApp), mCurrentTransform(0), @@ -108,12 +108,12 @@ GLConsumer::GLConsumer(const sp& bq, GLuint tex, memcpy(mCurrentTransformMatrix, mtxIdentity, sizeof(mCurrentTransformMatrix)); - mBufferQueue->setConsumerUsageBits(DEFAULT_USAGE_FLAGS); + mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS); } status_t GLConsumer::setDefaultMaxBufferCount(int bufferCount) { Mutex::Autolock lock(mMutex); - return mBufferQueue->setDefaultMaxBufferCount(bufferCount); + return mConsumer->setDefaultMaxBufferCount(bufferCount); } @@ -122,7 +122,7 @@ status_t GLConsumer::setDefaultBufferSize(uint32_t w, uint32_t h) Mutex::Autolock lock(mMutex); mDefaultWidth = w; mDefaultHeight = h; - return mBufferQueue->setDefaultBufferSize(w, h); + return mConsumer->setDefaultBufferSize(w, h); } status_t GLConsumer::updateTexImage() { @@ -946,23 +946,23 @@ void GLConsumer::abandonLocked() { void GLConsumer::setName(const String8& name) { Mutex::Autolock _l(mMutex); mName = name; - mBufferQueue->setConsumerName(name); + mConsumer->setConsumerName(name); } status_t GLConsumer::setDefaultBufferFormat(uint32_t defaultFormat) { Mutex::Autolock lock(mMutex); - return mBufferQueue->setDefaultBufferFormat(defaultFormat); + return mConsumer->setDefaultBufferFormat(defaultFormat); } status_t GLConsumer::setConsumerUsageBits(uint32_t usage) { Mutex::Autolock lock(mMutex); usage |= DEFAULT_USAGE_FLAGS; - return mBufferQueue->setConsumerUsageBits(usage); + return mConsumer->setConsumerUsageBits(usage); } status_t GLConsumer::setTransformHint(uint32_t hint) { Mutex::Autolock lock(mMutex); - return mBufferQueue->setTransformHint(hint); + return mConsumer->setTransformHint(hint); } void GLConsumer::dumpLocked(String8& result, const char* prefix) const diff --git a/libs/gui/IGraphicBufferConsumer.cpp b/libs/gui/IGraphicBufferConsumer.cpp index 526328146..6d65016cf 100644 --- a/libs/gui/IGraphicBufferConsumer.cpp +++ b/libs/gui/IGraphicBufferConsumer.cpp @@ -186,7 +186,8 @@ enum { SET_CONSUMER_NAME, SET_DEFAULT_BUFFER_FORMAT, SET_CONSUMER_USAGE_BITS, - SET_TRANSFORM_HINT + SET_TRANSFORM_HINT, + DUMP, }; @@ -344,6 +345,15 @@ public: } return reply.readInt32(); } + + virtual void dump(String8& result, const char* prefix) const { + Parcel data, reply; + data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); + data.writeString8(result); + data.writeString8(String8(prefix ? prefix : "")); + remote()->transact(DUMP, data, &reply); + reply.readString8(); + } }; IMPLEMENT_META_INTERFACE(GraphicBufferConsumer, "android.gui.IGraphicBufferConsumer"); @@ -452,6 +462,14 @@ status_t BnGraphicBufferConsumer::onTransact( reply->writeInt32(result); return NO_ERROR; } break; + case DUMP: { + CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); + String8 result = data.readString8(); + String8 prefix = data.readString8(); + static_cast(this)->dump(result, prefix); + reply->writeString8(result); + return NO_ERROR; + } } return BBinder::onTransact(code, data, reply, flags); } diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index bad413883..048553c7e 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -633,8 +633,8 @@ ScreenshotClient::~ScreenshotClient() { sp ScreenshotClient::getCpuConsumer() const { if (mCpuConsumer == NULL) { - sp bq = new BufferQueue(); - mCpuConsumer = new CpuConsumer(bq, 1); + mBufferQueue = new BufferQueue(); + mCpuConsumer = new CpuConsumer(mBufferQueue, 1); mCpuConsumer->setName(String8("ScreenshotClient")); } return mCpuConsumer; @@ -653,7 +653,7 @@ status_t ScreenshotClient::update(const sp& display, mHaveBuffer = false; } - status_t err = s->captureScreen(display, cpuConsumer->getBufferQueue(), + status_t err = s->captureScreen(display, mBufferQueue, reqWidth, reqHeight, minLayerZ, maxLayerZ, true); if (err == NO_ERROR) { diff --git a/libs/gui/tests/CpuConsumer_test.cpp b/libs/gui/tests/CpuConsumer_test.cpp index f8a35b49e..afbc02696 100644 --- a/libs/gui/tests/CpuConsumer_test.cpp +++ b/libs/gui/tests/CpuConsumer_test.cpp @@ -70,7 +70,7 @@ protected: mCC = new CpuConsumer(bq, params.maxLockedBuffers); String8 name("CpuConsumer_Under_Test"); mCC->setName(name); - mSTC = new Surface(mCC->getProducerInterface()); + mSTC = new Surface(bq); mANW = mSTC; } diff --git a/libs/gui/tests/SurfaceTextureClient_test.cpp b/libs/gui/tests/SurfaceTextureClient_test.cpp index 1de9c2792..459b00116 100644 --- a/libs/gui/tests/SurfaceTextureClient_test.cpp +++ b/libs/gui/tests/SurfaceTextureClient_test.cpp @@ -42,7 +42,7 @@ protected: sp bq = new BufferQueue(); mST = new GLConsumer(bq, 123); - mSTC = new Surface(mST->getBufferQueue()); + mSTC = new Surface(bq); mANW = mSTC; // We need a valid GL context so we can test updateTexImage() @@ -710,7 +710,7 @@ protected: for (int i = 0; i < NUM_SURFACE_TEXTURES; i++) { sp bq = new BufferQueue(); sp st(new GLConsumer(bq, i)); - sp stc(new Surface(st->getBufferQueue())); + sp stc(new Surface(bq)); mEglSurfaces[i] = eglCreateWindowSurface(mEglDisplay, myConfig, static_cast(stc.get()), NULL); ASSERT_EQ(EGL_SUCCESS, eglGetError()); diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp index ae223c6d8..05b0b670c 100644 --- a/libs/gui/tests/SurfaceTexture_test.cpp +++ b/libs/gui/tests/SurfaceTexture_test.cpp @@ -387,7 +387,7 @@ protected: GLTest::SetUp(); sp bq = new BufferQueue(); mGlConsumer = new GLConsumer(bq, TEX_ID); - mSurface = new Surface(mGlConsumer->getBufferQueue()); + mSurface = new Surface(bq); mANW = mSurface.get(); } @@ -481,8 +481,9 @@ protected: virtual void SetUp() { GLTest::SetUp(); sp bq = new BufferQueue(); + mBQ = bq; mST = new GLConsumer(bq, TEX_ID); - mSTC = new Surface(mST->getBufferQueue()); + mSTC = new Surface(bq); mANW = mSTC; mTextureRenderer = new TextureRenderer(TEX_ID, mST); ASSERT_NO_FATAL_FAILURE(mTextureRenderer->SetUp()); @@ -672,6 +673,7 @@ protected: Condition mFrameCondition; }; + sp mBQ; sp mST; sp mSTC; sp mANW; @@ -1211,7 +1213,7 @@ TEST_F(SurfaceTextureGLTest, DisconnectStressTest) { }; sp dw(new DisconnectWaiter()); - mST->getBufferQueue()->consumerConnect(dw, false); + mBQ->consumerConnect(dw, false); sp pt(new ProducerThread(mANW)); diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index bcdbedbaa..0440c4c3b 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -92,7 +92,7 @@ TEST_F(SurfaceTest, ScreenshotsOfProtectedBuffersSucceed) { sp consumer = new CpuConsumer(bq, 1); sp sf(ComposerService::getComposerService()); sp display(sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); - ASSERT_EQ(NO_ERROR, sf->captureScreen(display, consumer->getBufferQueue(), + ASSERT_EQ(NO_ERROR, sf->captureScreen(display, bq, 64, 64, 0, 0x7fffffff, true)); // Set the PROTECTED usage bit and verify that the screenshot fails. Note @@ -121,7 +121,7 @@ TEST_F(SurfaceTest, ScreenshotsOfProtectedBuffersSucceed) { &buf)); ASSERT_EQ(NO_ERROR, anw->queueBuffer(anw.get(), buf, -1)); } - ASSERT_EQ(NO_ERROR, sf->captureScreen(display, consumer->getBufferQueue(), + ASSERT_EQ(NO_ERROR, sf->captureScreen(display, bq, 64, 64, 0, 0x7fffffff, true)); } diff --git a/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp index 906cd80fb..0cfd8863d 100644 --- a/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp +++ b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp @@ -90,7 +90,7 @@ android_eglCreateWindowSurfaceTexture jint _remaining; EGLint *attrib_list = (EGLint *) 0; android::sp window; - android::sp glConsumer; + android::sp producer; if (!attrib_list_ref) { _exception = 1; @@ -111,12 +111,12 @@ not_valid_surface: _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; goto exit; } - glConsumer = android::SurfaceTexture_getSurfaceTexture(_env, win); + producer = android::SurfaceTexture_getProducer(_env, win); - if (glConsumer == NULL) + if (producer == NULL) goto not_valid_surface; - window = new android::Surface(glConsumer->getBufferQueue()); + window = new android::Surface(producer); if (window == NULL) goto not_valid_surface; diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index c67f4d8f8..391131d16 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -56,6 +56,7 @@ DisplayDevice::DisplayDevice( bool isSecure, const wp& displayToken, const sp& displaySurface, + const sp& producer, EGLConfig config) : mFlinger(flinger), mType(type), mHwcDisplayId(hwcId), @@ -73,7 +74,7 @@ DisplayDevice::DisplayDevice( mLayerStack(NO_LAYER_STACK), mOrientation() { - mNativeWindow = new Surface(mDisplaySurface->getIGraphicBufferProducer()); + mNativeWindow = new Surface(producer); ANativeWindow* const window = mNativeWindow.get(); int format; diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index 748be1ab5..ecf855a79 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -76,6 +76,7 @@ public: bool isSecure, const wp& displayToken, const sp& displaySurface, + const sp& producer, EGLConfig config); ~DisplayDevice(); diff --git a/services/surfaceflinger/DisplayHardware/DisplaySurface.h b/services/surfaceflinger/DisplayHardware/DisplaySurface.h index b0f460d30..9192db5ba 100644 --- a/services/surfaceflinger/DisplayHardware/DisplaySurface.h +++ b/services/surfaceflinger/DisplayHardware/DisplaySurface.h @@ -30,8 +30,6 @@ class String8; class DisplaySurface : public virtual RefBase { public: - virtual sp getIGraphicBufferProducer() const = 0; - // prepareFrame is called after the composition configuration is known but // before composition takes place. The DisplaySurface can use the // composition type to decide how to manage the flow of buffers between diff --git a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp index 419b81cd4..807d4e17f 100644 --- a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp +++ b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp @@ -50,25 +50,22 @@ namespace android { * */ -FramebufferSurface::FramebufferSurface(HWComposer& hwc, int disp) : - ConsumerBase(new BufferQueue(new GraphicBufferAlloc())), +FramebufferSurface::FramebufferSurface(HWComposer& hwc, int disp, + const sp& consumer) : + ConsumerBase(consumer), mDisplayType(disp), mCurrentBufferSlot(-1), mCurrentBuffer(0), mHwc(hwc) { mName = "FramebufferSurface"; - mBufferQueue->setConsumerName(mName); - mBufferQueue->setConsumerUsageBits(GRALLOC_USAGE_HW_FB | + mConsumer->setConsumerName(mName); + mConsumer->setConsumerUsageBits(GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER); - mBufferQueue->setDefaultBufferFormat(mHwc.getFormat(disp)); - mBufferQueue->setDefaultBufferSize(mHwc.getWidth(disp), mHwc.getHeight(disp)); - mBufferQueue->setDefaultMaxBufferCount(NUM_FRAMEBUFFER_SURFACE_BUFFERS); -} - -sp FramebufferSurface::getIGraphicBufferProducer() const { - return getBufferQueue(); + mConsumer->setDefaultBufferFormat(mHwc.getFormat(disp)); + mConsumer->setDefaultBufferSize(mHwc.getWidth(disp), mHwc.getHeight(disp)); + mConsumer->setDefaultMaxBufferCount(NUM_FRAMEBUFFER_SURFACE_BUFFERS); } status_t FramebufferSurface::prepareFrame(CompositionType compositionType) { diff --git a/services/surfaceflinger/DisplayHardware/FramebufferSurface.h b/services/surfaceflinger/DisplayHardware/FramebufferSurface.h index 92a7f9b1e..fcda28717 100644 --- a/services/surfaceflinger/DisplayHardware/FramebufferSurface.h +++ b/services/surfaceflinger/DisplayHardware/FramebufferSurface.h @@ -37,9 +37,7 @@ class HWComposer; class FramebufferSurface : public ConsumerBase, public DisplaySurface { public: - FramebufferSurface(HWComposer& hwc, int disp); - - virtual sp getIGraphicBufferProducer() const; + FramebufferSurface(HWComposer& hwc, int disp, const sp& consumer); virtual status_t prepareFrame(CompositionType compositionType); virtual status_t compositionComplete(); diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp index 57cb36171..30b00845b 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp @@ -40,8 +40,10 @@ static const char* dbgCompositionTypeStr(DisplaySurface::CompositionType type) { } VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int32_t dispId, - const sp& sink, const String8& name) -: ConsumerBase(new BufferQueue()), + const sp& sink, + const sp& bq, + const String8& name) +: ConsumerBase(bq), mHwc(hwc), mDisplayId(dispId), mDisplayName(name), @@ -51,7 +53,7 @@ VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int32_t dispId, mDbgLastCompositionType(COMPOSITION_UNKNOWN) { mSource[SOURCE_SINK] = sink; - mSource[SOURCE_SCRATCH] = mBufferQueue; + mSource[SOURCE_SCRATCH] = bq; resetPerFrameState(); @@ -60,26 +62,15 @@ VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int32_t dispId, mSource[SOURCE_SINK]->query(NATIVE_WINDOW_HEIGHT, &sinkHeight); ConsumerBase::mName = String8::format("VDS: %s", mDisplayName.string()); - mBufferQueue->setConsumerName(ConsumerBase::mName); - mBufferQueue->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER); - mBufferQueue->setDefaultBufferSize(sinkWidth, sinkHeight); - mBufferQueue->setDefaultMaxBufferCount(2); + mConsumer->setConsumerName(ConsumerBase::mName); + mConsumer->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER); + mConsumer->setDefaultBufferSize(sinkWidth, sinkHeight); + mConsumer->setDefaultMaxBufferCount(2); } VirtualDisplaySurface::~VirtualDisplaySurface() { } -sp VirtualDisplaySurface::getIGraphicBufferProducer() const { - if (mDisplayId >= 0) { - return static_cast( - const_cast(this)); - } else { - // There won't be any interaction with HWC for this virtual display, - // so the GLES driver can pass buffers directly to the sink. - return mSource[SOURCE_SINK]; - } -} - status_t VirtualDisplaySurface::prepareFrame(CompositionType compositionType) { if (mDisplayId < 0) return NO_ERROR; @@ -294,7 +285,7 @@ status_t VirtualDisplaySurface::queueBuffer(int pslot, // Queue the buffer back into the scratch pool QueueBufferOutput scratchQBO; int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, pslot); - result = mBufferQueue->queueBuffer(sslot, input, &scratchQBO); + result = mSource[SOURCE_SCRATCH]->queueBuffer(sslot, input, &scratchQBO); if (result != NO_ERROR) return result; diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h index dc9655b62..64a8dce28 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h @@ -68,17 +68,17 @@ class HWComposer; * is released and the output buffer is queued to the sink. */ class VirtualDisplaySurface : public DisplaySurface, - private BnGraphicBufferProducer, + public BnGraphicBufferProducer, private ConsumerBase { public: VirtualDisplaySurface(HWComposer& hwc, int32_t dispId, const sp& sink, + const sp& bq, const String8& name); // // DisplaySurface interface // - virtual sp getIGraphicBufferProducer() const; virtual status_t prepareFrame(CompositionType compositionType); virtual status_t compositionComplete(); virtual status_t advanceFrame(); diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 401b0f3ff..2defe34db 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -113,8 +113,8 @@ Layer::Layer(SurfaceFlinger* flinger, const sp& client, void Layer::onFirstRef() { // Creates a custom BufferQueue for SurfaceFlingerConsumer to use - sp bq = new SurfaceTextureLayer(mFlinger); - mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(bq, mTextureName, + mBufferQueue = new SurfaceTextureLayer(mFlinger); + mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(mBufferQueue, mTextureName, GL_TEXTURE_EXTERNAL_OES, false); mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0)); @@ -228,8 +228,8 @@ sp Layer::getHandle() { return new Handle(mFlinger, this); } -sp Layer::getBufferQueue() const { - return mSurfaceFlingerConsumer->getBufferQueue(); +sp Layer::getBufferQueue() const { + return mBufferQueue; } // --------------------------------------------------------------------------- @@ -926,7 +926,7 @@ Region Layer::latchBuffer(bool& recomputeVisibleRegions) } virtual bool reject(const sp& buf, - const BufferQueue::BufferItem& item) { + const IGraphicBufferConsumer::BufferItem& item) { if (buf == NULL) { return false; } diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 9093116b0..8332a5af1 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -154,7 +154,7 @@ public: Rect computeBounds() const; sp getHandle(); - sp getBufferQueue() const; + sp getBufferQueue() const; const String8& getName() const; // ----------------------------------------------------------------------- @@ -344,6 +344,7 @@ private: // constants sp mSurfaceFlingerConsumer; + sp mBufferQueue; GLuint mTextureName; bool mPremultipliedAlpha; String8 mName; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index b0e400257..864dc3ef4 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -451,9 +451,11 @@ status_t SurfaceFlinger::readyToRun() createBuiltinDisplayLocked(type); wp token = mBuiltinDisplays[i]; + sp bq = new BufferQueue(new GraphicBufferAlloc()); + sp fbs = new FramebufferSurface(*mHwc, i, bq); sp hw = new DisplayDevice(this, type, allocateHwcDisplayId(type), isSecure, token, - new FramebufferSurface(*mHwc, i), + fbs, bq, mEGLConfig); if (i > DisplayDevice::DISPLAY_PRIMARY) { // FIXME: currently we don't get blank/unblank requests @@ -1101,16 +1103,29 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) const DisplayDeviceState& state(curr[i]); sp dispSurface; + sp producer; + sp bq = new BufferQueue(new GraphicBufferAlloc()); + int32_t hwcDisplayId = -1; if (state.isVirtualDisplay()) { // Virtual displays without a surface are dormant: // they have external state (layer stack, projection, // etc.) but no internal state (i.e. a DisplayDevice). if (state.surface != NULL) { + hwcDisplayId = allocateHwcDisplayId(state.type); - dispSurface = new VirtualDisplaySurface( - *mHwc, hwcDisplayId, state.surface, + sp vds = new VirtualDisplaySurface( + *mHwc, hwcDisplayId, state.surface, bq, state.displayName); + + dispSurface = vds; + if (hwcDisplayId >= 0) { + producer = vds; + } else { + // There won't be any interaction with HWC for this virtual display, + // so the GLES driver can pass buffers directly to the sink. + producer = state.surface; + } } } else { ALOGE_IF(state.surface!=NULL, @@ -1120,14 +1135,15 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) hwcDisplayId = allocateHwcDisplayId(state.type); // for supported (by hwc) displays we provide our // own rendering surface - dispSurface = new FramebufferSurface(*mHwc, state.type); + dispSurface = new FramebufferSurface(*mHwc, state.type, bq); + producer = bq; } const wp& display(curr.keyAt(i)); if (dispSurface != NULL) { sp hw = new DisplayDevice(this, state.type, hwcDisplayId, state.isSecure, - display, dispSurface, mEGLConfig); + display, dispSurface, producer, mEGLConfig); hw->setLayerStack(state.layerStack); hw->setProjection(state.orientation, state.viewport, state.frame); diff --git a/services/surfaceflinger/SurfaceFlingerConsumer.h b/services/surfaceflinger/SurfaceFlingerConsumer.h index 5de6d129c..aa2b37fae 100644 --- a/services/surfaceflinger/SurfaceFlingerConsumer.h +++ b/services/surfaceflinger/SurfaceFlingerConsumer.h @@ -36,7 +36,7 @@ public: class BufferRejecter { friend class SurfaceFlingerConsumer; virtual bool reject(const sp& buf, - const BufferQueue::BufferItem& item) = 0; + const IGraphicBufferConsumer::BufferItem& item) = 0; protected: virtual ~BufferRejecter() { }