Surface: add getRemovedBuffer API
This allows clients to optionally sign up to track
buffers going out of Surface.
Test: compile
Bug: 34461678
Change-Id: I8696b304c169099c872bd9ba783015c0f0dad73a
diff --git a/include/gui/Surface.h b/include/gui/Surface.h
index 62f6cad..88ef010 100644
--- a/include/gui/Surface.h
+++ b/include/gui/Surface.h
@@ -257,10 +257,25 @@
virtual int query(int what, int* value) const;
virtual int connect(int api, const sp<IProducerListener>& listener);
+
+ // When reportBufferRemoval is true, clients must call getAndFlushRemovedBuffers to fetch
+ // GraphicBuffers removed from this surface after a dequeueBuffer, detachNextBuffer or
+ // attachBuffer call. This allows clients with their own buffer caches to free up buffers no
+ // longer in use by this surface.
+ virtual int connect(
+ int api, const sp<IProducerListener>& listener,
+ bool reportBufferRemoval);
virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer,
sp<Fence>* outFence);
virtual int attachBuffer(ANativeWindowBuffer*);
+ // When client connects to Surface with reportBufferRemoval set to true, any buffers removed
+ // from this Surface will be collected and returned here. Once this method returns, these
+ // buffers will no longer be referenced by this Surface unless they are attached to this
+ // Surface later. The list of removed buffers will only be stored until the next dequeueBuffer,
+ // detachNextBuffer, or attachBuffer call.
+ status_t getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out);
+
protected:
enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS };
enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
@@ -414,6 +429,9 @@
// A cached copy of the FrameEventHistory maintained by the consumer.
bool mEnableFrameTimestamps = false;
std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory;
+
+ bool mReportRemovedBuffers = false;
+ std::vector<sp<GraphicBuffer>> mRemovedBuffers;
};
} // namespace android