Move HwVsyncState into VsyncSchedule
In preparation for having a separate schedule per display, pull state
which is logically for a single display into VsyncSchedule. This should
be a pure refactor.
Consolidate mPrimaryHWVsyncEnabled and mHWVsyncAvailable (now in
VsyncSchedule) into a single enum which better captures the possible
states. Move SF's record of the pending HWC VSYNC state into the same
place, so it sits with other related logic. Remove the last HWC
VSYNC state, which did not affect behavior.
Move ISchedulerCallback into its own file, so that VsyncSchedule.cpp
doesn't need to depend on Scheduler.h.
Rename variables `makeUnavailable` and `makeAvailable` for clarity.
Make addResyncSample return a boolean, instead of void with an out
parameter.
Remove VsyncSchedule's move constructor. Now that it has a mutex, it is
no longer thread-safe. We don't actually need to move it anyway. Replace
std::optional with std::unique_ptr for owning a VsyncSchedule.
Factored out of If60218e85292c786b9fa70ecb33ee374d3a385e0. Relevant
differences from that patch:
- There is still only one VsyncSchedule.
- When SF turns off a display, we still disable vsync on that display.
In If60218e85292c786b9fa70ecb33ee374d3a385e0, this was redundant with
the call to disableHardwareVsync shortly before it, but right now we
only call disableHardwareVsync for the active display.
- Hold the VSYNC lock for more time in resyncToHaredwareVsync. This
better matches the original behavior.
- Remove mLastHwVsyncState.
- Recreate the code for storing and setting the pending VSYNC state.
- Inline setVsyncPeriod at its only call-site.
Bug: 255601557
Bug: 256196556
Bug: 241286146
Fixes: 266712910
Test: libsurfaceflinger_unittest
Change-Id: I54a1304a3428968134cc707b24d5b325927c31df
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index dae9546..a340919 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -43,6 +43,7 @@
#include "Display/DisplayModeRequest.h"
#include "EventThread.h"
#include "FrameRateOverrideMappings.h"
+#include "ISchedulerCallback.h"
#include "LayerHistory.h"
#include "MessageQueue.h"
#include "OneShotTimer.h"
@@ -92,16 +93,6 @@
using GlobalSignals = RefreshRateSelector::GlobalSignals;
-struct ISchedulerCallback {
- virtual void setVsyncEnabled(bool) = 0;
- virtual void requestDisplayModes(std::vector<display::DisplayModeRequest>) = 0;
- virtual void kernelTimerChanged(bool expired) = 0;
- virtual void triggerOnFrameRateOverridesChanged() = 0;
-
-protected:
- ~ISchedulerCallback() = default;
-};
-
class Scheduler : android::impl::MessageQueue {
using Impl = android::impl::MessageQueue;
@@ -192,20 +183,20 @@
void setRenderRate(Fps);
void enableHardwareVsync();
- void disableHardwareVsync(bool makeUnavailable);
+ void disableHardwareVsync(bool disallow);
// Resyncs the scheduler to hardware vsync.
- // If makeAvailable is true, then hardware vsync will be turned on.
+ // If allowToEnable is true, then hardware vsync will be turned on.
// Otherwise, if hardware vsync is not already enabled then this method will
// no-op.
- void resyncToHardwareVsync(bool makeAvailable, Fps refreshRate);
+ void resyncToHardwareVsync(bool allowToEnable, Fps refreshRate);
void resync() EXCLUDES(mDisplayLock);
void forceNextResync() { mLastResyncTime = 0; }
- // Passes a vsync sample to VsyncController. periodFlushed will be true if
- // VsyncController detected that the vsync period changed, and false otherwise.
- void addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod,
- bool* periodFlushed);
+ // Passes a vsync sample to VsyncController. Returns true if
+ // VsyncController detected that the vsync period changed and false
+ // otherwise.
+ bool addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod);
void addPresentFence(std::shared_ptr<FenceTime>);
// Layers are registered on creation, and unregistered when the weak reference expires.
@@ -297,7 +288,6 @@
void touchTimerCallback(TimerState);
void displayPowerTimerCallback(TimerState);
- void setVsyncPeriod(nsecs_t period);
void setVsyncConfig(const VsyncConfig&, Period vsyncPeriod);
// Chooses a leader among the registered displays, unless `leaderIdOpt` is specified. The new
@@ -362,14 +352,10 @@
ConnectionHandle mAppConnectionHandle;
ConnectionHandle mSfConnectionHandle;
- mutable std::mutex mHWVsyncLock;
- bool mPrimaryHWVsyncEnabled GUARDED_BY(mHWVsyncLock) = false;
- bool mHWVsyncAvailable GUARDED_BY(mHWVsyncLock) = false;
-
std::atomic<nsecs_t> mLastResyncTime = 0;
const FeatureFlags mFeatures;
- std::optional<VsyncSchedule> mVsyncSchedule;
+ std::unique_ptr<VsyncSchedule> mVsyncSchedule;
// Shifts the VSYNC phase during certain transactions and refresh rate changes.
const sp<VsyncModulator> mVsyncModulator;