Add promise for buffer releaseFence to LayerFE.
Buffers can only be released when a release fence fires.
Instead of tracking and waiting for each layer's Futures to
complete, LayerFE can keep track of its own Future via a
promise of a fence. This cleans up the shared futures that
are currently being tracked and allow us to setup for
eventual goals to reduce the number of screenshot calls to
the main thread.
Tests using a virtual display are modified to use the
mirrorDisplay API with a unique layerstack.
Bug: b/294936197, b/285553970
Test: manual (screenshot, camera, rotation, picture-in-picture)
Test: presubmit
Test: atest CompositionEnginePostCompositionTest
Test: atest SurfaceFlinger_test
Change-Id: I3a0af2cd02d3d010a1ea7c860c5cb0bc20837ec2
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 0ceecec..9108869 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -559,6 +559,14 @@
void onLayerDisplayed(ftl::SharedFuture<FenceResult>, ui::LayerStack layerStack,
std::function<FenceResult(FenceResult)>&& continuation = nullptr);
+ // Tracks mLastClientCompositionFence and gets the callback handle for this layer.
+ sp<CallbackHandle> findCallbackHandle();
+
+ // Adds the future release fence to a list of fences that are used to release the
+ // last presented buffer. Also keeps track of the layerstack in a list of previous
+ // layerstacks that have been presented.
+ void prepareReleaseCallbacks(ftl::Future<FenceResult>, ui::LayerStack layerStack);
+
void setWasClientComposed(const sp<Fence>& fence) {
mLastClientCompositionFence = fence;
mClearClientCompositionFenceOnLayerDisplayed = false;
@@ -934,6 +942,7 @@
// the release fences from the correct displays when we release the last buffer
// from the layer.
std::vector<ui::LayerStack> mPreviouslyPresentedLayerStacks;
+
struct FenceAndContinuation {
ftl::SharedFuture<FenceResult> future;
std::function<FenceResult(FenceResult)> continuation;
@@ -946,7 +955,16 @@
}
}
};
- std::vector<FenceAndContinuation> mAdditionalPreviousReleaseFences;
+ std::vector<FenceAndContinuation> mPreviousReleaseFenceAndContinuations;
+
+ // Release fences for buffers that have not yet received a release
+ // callback. A release callback may not be given when capturing
+ // screenshots asynchronously. There may be no buffer update for the
+ // layer, but the layer will still be composited on the screen in every
+ // frame. Kepping track of these fences ensures that they are not dropped
+ // and can be dispatched to the client at a later time.
+ std::vector<ftl::Future<FenceResult>> mAdditionalPreviousReleaseFences;
+
// Exposed so SurfaceFlinger can assert that it's held
const sp<SurfaceFlinger> mFlinger;