From ba93b3f8e403636b614a4a379f9421bc70dca84f Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Thu, 1 Aug 2013 15:48:40 -0700 Subject: [PATCH] log an error when dequeueBuffer gets a NULL Fence Bug: 9858745 Change-Id: If35d6a7d770bf0a42d55bc55880a9ddb721fcfd0 --- libs/gui/BufferQueue.cpp | 13 +++++++++---- libs/gui/IGraphicBufferProducer.cpp | 11 ++++------- libs/gui/Surface.cpp | 10 ++++++---- libs/gui/SurfaceComposerClient.cpp | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index 45488ff8d..e20ac8679 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -406,6 +406,13 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, sp* outFence, bool async returnFlags |= IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION; } + + if (CC_UNLIKELY(mSlots[buf].mFence == NULL)) { + ST_LOGE("dequeueBuffer: about to return a NULL fence from mSlot. " + "buf=%d, w=%d, h=%d, format=%d", + buf, buffer->width, buffer->height, buffer->format); + } + dpy = mSlots[buf].mEglDisplay; eglFence = mSlots[buf].mEglFence; *outFence = mSlots[buf].mFence; @@ -416,11 +423,9 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, sp* outFence, bool async if (returnFlags & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) { status_t error; sp graphicBuffer( - mGraphicBufferAlloc->createGraphicBuffer( - w, h, format, usage, &error)); + mGraphicBufferAlloc->createGraphicBuffer(w, h, format, usage, &error)); if (graphicBuffer == 0) { - ST_LOGE("dequeueBuffer: SurfaceComposer::createGraphicBuffer " - "failed"); + ST_LOGE("dequeueBuffer: SurfaceComposer::createGraphicBuffer failed"); return error; } diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp index 48b28708f..e3d2a20df 100644 --- a/libs/gui/IGraphicBufferProducer.cpp +++ b/libs/gui/IGraphicBufferProducer.cpp @@ -94,13 +94,10 @@ public: return result; } *buf = reply.readInt32(); - bool fenceWasWritten = reply.readInt32(); - if (fenceWasWritten) { - // If the fence was written by the callee, then overwrite the - // caller's fence here. If it wasn't written then don't touch the - // caller's fence. + bool nonNull = reply.readInt32(); + if (nonNull) { *fence = new Fence(); - reply.read(*(fence->get())); + reply.read(**fence); } result = reply.readInt32(); return result; @@ -209,7 +206,7 @@ status_t BnGraphicBufferProducer::onTransact( reply->writeInt32(buf); reply->writeInt32(fence != NULL); if (fence != NULL) { - reply->write(*fence.get()); + reply->write(*fence); } reply->writeInt32(result); return NO_ERROR; diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 998ea8ac8..fdb7d3d93 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -175,8 +175,7 @@ int Surface::setSwapInterval(int interval) { return NO_ERROR; } -int Surface::dequeueBuffer(android_native_buffer_t** buffer, - int* fenceFd) { +int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { ATRACE_CALL(); ALOGV("Surface::dequeueBuffer"); Mutex::Autolock lock(mMutex); @@ -193,6 +192,10 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, return result; } sp& gbuf(mSlots[buf].buffer); + + // this should never happen + ALOGE_IF(fence == NULL, "Surface::dequeueBuffer: received null Fence! buf=%d", buf); + if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) { freeAllBuffers(); } @@ -200,8 +203,7 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) { result = mGraphicBufferProducer->requestBuffer(buf, &gbuf); if (result != NO_ERROR) { - ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", - result); + ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", result); return result; } } diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 94f21b645..bad413883 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -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, cpuConsumer->getBufferQueue(), reqWidth, reqHeight, minLayerZ, maxLayerZ, true); if (err == NO_ERROR) {