From aaa3ecff4b49e0918c252e02b3aa18a3ad0d503d Mon Sep 17 00:00:00 2001 From: Jamie Gennis Date: Thu, 17 Nov 2011 16:00:44 -0800 Subject: [PATCH] SurfaceTexture: fix a bug with buffer reallocation This change fixes an issue involving buffer reallocation and the ALLOW_DEQUEUE_CURRENT_BUFFER mode in SurfaceTexture. The bug happened when the buffer slot currently attached to the GL texture was selected for dequeuing, but the dequeue operation caused the buffer to be reallocated. Because the buffer is new, the image producer could fill the buffer and queue it before an updateTexImage call, which would result in the "slot %d is current" error in queueBuffer. Bug: 5631630 Change-Id: Icdd8bc5cad3c7db43953446d9be2603aaea11a8d --- libs/gui/SurfaceTexture.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp index 374f3c524..ab154edff 100644 --- a/libs/gui/SurfaceTexture.cpp +++ b/libs/gui/SurfaceTexture.cpp @@ -434,6 +434,11 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h, mSlots[buf].mEglImage = EGL_NO_IMAGE_KHR; mSlots[buf].mEglDisplay = EGL_NO_DISPLAY; } + if (mCurrentTexture == buf) { + // The current texture no longer references the buffer in this slot + // since we just allocated a new buffer. + mCurrentTexture = INVALID_BUFFER_SLOT; + } returnFlags |= ISurfaceTexture::BUFFER_NEEDS_REALLOCATION; } ST_LOGV("dequeueBuffer: returning slot=%d buf=%p flags=%#x", buf,