SF: Dedupe functions to apply Scheduler::Policy
The only functional difference is the early out when there is no change
in timer state, which now applies to LayerRequirement state as well.
Bug: 185535769
Test: libsurfaceflinger_unittest
Change-Id: Ia7234847e4f44d78dbf3920d77f38f3bfa40e5a2
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index 468c4cc..9c32b1f 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -263,14 +263,17 @@
void touchTimerCallback(TimerState);
void displayPowerTimerCallback(TimerState);
- // handles various timer features to change the refresh rate.
- template <class T>
- bool handleTimerStateChanged(T* currentState, T newState);
-
void setVsyncPeriod(nsecs_t period);
using GlobalSignals = RefreshRateConfigs::GlobalSignals;
+ struct Policy;
+
+ // Sets the S state of the policy to the T value under mPolicyLock, and chooses a display mode
+ // that fulfills the new policy if the state changed. Returns the signals that were considered.
+ template <typename S, typename T>
+ GlobalSignals applyPolicy(S Policy::*, T&&) EXCLUDES(mPolicyLock);
+
// Returns the display mode that fulfills the policy, and the signals that were considered.
std::pair<DisplayModePtr, GlobalSignals> chooseDisplayMode() REQUIRES(mPolicyLock);
@@ -323,7 +326,7 @@
mutable std::mutex mPolicyLock;
- struct {
+ struct Policy {
// Policy for choosing the display mode.
LayerHistory::Summary contentRequirements;
TimerState idleTimer = TimerState::Reset;