Add pending period to DispSync.
When the period is updated due to a config change, cache the period
and don't immediately update the model until we actually observe updated
vsyncs from the hardware.
To make this more reliable, force hardware vsync to be enabled when we
first initiate a refresh rate change.
Also, override offsets with custom offsets while the period is in flux,
so that we don't fall into bad offsets when ramping up to 90hz
Bug: 128848865
Bug: 128860504
Test: systrace
Change-Id: I6aa87ad29b3effce9067a1d54d444023c7362b22
diff --git a/services/surfaceflinger/Scheduler/DispSync.h b/services/surfaceflinger/Scheduler/DispSync.h
index de2b874..8f8b8e7 100644
--- a/services/surfaceflinger/Scheduler/DispSync.h
+++ b/services/surfaceflinger/Scheduler/DispSync.h
@@ -49,7 +49,7 @@
virtual void reset() = 0;
virtual bool addPresentFence(const std::shared_ptr<FenceTime>&) = 0;
virtual void beginResync() = 0;
- virtual bool addResyncSample(nsecs_t timestamp) = 0;
+ virtual bool addResyncSample(nsecs_t timestamp, bool* periodChanged) = 0;
virtual void endResync() = 0;
virtual void setPeriod(nsecs_t period) = 0;
virtual nsecs_t getPeriod() = 0;
@@ -119,7 +119,13 @@
// addPresentFence returns true indicating that the model has drifted away
// from the hardware vsync events.
void beginResync() override;
- bool addResyncSample(nsecs_t timestamp) override;
+ // Adds a vsync sample to the dispsync model. The timestamp is the time
+ // of the vsync event that fired. periodChanged will return true if the
+ // vsync period was detected to have changed to mPendingPeriod.
+ //
+ // This method will return true if more vsync samples are needed to lock
+ // down the DispSync model, and false otherwise.
+ bool addResyncSample(nsecs_t timestamp, bool* periodChanged) override;
void endResync() override;
// The setPeriod method sets the vsync event model's period to a specific
@@ -199,6 +205,12 @@
// nanoseconds.
nsecs_t mPeriod;
+ // mPendingPeriod is the proposed period change in nanoseconds.
+ // If mPendingPeriod differs from mPeriod and is nonzero, it will
+ // be flushed to mPeriod when we detect that the hardware switched
+ // vsync frequency.
+ nsecs_t mPendingPeriod = 0;
+
// mPhase is the phase offset of the modeled vsync events. It is the
// number of nanoseconds from time 0 to the first vsync event.
nsecs_t mPhase;