SF: Always create LayerHistory in Scheduler
Currently if Scheduler is created when there is
only one supported display mode, LayerHistory is
not created. This optimization assumes that the
list of supported modes is never going to change
but this is not the case for TV devices.
The typical use case is when a TV dongle or
set-top box is first connected to a display
after it boots. In this cas some devices will
first report only one display mode and later
update to the full list of supported modes.
This CL changes the behaviour to always have an instance
of LayerHistory. If there's only one display mode
recordLayerHistory() and chooseRefreshRateForContent()
are noops.
The alternative to create LayerHistory on demand is
more cumbersome because we also would need to register
all already created layers.
Bug: 188872896
Test: presubmit
Change-Id: Ia236fd4a81cc736c172220ff60762ddbc3cbb83a
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index fac2c65..857071c 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -194,8 +194,6 @@
std::unique_ptr<LayerHistory> Scheduler::createLayerHistory(
const scheduler::RefreshRateConfigs& configs) {
- if (!configs.canSwitch()) return nullptr;
-
return std::make_unique<scheduler::LayerHistory>(configs);
}
@@ -579,8 +577,6 @@
}
void Scheduler::registerLayer(Layer* layer) {
- if (!mLayerHistory) return;
-
scheduler::LayerHistory::LayerVoteType voteType;
if (!mOptions.useContentDetection ||
@@ -600,26 +596,22 @@
}
void Scheduler::deregisterLayer(Layer* layer) {
- if (mLayerHistory) {
- mLayerHistory->deregisterLayer(layer);
- }
+ mLayerHistory->deregisterLayer(layer);
}
void Scheduler::recordLayerHistory(Layer* layer, nsecs_t presentTime,
LayerHistory::LayerUpdateType updateType) {
- if (mLayerHistory) {
+ if (mRefreshRateConfigs.canSwitch()) {
mLayerHistory->record(layer, presentTime, systemTime(), updateType);
}
}
void Scheduler::setModeChangePending(bool pending) {
- if (mLayerHistory) {
- mLayerHistory->setModeChangePending(pending);
- }
+ mLayerHistory->setModeChangePending(pending);
}
void Scheduler::chooseRefreshRateForContent() {
- if (!mLayerHistory) return;
+ if (!mRefreshRateConfigs.canSwitch()) return;
ATRACE_CALL();
@@ -691,9 +683,7 @@
// Display Power event will boost the refresh rate to performance.
// Clear Layer History to get fresh FPS detection
- if (mLayerHistory) {
- mLayerHistory->clear();
- }
+ mLayerHistory->clear();
}
void Scheduler::kernelIdleTimerCallback(TimerState state) {
@@ -732,9 +722,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)) {
- if (mLayerHistory) {
- mLayerHistory->clear();
- }
+ mLayerHistory->clear();
}
ATRACE_INT("TouchState", static_cast<int>(touch));
}
@@ -908,9 +896,7 @@
}
void Scheduler::onPrimaryDisplayAreaChanged(uint32_t displayArea) {
- if (mLayerHistory) {
- mLayerHistory->setDisplayArea(displayArea);
- }
+ mLayerHistory->setDisplayArea(displayArea);
}
void Scheduler::setPreferredRefreshRateForUid(FrameRateOverride frameRateOverride) {