Make shouldBeSeamless an enum
We change theboolean shouldBeSemaless to an enum with
three values. This introduces a third value "Default" which
indicates that the layer doesn't have a preference for
seamlessness. This is the default value for Surfaces which
haven't called setFrameRate, or have called setFrameRate(0).
Bug: 161776961
Test: presubmit
Change-Id: I157e332e82e95badc928d6a8135e657cd6984db4
diff --git a/services/surfaceflinger/tests/unittests/LayerHistoryTestV2.cpp b/services/surfaceflinger/tests/unittests/LayerHistoryTestV2.cpp
index 3b50321..7bfec9a 100644
--- a/services/surfaceflinger/tests/unittests/LayerHistoryTestV2.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerHistoryTestV2.cpp
@@ -73,12 +73,11 @@
[now](const auto& pair) { return pair.second->isAnimating(now); });
}
- void setLayerInfoVote(Layer* layer,
- LayerHistory::LayerVoteType vote) NO_THREAD_SAFETY_ANALYSIS {
+ void setDefaultLayerVote(Layer* layer,
+ LayerHistory::LayerVoteType vote) NO_THREAD_SAFETY_ANALYSIS {
for (auto& [weak, info] : history().mLayerInfos) {
if (auto strong = weak.promote(); strong && strong.get() == layer) {
info->setDefaultLayerVote(vote);
- info->setLayerVote({vote, 0, false});
return;
}
}
@@ -209,7 +208,7 @@
EXPECT_CALL(*layer, isVisible()).WillRepeatedly(Return(true));
EXPECT_CALL(*layer, getFrameRateForLayerTree()).WillRepeatedly(Return(Layer::FrameRate()));
- setLayerInfoVote(layer.get(), LayerHistory::LayerVoteType::NoVote);
+ setDefaultLayerVote(layer.get(), LayerHistory::LayerVoteType::NoVote);
EXPECT_EQ(1, layerCount());
EXPECT_EQ(0, activeLayerCount());
@@ -236,7 +235,7 @@
EXPECT_CALL(*layer, isVisible()).WillRepeatedly(Return(true));
EXPECT_CALL(*layer, getFrameRateForLayerTree()).WillRepeatedly(Return(Layer::FrameRate()));
- setLayerInfoVote(layer.get(), LayerHistory::LayerVoteType::Min);
+ setDefaultLayerVote(layer.get(), LayerHistory::LayerVoteType::Min);
EXPECT_EQ(1, layerCount());
EXPECT_EQ(0, activeLayerCount());
@@ -264,7 +263,7 @@
EXPECT_CALL(*layer, isVisible()).WillRepeatedly(Return(true));
EXPECT_CALL(*layer, getFrameRateForLayerTree()).WillRepeatedly(Return(Layer::FrameRate()));
- setLayerInfoVote(layer.get(), LayerHistory::LayerVoteType::Max);
+ setDefaultLayerVote(layer.get(), LayerHistory::LayerVoteType::Max);
EXPECT_EQ(1, layerCount());
EXPECT_EQ(0, activeLayerCount());
@@ -310,7 +309,7 @@
EXPECT_EQ(1, frequentLayerCount(time));
// layer became inactive, but the vote stays
- setLayerInfoVote(layer.get(), LayerHistory::LayerVoteType::Heuristic);
+ setDefaultLayerVote(layer.get(), LayerHistory::LayerVoteType::Heuristic);
time += MAX_ACTIVE_LAYER_PERIOD_NS.count();
ASSERT_EQ(1, history().summarize(time).size());
EXPECT_EQ(LayerHistory::LayerVoteType::ExplicitDefault, history().summarize(time)[0].vote);
@@ -343,7 +342,7 @@
EXPECT_EQ(1, frequentLayerCount(time));
// layer became inactive, but the vote stays
- setLayerInfoVote(layer.get(), LayerHistory::LayerVoteType::Heuristic);
+ setDefaultLayerVote(layer.get(), LayerHistory::LayerVoteType::Heuristic);
time += MAX_ACTIVE_LAYER_PERIOD_NS.count();
ASSERT_EQ(1, history().summarize(time).size());
EXPECT_EQ(LayerHistory::LayerVoteType::ExplicitExactOrMultiple,
diff --git a/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp
index df76110..5a92d0a 100644
--- a/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp
+++ b/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp
@@ -310,7 +310,7 @@
/*currentConfigId=*/HWC_CONFIG_ID_60);
const auto makeLayerRequirements = [](float refreshRate) -> std::vector<LayerRequirement> {
- return {{"testLayer", LayerVoteType::Heuristic, refreshRate, /*shouldBeSeamless*/ true,
+ return {{"testLayer", LayerVoteType::Heuristic, refreshRate, Seamlessness::OnlySeamless,
/*weight*/ 1.0f, /*focused*/ false}};
};
@@ -1263,7 +1263,7 @@
auto& layer = layers[0];
layer.vote = LayerVoteType::ExplicitDefault;
layer.desiredRefreshRate = 90.0f;
- layer.shouldBeSeamless = false;
+ layer.seamlessness = Seamlessness::SeamedAndSeamless;
layer.name = "90Hz ExplicitDefault";
layer.focused = true;
@@ -1280,32 +1280,49 @@
.getConfigId());
// Verify that we won't change the group if seamless switch is required.
- layer.shouldBeSeamless = true;
+ layer.seamlessness = Seamlessness::OnlySeamless;
ASSERT_EQ(HWC_CONFIG_ID_60,
refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
.getConfigId());
- // At this point the default config in the DisplayManager policy with be 60Hz.
- // Verify that if the current config is in another group and there are no layers with
- // shouldBeSeamless=false we'll go back to the default group.
+ // Verify that we won't do a seamless switch if we request the same mode as the default
refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
layer.desiredRefreshRate = 60.0f;
layer.name = "60Hz ExplicitDefault";
- layer.shouldBeSeamless = true;
+ layer.seamlessness = Seamlessness::OnlySeamless;
+ ASSERT_EQ(HWC_CONFIG_ID_90,
+ refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
+ .getConfigId());
+
+ // Verify that if the current config is in another group and there are no layers with
+ // seamlessness=SeamedAndSeamless we'll go back to the default group.
+ layer.desiredRefreshRate = 60.0f;
+ layer.name = "60Hz ExplicitDefault";
+ layer.seamlessness = Seamlessness::Default;
ASSERT_EQ(HWC_CONFIG_ID_60,
refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
.getConfigId());
- // If there's a layer with shouldBeSeamless=false, another layer with shouldBeSeamless=true
- // can't change the config group.
+ // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
+ // seamlessness=OnlySeamless can't change the config group.
refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
- auto layer2 = LayerRequirement{.weight = 0.5f};
+ layer.seamlessness = Seamlessness::OnlySeamless;
+
+ layers.push_back(LayerRequirement{.weight = 0.5f});
+ auto& layer2 = layers[layers.size() - 1];
layer2.vote = LayerVoteType::ExplicitDefault;
layer2.desiredRefreshRate = 90.0f;
layer2.name = "90Hz ExplicitDefault";
- layer2.shouldBeSeamless = false;
+ layer2.seamlessness = Seamlessness::SeamedAndSeamless;
layer2.focused = false;
- layers.push_back(layer2);
+
+ ASSERT_EQ(HWC_CONFIG_ID_90,
+ refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
+ .getConfigId());
+
+ // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
+ // seamlessness=Default can't change the config group.
+ layers[0].seamlessness = Seamlessness::Default;
ASSERT_EQ(HWC_CONFIG_ID_90,
refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
.getConfigId());
@@ -1326,7 +1343,7 @@
auto& layer = layers[0];
layer.vote = LayerVoteType::ExplicitExactOrMultiple;
layer.desiredRefreshRate = 60.0f;
- layer.shouldBeSeamless = false;
+ layer.seamlessness = Seamlessness::SeamedAndSeamless;
layer.name = "60Hz ExplicitExactOrMultiple";
layer.focused = true;
@@ -1355,13 +1372,13 @@
LayerRequirement>{LayerRequirement{.name = "60Hz ExplicitDefault",
.vote = LayerVoteType::ExplicitDefault,
.desiredRefreshRate = 60.0f,
- .shouldBeSeamless = false,
+ .seamlessness = Seamlessness::SeamedAndSeamless,
.weight = 0.5f,
.focused = false},
LayerRequirement{.name = "25Hz ExplicitExactOrMultiple",
.vote = LayerVoteType::ExplicitExactOrMultiple,
.desiredRefreshRate = 25.0f,
- .shouldBeSeamless = true,
+ .seamlessness = Seamlessness::OnlySeamless,
.weight = 1.0f,
.focused = true}};
auto& seamedLayer = layers[0];