Reland "Create a VsyncSchedule per display"
In order to determine the vsync offsets between displays, keep track of
a VsyncSchedule for each display.
Store the VsyncSchedules in a SmallMap. Update getVsyncSchedule with a
parameter to choose the display. The default parameter uses the leader's
display, which is what many current callers want.
Update VsyncDispatches when the leader changes, so that they are always
listening to the leader.
Enable and disable vsync callbacks per display. Earlier attempts to turn
them on and off together could leave a secondary display on a bad
schedule. Add a method for resyncing all displays at once.
Use std::shared_ptrs for VsyncDispatches. This prevents lifetime issues
if a VsyncSchedule gets removed while its VsyncDispatch is still in use.
Same for VsyncTracker, which is referenced by VsyncDispatch.
When the leader VsyncSchedule changes, call cancel on
VsyncCallbackRegistrations and replace them with new ones using the new
VsyncDispatches. If a callback was scheduled, schedule a new one.
Update VsyncSchedule's members' traces so that there is a separate track
for each display.
For refresh rate changes, modulate vsync config based on the leader
display. When switching leaders, force a period transition to ensure
that a potential refresh rate change is completed.
This reverts commit db16a2be4054d0dd7d940f4fa0a2ced0575fd2e7 aka
I0757a7df540fad316b2db42e4c77f1c73bc49420, which reverted the original
CL, If60218e85292c786b9fa70ecb33ee374d3a385e0. Notable differences from
the original CL:
- Logical pieces have been separated and landed in the following CLs:
- I21be76e20776d8a3f49e5bd295a0042de9e2dde9
- I062002245db8fd817e145a3aaf197bb874b00636
- I54a1304a3428968134cc707b24d5b325927c31df
- Remove IEventThreadCallback changes. These are ultimately orthogonal
to the motivation of this CL.
- Store the ID instead of the name and use ftl::Concat, as tracked in
b/266817103.
- Rename MessageQueue::updateVsyncRegistration to onNewVsyncSchedule, to
match the name in EventThread. These methods do essentially the same
thing, so use the same name.
- Crucially, I54a1304a3428968134cc707b24d5b325927c31df restores the
pending HWC Vsync state, which was originally removed in
If60218e85292c786b9fa70ecb33ee374d3a385e0. The removal seems to have
been responsible for b/267562341.
Bug: 255601557
Bug: 256196556
Bug: 241285473
Bug: 241286146
Bug: 268366385
Fixes: 266817103
Test: libsurfaceflinger_unittest
Test: manual (look at perfetto traces)
Change-Id: Icdb80253436b4d0034fc20fcae8583efb7c30292
diff --git a/services/surfaceflinger/Scheduler/VsyncSchedule.h b/services/surfaceflinger/Scheduler/VsyncSchedule.h
index a32acc7..763d058 100644
--- a/services/surfaceflinger/Scheduler/VsyncSchedule.h
+++ b/services/surfaceflinger/Scheduler/VsyncSchedule.h
@@ -25,6 +25,7 @@
#include <ftl/optional.h>
#include <scheduler/Features.h>
#include <scheduler/Time.h>
+#include <ui/DisplayId.h>
namespace android {
class EventThreadTest;
@@ -50,7 +51,7 @@
// Schedule that synchronizes to hardware VSYNC of a physical display.
class VsyncSchedule {
public:
- explicit VsyncSchedule(FeatureFlags);
+ VsyncSchedule(PhysicalDisplayId, FeatureFlags);
~VsyncSchedule();
Period period() const;
@@ -61,7 +62,9 @@
// enable hardware VSYNCs in order to calibrate.
//
// \param [in] period The period that the system is changing into.
- void startPeriodTransition(ISchedulerCallback&, Period period);
+ // \param [in] force True to force a transition even if it is not a
+ // change.
+ void startPeriodTransition(ISchedulerCallback&, Period period, bool force);
// Pass a VSYNC sample to VsyncController. Return true if
// VsyncController detected that the VSYNC period changed. Enable or disable
@@ -74,8 +77,13 @@
VsyncTracker& getTracker() { return *mTracker; }
VsyncController& getController() { return *mController; }
+ // TODO(b/185535769): Once these are hidden behind the API, they may no
+ // longer need to be shared_ptrs.
+ using DispatchPtr = std::shared_ptr<VsyncDispatch>;
+ using TrackerPtr = std::shared_ptr<VsyncTracker>;
+
// TODO(b/185535769): Remove once VsyncSchedule owns all registrations.
- VsyncDispatch& getDispatch() { return *mDispatch; }
+ DispatchPtr getDispatch() { return mDispatch; }
void dump(std::string&) const;
@@ -84,7 +92,8 @@
void enableHardwareVsync(ISchedulerCallback&) EXCLUDES(mHwVsyncLock);
// Disable hardware VSYNCs. If `disallow` is true, future calls to
- // enableHardwareVsync are ineffective until allowHardwareVsync is called.
+ // enableHardwareVsync are ineffective until isHardwareVsyncAllowed is
+ // called with `makeAllowed` set to true.
void disableHardwareVsync(ISchedulerCallback&, bool disallow) EXCLUDES(mHwVsyncLock);
// If true, enableHardwareVsync can enable hardware VSYNC (if not already
@@ -95,22 +104,21 @@
bool getPendingHardwareVsyncState() const REQUIRES(kMainThreadContext);
+protected:
+ using ControllerPtr = std::unique_ptr<VsyncController>;
+
+ // For tests.
+ VsyncSchedule(PhysicalDisplayId, TrackerPtr, DispatchPtr, ControllerPtr);
+
private:
friend class TestableScheduler;
friend class android::EventThreadTest;
friend class android::VsyncScheduleTest;
friend class android::fuzz::SchedulerFuzzer;
- using TrackerPtr = std::unique_ptr<VsyncTracker>;
- using DispatchPtr = std::unique_ptr<VsyncDispatch>;
- using ControllerPtr = std::unique_ptr<VsyncController>;
-
- // For tests.
- VsyncSchedule(TrackerPtr, DispatchPtr, ControllerPtr);
-
- static TrackerPtr createTracker();
- static DispatchPtr createDispatch(VsyncTracker&);
- static ControllerPtr createController(VsyncTracker&, FeatureFlags);
+ static TrackerPtr createTracker(PhysicalDisplayId);
+ static DispatchPtr createDispatch(TrackerPtr);
+ static ControllerPtr createController(PhysicalDisplayId, VsyncTracker&, FeatureFlags);
void enableHardwareVsyncLocked(ISchedulerCallback&) REQUIRES(mHwVsyncLock);
@@ -138,6 +146,7 @@
class PredictedVsyncTracer;
using TracerPtr = std::unique_ptr<PredictedVsyncTracer>;
+ const PhysicalDisplayId mId;
const TrackerPtr mTracker;
const DispatchPtr mDispatch;
const ControllerPtr mController;