SurfaceFlinger: Add TrustedPresentationListener API
TrustedPresentationListener is intended to allow the producer
of a buffer layer to gain a trusted signal on whether and to
what extent a layer is presented. A strawman design would be to
provide the producer details on it's presentation (alpha,
position, scale, final crop, covered region, etc). In the strawman
design the client end would then decide itself whether each of these
parameters were in an acceptable range.
However providing the client feedback on it's per frame position would have
a negative system health impact. Furthermore in some of the target use cases
we can't even be sure the layer of interest is actively producing buffers
and so there may be no existing callback to piggy-back on.
Because of this we use a server side thresholding approach, where the client
expresses some visibility threshold and a time stability constraint. See
SurfaceComposerClient.h comment for details on these thresholds and their
computation.
Bug: 256993331
Test: LayerTrustedPresentationListener_test.cpp
Change-Id: If4bef60dc6b22ce4959c353fa2a19b0994a00f5c
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 08a13a3..63894cd 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -527,6 +527,19 @@
uint32_t getTransactionFlags() const { return mTransactionFlags; }
+ static bool computeTrustedPresentationState(const FloatRect& bounds,
+ const FloatRect& sourceBounds,
+ const Region& coveredRegion,
+ const FloatRect& screenBounds, float,
+ const ui::Transform&,
+ const TrustedPresentationThresholds&);
+ void updateTrustedPresentationState(const DisplayDevice* display, int64_t time_in_ms,
+ bool leaveState);
+
+ inline bool hasTrustedPresentationListener() {
+ return mTrustedPresentationListener.callbackInterface != nullptr;
+ }
+
// Sets the masked bits.
void setTransactionFlags(uint32_t mask);
@@ -728,6 +741,9 @@
std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForBuffer(
const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName);
+ void setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds,
+ TrustedPresentationListener const& listener);
+
// Creates a new handle each time, so we only expect
// this to be called once.
sp<IBinder> getHandle();
@@ -883,6 +899,12 @@
// These are only accessed by the main thread or the tracing thread.
State mDrawingState;
+ TrustedPresentationThresholds mTrustedPresentationThresholds;
+ TrustedPresentationListener mTrustedPresentationListener;
+ bool mLastComputedTrustedPresentationState = false;
+ bool mLastReportedTrustedPresentationState = false;
+ int64_t mEnteredTrustedPresentationStateTime = -1;
+
uint32_t mTransactionFlags{0};
// Updated in doTransaction, used to track the last sequence number we
// committed. Currently this is really only used for updating visible