SurfaceFlinger: only focused layers can use appRequestRange
When DisplayManager sets the DisplayConfigsSpecs with a policy
that the appRequestRange is broader than the primaryRange,
it means that an app can choose a refresh rate from the
appRequestRange and not from the primaryRange only if that app
explicitly specified a frame rate using setFrameRate API. However,
to avoid cases where we switch the refresh rate back and forth from
the two ranges, we are allowing only applications that their window
is focused from WindowManager's perspective to select refresh rate out
the primaryRange. This matches the behavior of an application that sets
the preferredDisplayModeId.
Bug: 144307188
Bug: 159940172
Test: adb shell /data/nativetest64/libsurfaceflinger_unittest/libsurfaceflinger_unittest
Test: YouTube in PIP mode while device is restricted by primaryRange
Change-Id: I26a9690210bb5771bd8aae2bff301031617f7c8f
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp
index 2925109..ecf2597 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.cpp
+++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp
@@ -109,6 +109,8 @@
auto layer = weakLayer.promote();
// Only use the layer if the reference still exists.
if (layer || CC_UNLIKELY(mTraceEnabled)) {
+ const auto layerFocused =
+ Layer::isLayerFocusedBasedOnPriority(layer->getFrameRateSelectionPriority());
// Check if frame rate was set on layer.
const auto frameRate = layer->getFrameRateForLayerTree();
if (frameRate.rate > 0.f) {
@@ -122,11 +124,12 @@
return LayerVoteType::NoVote;
}
}();
- summary.push_back({layer->getName(), voteType, frameRate.rate, /* weight */ 1.0f});
+ summary.push_back({layer->getName(), voteType, frameRate.rate, /* weight */ 1.0f,
+ layerFocused});
} else if (recent) {
summary.push_back({layer->getName(), LayerVoteType::Heuristic,
info->getRefreshRate(now),
- /* weight */ 1.0f});
+ /* weight */ 1.0f, layerFocused});
}
if (CC_UNLIKELY(mTraceEnabled)) {