From 1bac1681c60a68d88ee44db1ec95f93ffe5db1bf Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 5 Mar 2013 17:57:26 -0800 Subject: [PATCH 1/5] Return NO_MEMORY when glReadPixels() fails. Change-Id: Ic66134ef457e8442ae9135e9ec50e3d02932a253 --- services/surfaceflinger/SurfaceFlinger.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 8fa0800b6..a0d2827d7 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2815,6 +2815,8 @@ status_t SurfaceFlinger::captureScreenImplLocked( *h = sh; *f = PIXEL_FORMAT_RGBA_8888; result = NO_ERROR; + } else { + result = NO_MEMORY; } } else { result = NO_MEMORY; From a25a959b7f170dcb59ba99f7b9fd36cb8179dbb2 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Thu, 15 Aug 2013 10:05:01 -0700 Subject: [PATCH 2/5] Initialize mIndent Bug 10334731 Change-Id: Ia3aa118a1516cc480b0d85179b78c4447f982dd6 --- services/surfaceflinger/RenderEngine/ProgramCache.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/ProgramCache.cpp index 835ed8a51..f37871311 100644 --- a/services/surfaceflinger/RenderEngine/ProgramCache.cpp +++ b/services/surfaceflinger/RenderEngine/ProgramCache.cpp @@ -43,6 +43,8 @@ class Formatter { friend Formatter& indent(Formatter& f); friend Formatter& dedent(Formatter& f); public: + Formatter() : mIndent(0) {} + String8 getString() const { return mString; } From 79f0edfa8bd0329bd596ac43e7bd14cd4b9d9002 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Thu, 15 Aug 2013 10:39:11 -0700 Subject: [PATCH 3/5] Disable GLES 2.x rendering Bug 10340705 Change-Id: I91f3baf0d79655d8d031c100d0b116f745c2fbef --- services/surfaceflinger/RenderEngine/RenderEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.cpp b/services/surfaceflinger/RenderEngine/RenderEngine.cpp index ee51bd9d1..dc9cf4c5c 100644 --- a/services/surfaceflinger/RenderEngine/RenderEngine.cpp +++ b/services/surfaceflinger/RenderEngine/RenderEngine.cpp @@ -42,7 +42,7 @@ RenderEngine* RenderEngine::create(EGLDisplay display, EGLConfig config) { EGL_NONE, EGL_NONE }; - EGLContext ctxt = eglCreateContext(display, config, NULL, contextAttributes); + EGLContext ctxt = EGL_NO_CONTEXT; // eglCreateContext(display, config, NULL, contextAttributes); if (ctxt == EGL_NO_CONTEXT) { // maybe ES 2.x is not supported ALOGW("can't create an ES 2.x context, trying 1.x"); From a7395b4078b0b4f812132065acd8a3abecb2e274 Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Thu, 19 Sep 2013 13:36:07 -0700 Subject: [PATCH 4/5] GLConsumer: Add query for current frame number. Surface the underlying frame number of the current texture. Bug: 10830400 Change-Id: Ide3a7da12ea0aac54588beb6bf00dbfe2cd37653 --- include/gui/GLConsumer.h | 11 +++++++++++ libs/gui/GLConsumer.cpp | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/include/gui/GLConsumer.h b/include/gui/GLConsumer.h index 00f38b44b..75ee30c63 100644 --- a/include/gui/GLConsumer.h +++ b/include/gui/GLConsumer.h @@ -141,6 +141,13 @@ public: // documented by the source. int64_t getTimestamp(); + // getFrameNumber retrieves the frame number associated with the texture + // image set by the most recent call to updateTexImage. + // + // The frame number is an incrementing counter set to 0 at the creation of + // the BufferQueue associated with this consumer. + int64_t getFrameNumber(); + // setDefaultBufferSize is used to set the size of buffers returned by // requestBuffers when a with and height of zero is requested. // A call to setDefaultBufferSize() may trigger requestBuffers() to @@ -337,6 +344,10 @@ private: // gets set each time updateTexImage is called. int64_t mCurrentTimestamp; + // mCurrentFrameNumber is the frame counter for the current texture. + // It gets set each time updateTexImage is called. + int64_t mCurrentFrameNumber; + uint32_t mDefaultWidth, mDefaultHeight; // mFilteringEnabled indicates whether the transform matrix is computed for diff --git a/libs/gui/GLConsumer.cpp b/libs/gui/GLConsumer.cpp index 0a2afbf9b..cf3f12a0c 100644 --- a/libs/gui/GLConsumer.cpp +++ b/libs/gui/GLConsumer.cpp @@ -96,6 +96,7 @@ GLConsumer::GLConsumer(const sp& bq, uint32_t tex, mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), mCurrentFence(Fence::NO_FENCE), mCurrentTimestamp(0), + mCurrentFrameNumber(0), mDefaultWidth(1), mDefaultHeight(1), mFilteringEnabled(true), @@ -380,6 +381,7 @@ status_t GLConsumer::updateAndReleaseLocked(const BufferQueue::BufferItem& item) mCurrentScalingMode = item.mScalingMode; mCurrentTimestamp = item.mTimestamp; mCurrentFence = item.mFence; + mCurrentFrameNumber = item.mFrameNumber; computeCurrentTransformMatrixLocked(); @@ -819,6 +821,12 @@ nsecs_t GLConsumer::getTimestamp() { return mCurrentTimestamp; } +nsecs_t GLConsumer::getFrameNumber() { + ST_LOGV("getFrameNumber"); + Mutex::Autolock lock(mMutex); + return mCurrentFrameNumber; +} + EGLImageKHR GLConsumer::createImage(EGLDisplay dpy, const sp& graphicBuffer) { EGLClientBuffer cbuf = (EGLClientBuffer)graphicBuffer->getNativeBuffer(); From 8499e93f4ddb19bb66c7ab57add1d6d803c4fc26 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 25 Sep 2013 20:40:07 -0700 Subject: [PATCH 5/5] fix crashers with wifi/virtual displays Bug: 10647742 Change-Id: I4b8ed9da52ef95af3a3b3a04b98514a3776a674d --- .../DisplayHardware/VirtualDisplaySurface.cpp | 11 +++++++++++ services/surfaceflinger/SurfaceFlinger.cpp | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp index c06043d4f..88ef3928c 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp @@ -258,6 +258,17 @@ status_t VirtualDisplaySurface::dequeueBuffer(int* pslot, sp* fence, bool Source source = fbSourceForCompositionType(mCompositionType); if (source == SOURCE_SINK) { + + if (mOutputProducerSlot < 0) { + // Last chance bailout if something bad happened earlier. For example, + // in a GLES configuration, if the sink disappears then dequeueBuffer + // will fail, the GLES driver won't queue a buffer, but SurfaceFlinger + // will soldier on. So we end up here without a buffer. There should + // be lots of scary messages in the log just before this. + VDS_LOGE("dequeueBuffer: no buffer, bailing out"); + return NO_MEMORY; + } + // We already dequeued the output buffer. If the GLES driver wants // something incompatible, we have to cancel and get a new one. This // will mean that HWC will see a different output buffer between diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 879c91187..f83cc0669 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -963,6 +963,12 @@ void SurfaceFlinger::postFramebuffer() hwc.commit(); } + // make the default display current because the VirtualDisplayDevice code cannot + // deal with dequeueBuffer() being called outside of the composition loop; however + // the code below can call glFlush() which is allowed (and does in some case) call + // dequeueBuffer(). + getDefaultDisplayDevice()->makeCurrent(mEGLDisplay, mEGLContext); + for (size_t dpy=0 ; dpy hw(mDisplays[dpy]); const Vector< sp >& currentLayers(hw->getVisibleLayersSortedByZ());