SF: Register resync callback per event connection
This CL ties the resync callback to an EventThreadConnection instead
of an EventThread. This is a step towards having IDisplayEventConnection
subscribe to a given display rather than the primary display implicitly.
Each display will then have SurfaceFlinger::VsyncState that resyncs
independently at potentially different rates. Callbacks have weak
references to the per-display VsyncState owned by SurfaceFlinger.
Bug: 74619554
Test: Boot and turn display on/off repeatedly
Change-Id: Ic7cc64e2004fa07a5d54431fc330995048a4ed20
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index eb7127e..9f81476 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -706,6 +706,7 @@
void preComposition();
void postComposition();
+ void getCompositorTiming(CompositorTiming* compositorTiming);
void updateCompositorTiming(const DisplayStatInfo& stats, nsecs_t compositeTime,
std::shared_ptr<FenceTime>& presentFenceTime);
void setCompositorTimingSnapped(const DisplayStatInfo& stats,
@@ -764,14 +765,31 @@
void resyncToHardwareVsync(bool makeAvailable);
void disableHardwareVsync(bool makeUnavailable);
-public:
- void resyncWithRateLimit();
- void getCompositorTiming(CompositorTiming* compositorTiming);
-private:
// Sets the refresh rate to newFps by switching active configs, if they are available for
// the desired refresh rate.
void setRefreshRateTo(float newFps);
+ // Stores per-display state about VSYNC.
+ struct VsyncState {
+ explicit VsyncState(SurfaceFlinger& flinger) : flinger(flinger) {}
+
+ void resync();
+
+ SurfaceFlinger& flinger;
+ nsecs_t lastResyncTime = 0;
+ };
+
+ const std::shared_ptr<VsyncState> mPrimaryVsyncState{std::make_shared<VsyncState>(*this)};
+
+ auto makeResyncCallback() {
+ std::weak_ptr<VsyncState> ptr = mPrimaryVsyncState;
+ return [ptr]() {
+ if (const auto vsync = ptr.lock()) {
+ vsync->resync();
+ }
+ };
+ }
+
/* ------------------------------------------------------------------------
* Debugging & dumpsys
*/