Merge "Unbind texture buffer after each drawLayers call"
diff --git a/media/libstagefright/FrameCaptureProcessor.cpp b/media/libstagefright/FrameCaptureProcessor.cpp
index 96c1195..ee642d4 100644
--- a/media/libstagefright/FrameCaptureProcessor.cpp
+++ b/media/libstagefright/FrameCaptureProcessor.cpp
@@ -164,14 +164,21 @@
 
     if (err != OK) {
         ALOGE("drawLayers returned err %d", err);
-        return err;
+    } else {
+        err = fence->wait(500);
+        if (err != OK) {
+            ALOGW("wait for fence returned err %d", err);
+            err = OK;
+        }
     }
-
-    err = fence->wait(500);
-    if (err != OK) {
-        ALOGW("wait for fence returned err %d", err);
+    mRE->cleanupPostRender();
+    // Unbind the buffer now to remove it from the RenderEngine's image cache.
+    // The buffer was put into the image cache during the drawLayers() call above.
+    const sp<GraphicBuffer> &gbuf = layerSettings.source.buffer.buffer;
+    if (gbuf != nullptr) {
+        mRE->unbindExternalTextureBuffer(gbuf->getId());
     }
-    return OK;
+    return err;
 }
 
 void FrameCaptureProcessor::onMessageReceived(const sp<AMessage> &msg) {