SF: Split Scheduler initialization
Create VsyncSchedule and timers after Scheduler construction, which will
happen on boot rather than initial hotplug in the future.
Remove Scheduler from SF factory.
Bug: 185535769
Test: Boot
Change-Id: I1096987f468a43fa4b6ae39709b44425d026248c
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index eeea25d..f201996 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -117,16 +117,10 @@
}
};
-Scheduler::Scheduler(const std::shared_ptr<scheduler::RefreshRateConfigs>& configs,
- ISchedulerCallback& callback)
- : Scheduler(configs, callback,
- {.useContentDetection = sysprop::use_content_detection_for_refresh_rate(false)}) {
-}
+Scheduler::Scheduler(ISchedulerCallback& callback, Options options)
+ : mOptions(options), mSchedulerCallback(callback) {}
-Scheduler::Scheduler(const std::shared_ptr<scheduler::RefreshRateConfigs>& configs,
- ISchedulerCallback& callback, Options options)
- : Scheduler(createVsyncSchedule(configs->supportsKernelIdleTimer()), configs, callback,
- createLayerHistory(), options) {
+void Scheduler::startTimers() {
using namespace sysprop;
if (const int64_t millis = set_touch_timer_ms(0); millis > 0) {
@@ -147,22 +141,6 @@
}
}
-Scheduler::Scheduler(VsyncSchedule schedule,
- const std::shared_ptr<scheduler::RefreshRateConfigs>& configs,
- ISchedulerCallback& schedulerCallback,
- std::unique_ptr<LayerHistory> layerHistory, Options options)
- : mOptions(options),
- mVsyncSchedule(std::move(schedule)),
- mLayerHistory(std::move(layerHistory)),
- mSchedulerCallback(schedulerCallback),
- mPredictedVsyncTracer(
- base::GetBoolProperty("debug.sf.show_predicted_vsync", false)
- ? std::make_unique<PredictedVsyncTracer>(*mVsyncSchedule.dispatch)
- : nullptr) {
- setRefreshRateConfigs(configs);
- mSchedulerCallback.setVsyncEnabled(false);
-}
-
Scheduler::~Scheduler() {
// Ensure the OneShotTimer threads are joined before we start destroying state.
mDisplayPowerTimer.reset();
@@ -170,7 +148,7 @@
mRefreshRateConfigs.reset();
}
-Scheduler::VsyncSchedule Scheduler::createVsyncSchedule(bool supportKernelTimer) {
+void Scheduler::createVsyncSchedule(bool supportKernelTimer) {
auto clock = std::make_unique<scheduler::SystemClock>();
auto tracker = createVSyncTracker();
auto dispatch = createVSyncDispatch(*tracker);
@@ -180,11 +158,11 @@
auto controller =
std::make_unique<scheduler::VSyncReactor>(std::move(clock), *tracker, pendingFenceLimit,
supportKernelTimer);
- return {std::move(controller), std::move(tracker), std::move(dispatch)};
-}
+ mVsyncSchedule = {std::move(controller), std::move(tracker), std::move(dispatch)};
-std::unique_ptr<LayerHistory> Scheduler::createLayerHistory() {
- return std::make_unique<scheduler::LayerHistory>();
+ if (base::GetBoolProperty("debug.sf.show_predicted_vsync", false)) {
+ mPredictedVsyncTracer = std::make_unique<PredictedVsyncTracer>(*mVsyncSchedule.dispatch);
+ }
}
std::unique_ptr<VSyncSource> Scheduler::makePrimaryDispSyncSource(
@@ -594,11 +572,11 @@
// If the content detection feature is off, we still keep the layer history,
// since we use it for other features (like Frame Rate API), so layers
// still need to be registered.
- mLayerHistory->registerLayer(layer, voteType);
+ mLayerHistory.registerLayer(layer, voteType);
}
void Scheduler::deregisterLayer(Layer* layer) {
- mLayerHistory->deregisterLayer(layer);
+ mLayerHistory.deregisterLayer(layer);
}
void Scheduler::recordLayerHistory(Layer* layer, nsecs_t presentTime,
@@ -608,11 +586,11 @@
if (!mRefreshRateConfigs->canSwitch()) return;
}
- mLayerHistory->record(layer, presentTime, systemTime(), updateType);
+ mLayerHistory.record(layer, presentTime, systemTime(), updateType);
}
void Scheduler::setModeChangePending(bool pending) {
- mLayerHistory->setModeChangePending(pending);
+ mLayerHistory.setModeChangePending(pending);
}
void Scheduler::chooseRefreshRateForContent() {
@@ -625,7 +603,7 @@
const auto refreshRateConfigs = holdRefreshRateConfigs();
scheduler::LayerHistory::Summary summary =
- mLayerHistory->summarize(*refreshRateConfigs, systemTime());
+ mLayerHistory.summarize(*refreshRateConfigs, systemTime());
scheduler::RefreshRateConfigs::GlobalSignals consideredSignals;
DisplayModePtr newMode;
bool frameRateChanged;
@@ -686,7 +664,7 @@
// Display Power event will boost the refresh rate to performance.
// Clear Layer History to get fresh FPS detection
- mLayerHistory->clear();
+ mLayerHistory.clear();
}
void Scheduler::kernelIdleTimerCallback(TimerState state) {
@@ -730,7 +708,7 @@
// NOTE: Instead of checking all the layers, we should be checking the layer
// that is currently on top. b/142507166 will give us this capability.
if (handleTimerStateChanged(&mFeatures.touch, touch)) {
- mLayerHistory->clear();
+ mLayerHistory.clear();
}
ATRACE_INT("TouchState", static_cast<int>(touch));
}
@@ -747,7 +725,7 @@
mTouchTimer ? mTouchTimer->dump().c_str() : "off");
StringAppendF(&result, "+ Content detection: %s %s\n\n",
toContentDetectionString(mOptions.useContentDetection),
- mLayerHistory ? mLayerHistory->dump().c_str() : "(no layer history)");
+ mLayerHistory.dump().c_str());
{
std::lock_guard lock(mFrameRateOverridesLock);
@@ -911,7 +889,7 @@
}
void Scheduler::onActiveDisplayAreaChanged(uint32_t displayArea) {
- mLayerHistory->setDisplayArea(displayArea);
+ mLayerHistory.setDisplayArea(displayArea);
}
void Scheduler::setPreferredRefreshRateForUid(FrameRateOverride frameRateOverride) {
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index 8397738..8204abc 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -75,9 +75,17 @@
using RefreshRate = scheduler::RefreshRateConfigs::RefreshRate;
using ModeEvent = scheduler::RefreshRateConfigEvent;
- Scheduler(const std::shared_ptr<scheduler::RefreshRateConfigs>&, ISchedulerCallback&);
+ struct Options {
+ // Whether to use content detection at all.
+ bool useContentDetection = false;
+ };
+
+ Scheduler(ISchedulerCallback&, Options);
~Scheduler();
+ void createVsyncSchedule(bool supportKernelIdleTimer);
+ void startTimers();
+
using ConnectionHandle = scheduler::ConnectionHandle;
ConnectionHandle createConnection(const char* connectionName, frametimeline::TokenManager*,
std::chrono::nanoseconds workDuration,
@@ -213,27 +221,12 @@
enum class TimerState { Reset, Expired };
enum class TouchState { Inactive, Active };
- struct Options {
- // Whether to use content detection at all.
- bool useContentDetection;
- };
-
struct VsyncSchedule {
std::unique_ptr<scheduler::VsyncController> controller;
std::unique_ptr<scheduler::VSyncTracker> tracker;
std::unique_ptr<scheduler::VSyncDispatch> dispatch;
};
- // Unlike the testing constructor, this creates the VsyncSchedule, LayerHistory, and timers.
- Scheduler(const std::shared_ptr<scheduler::RefreshRateConfigs>&, ISchedulerCallback&, Options);
-
- // Used by tests to inject mocks.
- Scheduler(VsyncSchedule, const std::shared_ptr<scheduler::RefreshRateConfigs>&,
- ISchedulerCallback&, std::unique_ptr<LayerHistory>, Options);
-
- static VsyncSchedule createVsyncSchedule(bool supportKernelIdleTimer);
- static std::unique_ptr<LayerHistory> createLayerHistory();
-
// Create a connection on the given EventThread.
ConnectionHandle createConnection(std::unique_ptr<EventThread>);
sp<EventThreadConnection> createConnectionInternal(
@@ -297,7 +290,7 @@
VsyncSchedule mVsyncSchedule;
// Used to choose refresh rate if content detection is enabled.
- std::unique_ptr<LayerHistory> mLayerHistory;
+ LayerHistory mLayerHistory;
// Timer used to monitor touch events.
std::optional<scheduler::OneShotTimer> mTouchTimer;
@@ -338,7 +331,7 @@
GUARDED_BY(mVsyncTimelineLock);
static constexpr std::chrono::nanoseconds MAX_VSYNC_APPLIED_TIME = 200ms;
- const std::unique_ptr<PredictedVsyncTracer> mPredictedVsyncTracer;
+ std::unique_ptr<PredictedVsyncTracer> mPredictedVsyncTracer;
// The frame rate override lists need their own mutex as they are being read
// by SurfaceFlinger, Scheduler and EventThread (as a callback) to prevent deadlocks