Introduce release buffer callback for BufferStateLayer
Currently BLAST clients use the TransactionCompleted callbacks to
determine when to release buffers. The TransactionCompleted callback
is overloaded. For transactions without buffers, the callback is
called when the transaction is applied on the server. If the
Transaction contains one or more buffers, the callback is called when
all the buffers are latched and ready to be presented. If we have
multiple buffers on multiple transactions, where one or more buffers
maybe dropped, the pending callbacks are called together. This may
delay signaling the client when a buffer can be released.
To fix this, we introduce a new buffer release callback that is
called as soon as a buffer is dropped by the server or when a new
buffer has been latched and the buffer will no longer be presented.
This new callback provides a graphic bufferid to identify the buffer
that can be released and a release fence to wait on.
BlastBufferQueue has been switched to use this new callback. Other
BLAST users continue to use the existing callback.
Test: go/wm-smoke
Test: atest ReleaseBufferCallbackTest
Bug: 178385281
Change-Id: Idd88e4994e543443198a5a8cfa0e3f5f67d5d482
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 26d8e74..85ff479 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -312,6 +312,7 @@
// When the transaction was posted
nsecs_t postTime;
+ sp<ITransactionCompletedListener> releaseBufferListener;
// SurfaceFrame that tracks the timeline of Transactions that contain a Buffer. Only one
// such SurfaceFrame exists because only one buffer can be presented on the layer per vsync.
// If multiple buffers are queued, the prior ones will be dropped, along with the
@@ -466,7 +467,8 @@
nsecs_t /*postTime*/, nsecs_t /*desiredPresentTime*/,
bool /*isAutoTimestamp*/, const client_cache_t& /*clientCacheId*/,
uint64_t /* frameNumber */, std::optional<nsecs_t> /* dequeueTime */,
- const FrameTimelineInfo& /*info*/) {
+ const FrameTimelineInfo& /*info*/,
+ const sp<ITransactionCompletedListener>& /* releaseBufferListener */) {
return false;
};
virtual bool setAcquireFence(const sp<Fence>& /*fence*/) { return false; };
@@ -774,6 +776,12 @@
virtual uint32_t doTransaction(uint32_t transactionFlags);
/*
+ * Called before updating the drawing state buffer. Used by BufferStateLayer to release any
+ * unlatched buffers in the drawing state.
+ */
+ virtual void bufferMayChange(sp<GraphicBuffer>& /* newBuffer */){};
+
+ /*
* Remove relative z for the layer if its relative parent is not part of the
* provided layer tree.
*/