diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 975d00575..b628a15f8 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -178,19 +178,38 @@ int Surface::setSwapInterval(int interval) { int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { ATRACE_CALL(); ALOGV("Surface::dequeueBuffer"); - Mutex::Autolock lock(mMutex); + + int reqW; + int reqH; + bool swapIntervalZero; + uint32_t reqFormat; + uint32_t reqUsage; + + { + Mutex::Autolock lock(mMutex); + + reqW = mReqWidth ? mReqWidth : mUserWidth; + reqH = mReqHeight ? mReqHeight : mUserHeight; + + swapIntervalZero = mSwapIntervalZero; + reqFormat = mReqFormat; + reqUsage = mReqUsage; + } // Drop the lock so that we can still touch the Surface while blocking in IGBP::dequeueBuffer + int buf = -1; - int reqW = mReqWidth ? mReqWidth : mUserWidth; - int reqH = mReqHeight ? mReqHeight : mUserHeight; sp fence; - status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, mSwapIntervalZero, - reqW, reqH, mReqFormat, mReqUsage); + status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, swapIntervalZero, + reqW, reqH, reqFormat, reqUsage); + if (result < 0) { - ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(%d, %d, %d, %d)" - "failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage, + ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(%d, %d, %d, %d, %d)" + "failed: %d", swapIntervalZero, reqW, reqH, reqFormat, reqUsage, result); return result; } + + Mutex::Autolock lock(mMutex); + sp& gbuf(mSlots[buf].buffer); // this should never happen