OSDN Git Service

ConsumerBase: discardFreeBuffers() also needs to dump its own cache
authorEino-Ville Talvala <etalvala@google.com>
Wed, 14 Jun 2017 00:09:11 +0000 (17:09 -0700)
committerEino-Ville Talvala <etalvala@google.com>
Wed, 14 Jun 2017 00:09:11 +0000 (17:09 -0700)
ConsumerBase has its own cached slots with graphic buffer references,
so it's not enough to just ask the buffer queue consumer to free
buffers.

Add code equivalent to what happens in the onBuffersReleased callback.

Test:
Bug: 62593139
Change-Id: Ibc1444b868c6150aa2da1c209e06bdba42f1595d

include/gui/IGraphicBufferConsumer.h
libs/gui/ConsumerBase.cpp

index 57cce16..3d069df 100644 (file)
@@ -267,6 +267,8 @@ public:
     // discardFreeBuffers releases all currently-free buffers held by the BufferQueue, in order to
     // reduce the memory consumption of the BufferQueue to the minimum possible without
     // discarding data.
+    // The consumer invoking this method is responsible for calling getReleasedBuffers() after this
+    // call to free up any of its locally cached buffers.
     virtual status_t discardFreeBuffers() = 0;
 
     // dump state into a string
index 5c6158c..c2b10a9 100644 (file)
@@ -253,7 +253,18 @@ status_t ConsumerBase::discardFreeBuffers() {
         CB_LOGE("discardFreeBuffers: ConsumerBase is abandoned!");
         return NO_INIT;
     }
-    return mConsumer->discardFreeBuffers();
+    status_t err = mConsumer->discardFreeBuffers();
+    if (err != OK) {
+        return err;
+    }
+    uint64_t mask;
+    mConsumer->getReleasedBuffers(&mask);
+    for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
+        if (mask & (1ULL << i)) {
+            freeBufferLocked(i);
+        }
+    }
+    return OK;
 }
 
 void ConsumerBase::dumpState(String8& result) const {