BufferQueue consumers: Add discardFreeBuffer method
This method releases all free buffers owned by the buffer queue,
in order to save memory (at the cost of potential future
reallocation of buffers).
Bug: 28695173
Change-Id: I458d10373e639e3144faf673af2ba01aca36e65a
diff --git a/include/gui/BufferQueueConsumer.h b/include/gui/BufferQueueConsumer.h
index a9fce1a..8ec0546 100644
--- a/include/gui/BufferQueueConsumer.h
+++ b/include/gui/BufferQueueConsumer.h
@@ -140,6 +140,9 @@
virtual status_t getOccupancyHistory(bool forceFlush,
std::vector<OccupancyTracker::Segment>* outHistory) override;
+ // See IGraphicBufferConsumer::discardFreeBuffers
+ virtual status_t discardFreeBuffers() override;
+
// dump our state in a String
virtual void dump(String8& result, const char* prefix) const;
diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h
index 98add9e..82bc121 100644
--- a/include/gui/BufferQueueCore.h
+++ b/include/gui/BufferQueueCore.h
@@ -125,6 +125,11 @@
// all slots, even if they're currently dequeued, queued, or acquired.
void freeAllBuffersLocked();
+ // discardFreeBuffersLocked releases all currently-free buffers held by the
+ // queue, in order to reduce the memory consumption of the queue to the
+ // minimum possible without discarding data.
+ void discardFreeBuffersLocked();
+
// If delta is positive, makes more slots available. If negative, takes
// away slots. Returns false if the request can't be met.
bool adjustAvailableSlotsLocked(int delta);
diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h
index d1f4cdd..0490c3c 100644
--- a/include/gui/ConsumerBase.h
+++ b/include/gui/ConsumerBase.h
@@ -89,6 +89,9 @@
status_t getOccupancyHistory(bool forceFlush,
std::vector<OccupancyTracker::Segment>* outHistory);
+ // See IGraphicBufferConsumer::discardFreeBuffers
+ status_t discardFreeBuffers();
+
private:
ConsumerBase(const ConsumerBase&);
void operator=(const ConsumerBase&);
diff --git a/include/gui/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h
index 4915478..3b10d78 100644
--- a/include/gui/IGraphicBufferConsumer.h
+++ b/include/gui/IGraphicBufferConsumer.h
@@ -272,6 +272,11 @@
virtual status_t getOccupancyHistory(bool forceFlush,
std::vector<OccupancyTracker::Segment>* outHistory) = 0;
+ // discardFreeBuffers releases all currently-free buffers held by the queue,
+ // in order to reduce the memory consumption of the queue to the minimum
+ // possible without discarding data.
+ virtual status_t discardFreeBuffers() = 0;
+
// dump state into a string
virtual void dump(String8& result, const char* prefix) const = 0;