blob: 9d323962b984e7a6369873732608ef810e1a2e22 [file] [log] [blame]
Alec Mouri0a1cc962019-03-14 12:33:02 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#undef LOG_TAG
18#define LOG_TAG "SchedulerUnittests"
19
20#include <gmock/gmock.h>
21#include <log/log.h>
22#include <thread>
23
Ady Abraham6fb599b2020-03-05 13:48:22 -080024#include "../../Scheduler/RefreshRateConfigs.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070025#include "DisplayHardware/HWC2.h"
26#include "Scheduler/RefreshRateConfigs.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070027
28using namespace std::chrono_literals;
29using testing::_;
30
31namespace android {
32namespace scheduler {
33
Alec Mouri0a1cc962019-03-14 12:33:02 -070034using RefreshRate = RefreshRateConfigs::RefreshRate;
Ady Abraham8a82ba62020-01-17 12:43:17 -080035using LayerVoteType = RefreshRateConfigs::LayerVoteType;
36using LayerRequirement = RefreshRateConfigs::LayerRequirement;
Alec Mouri0a1cc962019-03-14 12:33:02 -070037
38class RefreshRateConfigsTest : public testing::Test {
39protected:
Ady Abraham2139f732019-11-13 18:56:40 -080040 static inline const HwcConfigIndexType HWC_CONFIG_ID_60 = HwcConfigIndexType(0);
Ady Abraham8a82ba62020-01-17 12:43:17 -080041 static inline const HwcConfigIndexType HWC_CONFIG_ID_72 = HwcConfigIndexType(1);
42 static inline const HwcConfigIndexType HWC_CONFIG_ID_90 = HwcConfigIndexType(2);
43 static inline const HwcConfigIndexType HWC_CONFIG_ID_120 = HwcConfigIndexType(3);
44 static inline const HwcConfigIndexType HWC_CONFIG_ID_30 = HwcConfigIndexType(4);
Ady Abraham2139f732019-11-13 18:56:40 -080045 static inline const HwcConfigGroupType HWC_GROUP_ID_0 = HwcConfigGroupType(0);
46 static inline const HwcConfigGroupType HWC_GROUP_ID_1 = HwcConfigGroupType(1);
Ady Abraham8a82ba62020-01-17 12:43:17 -080047 static constexpr auto VSYNC_30 = static_cast<int64_t>(1e9f / 30);
48 static constexpr auto VSYNC_60 = static_cast<int64_t>(1e9f / 60);
49 static constexpr auto VSYNC_72 = static_cast<int64_t>(1e9f / 72);
50 static constexpr auto VSYNC_90 = static_cast<int64_t>(1e9f / 90);
51 static constexpr auto VSYNC_120 = static_cast<int64_t>(1e9f / 120);
Ana Krulec72f0d6e2020-01-06 15:24:47 -080052 static constexpr int64_t VSYNC_60_POINT_4 = 16666665;
Alec Mouri0a1cc962019-03-14 12:33:02 -070053
54 RefreshRateConfigsTest();
55 ~RefreshRateConfigsTest();
Alec Mouri0a1cc962019-03-14 12:33:02 -070056};
57
58RefreshRateConfigsTest::RefreshRateConfigsTest() {
59 const ::testing::TestInfo* const test_info =
60 ::testing::UnitTest::GetInstance()->current_test_info();
61 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
62}
63
64RefreshRateConfigsTest::~RefreshRateConfigsTest() {
65 const ::testing::TestInfo* const test_info =
66 ::testing::UnitTest::GetInstance()->current_test_info();
67 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
68}
69
70namespace {
71/* ------------------------------------------------------------------------
72 * Test cases
73 */
Ady Abraham2139f732019-11-13 18:56:40 -080074TEST_F(RefreshRateConfigsTest, oneDeviceConfig_SwitchingSupported) {
75 std::vector<RefreshRateConfigs::InputConfig> configs{
76 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}}};
Steven Thomas2bbaabe2019-08-28 16:08:35 -070077 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -080078 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -070079}
80
Ana Kruleced3a8cc2019-11-14 00:55:07 +010081TEST_F(RefreshRateConfigsTest, invalidPolicy) {
82 std::vector<RefreshRateConfigs::InputConfig> configs{
83 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}}};
84 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -080085 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ana Kruleced3a8cc2019-11-14 00:55:07 +010086 ASSERT_LT(refreshRateConfigs->setPolicy(HwcConfigIndexType(10), 60, 60, nullptr), 0);
87 ASSERT_LT(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 20, 40, nullptr), 0);
88}
89
Steven Thomas2bbaabe2019-08-28 16:08:35 -070090TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap) {
Ady Abraham2139f732019-11-13 18:56:40 -080091 std::vector<RefreshRateConfigs::InputConfig> configs{
92 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
93 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
Steven Thomas2bbaabe2019-08-28 16:08:35 -070094 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -080095 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -070096
Ady Abraham2139f732019-11-13 18:56:40 -080097 const auto minRate = refreshRateConfigs->getMinRefreshRate();
98 const auto performanceRate = refreshRateConfigs->getMaxRefreshRate();
Alec Mouri0a1cc962019-03-14 12:33:02 -070099
Ady Abraham2139f732019-11-13 18:56:40 -0800100 RefreshRate expectedDefaultConfig = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
101 ASSERT_EQ(expectedDefaultConfig, minRate);
102 RefreshRate expectedPerformanceConfig = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps",
103 90};
104 ASSERT_EQ(expectedPerformanceConfig, performanceRate);
105
106 const auto minRateByPolicy = refreshRateConfigs->getMinRefreshRateByPolicy();
107 const auto performanceRateByPolicy = refreshRateConfigs->getMaxRefreshRateByPolicy();
108 ASSERT_EQ(minRateByPolicy, minRate);
109 ASSERT_EQ(performanceRateByPolicy, performanceRate);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700110}
Ady Abraham2139f732019-11-13 18:56:40 -0800111
112TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentGroups) {
113 std::vector<RefreshRateConfigs::InputConfig> configs{
114 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
115 {HWC_CONFIG_ID_90, HWC_GROUP_ID_1, VSYNC_90}}};
116 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800117 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800118
Ady Abraham2139f732019-11-13 18:56:40 -0800119 const auto minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
120 const auto performanceRate = refreshRateConfigs->getMaxRefreshRate();
121 const auto minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
122 const auto performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
123
124 RefreshRate expectedDefaultConfig = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
125 ASSERT_EQ(expectedDefaultConfig, minRate);
126 ASSERT_EQ(expectedDefaultConfig, minRate60);
127 ASSERT_EQ(expectedDefaultConfig, performanceRate60);
128
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100129 ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_90, 60, 90, nullptr), 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800130 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
131
Ady Abraham2139f732019-11-13 18:56:40 -0800132 const auto minRate90 = refreshRateConfigs->getMinRefreshRateByPolicy();
133 const auto performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
134
135 RefreshRate expectedPerformanceConfig = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_1, "90fps",
136 90};
137 ASSERT_EQ(expectedPerformanceConfig, performanceRate);
138 ASSERT_EQ(expectedPerformanceConfig, minRate90);
139 ASSERT_EQ(expectedPerformanceConfig, performanceRate90);
140}
141
142TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_policyChange) {
143 std::vector<RefreshRateConfigs::InputConfig> configs{
144 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
145 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
146 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800147 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
148
Ady Abraham2139f732019-11-13 18:56:40 -0800149 auto minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
150 auto performanceRate = refreshRateConfigs->getMaxRefreshRateByPolicy();
151
152 RefreshRate expectedDefaultConfig = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
153 ASSERT_EQ(expectedDefaultConfig, minRate);
154 RefreshRate expectedPerformanceConfig = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps",
155 90};
156 ASSERT_EQ(expectedPerformanceConfig, performanceRate);
157
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100158 ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 60, 60, nullptr), 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800159
160 auto minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
161 auto performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
162 ASSERT_EQ(expectedDefaultConfig, minRate60);
163 ASSERT_EQ(expectedDefaultConfig, performanceRate60);
164}
165
166TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getCurrentRefreshRate) {
167 std::vector<RefreshRateConfigs::InputConfig> configs{
168 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
169 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
170 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800171 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800172 {
173 auto current = refreshRateConfigs->getCurrentRefreshRate();
174 EXPECT_EQ(current.configId, HWC_CONFIG_ID_60);
175 }
176
177 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
178 {
179 auto current = refreshRateConfigs->getCurrentRefreshRate();
180 EXPECT_EQ(current.configId, HWC_CONFIG_ID_90);
181 }
182
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100183 ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_90, 90, 90, nullptr), 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800184 {
185 auto current = refreshRateConfigs->getCurrentRefreshRate();
186 EXPECT_EQ(current.configId, HWC_CONFIG_ID_90);
187 }
188}
189
190TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getRefreshRateForContent) {
191 std::vector<RefreshRateConfigs::InputConfig> configs{
192 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
193 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
194 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800195 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800196
197 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
198 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
199
Ady Abraham8a82ba62020-01-17 12:43:17 -0800200 const auto makeLayerRequirements = [](float refreshRate) -> std::vector<LayerRequirement> {
201 return {{"testLayer", LayerVoteType::Heuristic, refreshRate, 1.0f}};
202 };
203
204 EXPECT_EQ(expected90Config,
205 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(90.0f)));
206 EXPECT_EQ(expected60Config,
207 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(60.0f)));
208 EXPECT_EQ(expected90Config,
209 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(45.0f)));
210 EXPECT_EQ(expected60Config,
211 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(30.0f)));
212 EXPECT_EQ(expected60Config,
213 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(24.0f)));
Ady Abraham2139f732019-11-13 18:56:40 -0800214
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100215 ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 60, 60, nullptr), 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800216 EXPECT_EQ(expected60Config,
217 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(90.0f)));
218 EXPECT_EQ(expected60Config,
219 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(60.0f)));
220 EXPECT_EQ(expected60Config,
221 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(45.0f)));
222 EXPECT_EQ(expected60Config,
223 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(30.0f)));
224 EXPECT_EQ(expected60Config,
225 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(24.0f)));
Ady Abraham2139f732019-11-13 18:56:40 -0800226
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100227 ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_90, 90, 90, nullptr), 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800228 EXPECT_EQ(expected90Config,
229 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(90.0f)));
230 EXPECT_EQ(expected90Config,
231 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(60.0f)));
232 EXPECT_EQ(expected90Config,
233 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(45.0f)));
234 EXPECT_EQ(expected90Config,
235 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(30.0f)));
236 EXPECT_EQ(expected90Config,
237 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(24.0f)));
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100238 ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 0, 120, nullptr), 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800239 EXPECT_EQ(expected90Config,
240 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(90.0f)));
241 EXPECT_EQ(expected60Config,
242 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(60.0f)));
243 EXPECT_EQ(expected90Config,
244 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(45.0f)));
245 EXPECT_EQ(expected60Config,
246 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(30.0f)));
247 EXPECT_EQ(expected60Config,
248 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(24.0f)));
249}
250
Ana Krulec3d367c82020-02-25 15:02:01 -0800251TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_noLayers) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800252 bool ignored;
Ana Krulec3d367c82020-02-25 15:02:01 -0800253 std::vector<RefreshRateConfigs::InputConfig> configs{
254 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
255 {HWC_CONFIG_ID_72, HWC_GROUP_ID_0, VSYNC_72},
256 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
257 auto refreshRateConfigs = std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/
258 HWC_CONFIG_ID_72);
259
260 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
261 RefreshRate expected72Config = {HWC_CONFIG_ID_72, VSYNC_72, HWC_GROUP_ID_0, "72fps", 72};
262
263 // If there are not layers, there is not content detection, so return the current
264 // refresh rate.
265 auto layers = std::vector<LayerRequirement>{};
266 EXPECT_EQ(expected72Config,
267 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/
Ady Abraham6fb599b2020-03-05 13:48:22 -0800268 false, &ignored));
Ana Krulec3d367c82020-02-25 15:02:01 -0800269
270 // Current refresh rate can always be changed.
271 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_60);
272 EXPECT_EQ(expected60Config,
273 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/
Ady Abraham6fb599b2020-03-05 13:48:22 -0800274 false, &ignored));
Ana Krulec3d367c82020-02-25 15:02:01 -0800275}
276
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800277TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_60_90) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800278 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800279 std::vector<RefreshRateConfigs::InputConfig> configs{
280 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
281 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
282 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800283 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800284
285 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
286 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
287
288 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
289 auto& lr = layers[0];
290
291 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800292 lr.name = "Min";
293 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800294 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
295 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800296
297 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800298 lr.name = "Max";
299 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800300 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
301 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800302
303 lr.desiredRefreshRate = 90.0f;
304 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800305 lr.name = "90Hz Heuristic";
306 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800307 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
308 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800309
310 lr.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800311 lr.name = "60Hz Heuristic";
312 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800313 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
314 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800315
316 lr.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800317 lr.name = "45Hz Heuristic";
318 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800319 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
320 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800321
322 lr.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800323 lr.name = "30Hz Heuristic";
324 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800325 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
326 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800327
328 lr.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800329 lr.name = "24Hz Heuristic";
330 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800331 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
332 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800333
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800334 lr.name = "";
Ady Abraham8a82ba62020-01-17 12:43:17 -0800335 ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 60, 60, nullptr), 0);
336
337 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800338 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800339 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
340 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800341
342 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800343 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800344 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
345 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800346
347 lr.desiredRefreshRate = 90.0f;
348 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800349 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800350 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
351 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800352
353 lr.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800354 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800355 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
356 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800357
358 lr.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800359 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800360 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
361 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800362
363 lr.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800364 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800365 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
366 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800367
368 lr.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800369 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800370 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
371 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800372
373 ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_90, 90, 90, nullptr), 0);
374
375 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800376 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800377 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
378 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800379
380 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800381 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800382 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
383 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800384
385 lr.desiredRefreshRate = 90.0f;
386 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800387 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800388 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
389 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800390
391 lr.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800392 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800393 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
394 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800395
396 lr.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800397 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800398 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
399 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800400
401 lr.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800402 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800403 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
404 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800405
406 lr.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800407 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800408 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
409 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800410
411 ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 0, 120, nullptr), 0);
412 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800413 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800414 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
415 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800416
417 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800418 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800419 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
420 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800421
422 lr.desiredRefreshRate = 90.0f;
423 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800424 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800425 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
426 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800427
428 lr.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800429 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800430 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
431 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800432
433 lr.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800434 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800435 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
436 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800437
438 lr.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800439 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800440 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
441 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800442
443 lr.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800444 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800445 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
446 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800447}
448
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800449TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_60_72_90) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800450 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800451 std::vector<RefreshRateConfigs::InputConfig> configs{
452 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
453 {HWC_CONFIG_ID_72, HWC_GROUP_ID_0, VSYNC_72},
454 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
455 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800456 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800457
458 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
459 RefreshRate expected72Config = {HWC_CONFIG_ID_72, VSYNC_72, HWC_GROUP_ID_0, "72fps", 70};
460 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
461
462 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
463 auto& lr = layers[0];
464
465 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800466 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800467 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
468 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800469
470 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800471 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800472 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
473 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800474
475 lr.desiredRefreshRate = 90.0f;
476 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800477 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800478 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
479 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800480
481 lr.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800482 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800483 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
484 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800485
486 lr.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800487 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800488 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
489 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800490
491 lr.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800492 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800493 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
494 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800495
496 lr.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800497 EXPECT_EQ(expected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800498 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
499 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800500}
501
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800502TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_30_60_72_90_120) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800503 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800504 std::vector<RefreshRateConfigs::InputConfig> configs{
505 {{HWC_CONFIG_ID_30, HWC_GROUP_ID_0, VSYNC_30},
506 {HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
507 {HWC_CONFIG_ID_72, HWC_GROUP_ID_0, VSYNC_72},
508 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90},
509 {HWC_CONFIG_ID_120, HWC_GROUP_ID_0, VSYNC_120}}};
510 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800511 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800512
513 RefreshRate expected30Config = {HWC_CONFIG_ID_30, VSYNC_30, HWC_GROUP_ID_0, "30fps", 30};
514 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
515 RefreshRate expected72Config = {HWC_CONFIG_ID_72, VSYNC_72, HWC_GROUP_ID_0, "72fps", 70};
516 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
517 RefreshRate expected120Config = {HWC_CONFIG_ID_120, VSYNC_120, HWC_GROUP_ID_0, "120fps", 120};
518
519 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
520 LayerRequirement{.weight = 1.0f}};
521 auto& lr1 = layers[0];
522 auto& lr2 = layers[1];
523
524 lr1.desiredRefreshRate = 24.0f;
525 lr1.vote = LayerVoteType::Heuristic;
526 lr2.desiredRefreshRate = 60.0f;
527 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800528 EXPECT_EQ(expected120Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800529 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
530 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800531
532 lr1.desiredRefreshRate = 24.0f;
533 lr1.vote = LayerVoteType::Heuristic;
534 lr2.desiredRefreshRate = 48.0f;
535 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800536 EXPECT_EQ(expected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800537 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
538 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800539
540 lr1.desiredRefreshRate = 24.0f;
541 lr1.vote = LayerVoteType::Heuristic;
542 lr2.desiredRefreshRate = 48.0f;
543 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800544 EXPECT_EQ(expected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800545 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
546 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800547}
548
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800549TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_30_60_90_120_DifferentTypes) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800550 bool ignored;
Ady Abraham71c437d2020-01-31 15:56:57 -0800551 std::vector<RefreshRateConfigs::InputConfig> configs{
552 {{HWC_CONFIG_ID_30, HWC_GROUP_ID_0, VSYNC_30},
553 {HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
554 {HWC_CONFIG_ID_72, HWC_GROUP_ID_0, VSYNC_72},
555 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90},
556 {HWC_CONFIG_ID_120, HWC_GROUP_ID_0, VSYNC_120}}};
557 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800558 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham71c437d2020-01-31 15:56:57 -0800559
560 RefreshRate expected30Config = {HWC_CONFIG_ID_30, VSYNC_30, HWC_GROUP_ID_0, "30fps", 30};
561 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
562 RefreshRate expected72Config = {HWC_CONFIG_ID_72, VSYNC_72, HWC_GROUP_ID_0, "72fps", 72};
563 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
564 RefreshRate expected120Config = {HWC_CONFIG_ID_120, VSYNC_120, HWC_GROUP_ID_0, "120fps", 120};
565
566 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
567 LayerRequirement{.weight = 1.0f}};
568 auto& lr1 = layers[0];
569 auto& lr2 = layers[1];
570
571 lr1.desiredRefreshRate = 24.0f;
572 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800573 lr1.name = "24Hz ExplicitDefault";
Ady Abraham71c437d2020-01-31 15:56:57 -0800574 lr2.desiredRefreshRate = 60.0f;
575 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800576 lr2.name = "60Hz Heuristic";
577 EXPECT_EQ(expected120Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800578 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
579 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800580
581 lr1.desiredRefreshRate = 24.0f;
582 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800583 lr1.name = "24Hz ExplicitExactOrMultiple";
Ady Abraham71c437d2020-01-31 15:56:57 -0800584 lr2.desiredRefreshRate = 60.0f;
585 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800586 lr2.name = "60Hz Heuristic";
587 EXPECT_EQ(expected120Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800588 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
589 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800590
591 lr1.desiredRefreshRate = 24.0f;
592 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800593 lr1.name = "24Hz ExplicitExactOrMultiple";
Ady Abraham71c437d2020-01-31 15:56:57 -0800594 lr2.desiredRefreshRate = 60.0f;
595 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800596 lr2.name = "60Hz ExplicitDefault";
597 EXPECT_EQ(expected120Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800598 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
599 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800600
601 lr1.desiredRefreshRate = 24.0f;
602 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800603 lr1.name = "24Hz ExplicitExactOrMultiple";
Ady Abraham71c437d2020-01-31 15:56:57 -0800604 lr2.desiredRefreshRate = 90.0f;
605 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800606 lr2.name = "90Hz Heuristic";
607 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800608 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
609 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800610
611 lr1.desiredRefreshRate = 24.0f;
612 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
613 lr1.name = "24Hz ExplicitExactOrMultiple";
614 lr2.desiredRefreshRate = 90.0f;
615 lr2.vote = LayerVoteType::ExplicitDefault;
616 lr2.name = "90Hz Heuristic";
617 EXPECT_EQ(expected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800618 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
619 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800620
621 lr1.desiredRefreshRate = 24.0f;
622 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800623 lr1.name = "24Hz ExplicitDefault";
Ady Abraham71c437d2020-01-31 15:56:57 -0800624 lr2.desiredRefreshRate = 90.0f;
625 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800626 lr2.name = "90Hz Heuristic";
627 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800628 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
629 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800630
631 lr1.desiredRefreshRate = 24.0f;
632 lr1.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800633 lr1.name = "24Hz Heuristic";
Ady Abraham71c437d2020-01-31 15:56:57 -0800634 lr2.desiredRefreshRate = 90.0f;
635 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800636 lr2.name = "90Hz ExplicitDefault";
637 EXPECT_EQ(expected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800638 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
639 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800640
641 lr1.desiredRefreshRate = 24.0f;
642 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800643 lr1.name = "24Hz ExplicitExactOrMultiple";
Ady Abraham71c437d2020-01-31 15:56:57 -0800644 lr2.desiredRefreshRate = 90.0f;
645 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800646 lr2.name = "90Hz ExplicitDefault";
647 EXPECT_EQ(expected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800648 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
649 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800650
651 lr1.desiredRefreshRate = 24.0f;
652 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800653 lr1.name = "24Hz ExplicitDefault";
Ady Abraham71c437d2020-01-31 15:56:57 -0800654 lr2.desiredRefreshRate = 90.0f;
655 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800656 lr2.name = "90Hz ExplicitExactOrMultiple";
657 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800658 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
659 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800660}
661
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800662TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_30_60) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800663 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800664 std::vector<RefreshRateConfigs::InputConfig> configs{
665 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
666 {HWC_CONFIG_ID_30, HWC_GROUP_ID_0, VSYNC_30}}};
667 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800668 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800669
670 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
671 RefreshRate expected30Config = {HWC_CONFIG_ID_30, VSYNC_30, HWC_GROUP_ID_0, "30fps", 30};
672
673 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
674 auto& lr = layers[0];
675
676 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800677 EXPECT_EQ(expected30Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800678 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
679 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800680
681 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800682 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800683 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
684 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800685
686 lr.desiredRefreshRate = 90.0f;
687 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800688 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800689 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
690 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800691
692 lr.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800693 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800694 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
695 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800696
697 lr.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800698 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800699 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
700 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800701
702 lr.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800703 EXPECT_EQ(expected30Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800704 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
705 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800706
707 lr.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800708 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800709 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
710 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800711}
712
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800713TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_30_60_72_90) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800714 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800715 std::vector<RefreshRateConfigs::InputConfig> configs{
716 {{HWC_CONFIG_ID_30, HWC_GROUP_ID_0, VSYNC_30},
717 {HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
718 {HWC_CONFIG_ID_72, HWC_GROUP_ID_0, VSYNC_72},
719 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
720 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800721 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800722
723 RefreshRate expected30Config = {HWC_CONFIG_ID_30, VSYNC_30, HWC_GROUP_ID_0, "30fps", 30};
724 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
725 RefreshRate expected72Config = {HWC_CONFIG_ID_72, VSYNC_72, HWC_GROUP_ID_0, "72fps", 70};
726 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
727
728 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
729 auto& lr = layers[0];
730
731 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800732 lr.name = "Min";
733 EXPECT_EQ(expected30Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800734 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
735 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800736
737 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800738 lr.name = "Max";
739 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800740 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
741 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800742
743 lr.desiredRefreshRate = 90.0f;
744 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800745 lr.name = "90Hz Heuristic";
746 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800747 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
748 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800749
750 lr.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800751 lr.name = "60Hz Heuristic";
752 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800753 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
754 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800755 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800756 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
757 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800758
759 lr.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800760 lr.name = "45Hz Heuristic";
761 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800762 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
763 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800764 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800765 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
766 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800767
768 lr.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800769 lr.name = "30Hz Heuristic";
770 EXPECT_EQ(expected30Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800771 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
772 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800773 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800774 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
775 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800776
777 lr.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800778 lr.name = "24Hz Heuristic";
779 EXPECT_EQ(expected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800780 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
781 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800782 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800783 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
784 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800785
786 lr.desiredRefreshRate = 24.0f;
787 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
788 lr.name = "24Hz ExplicitExactOrMultiple";
789 EXPECT_EQ(expected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800790 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
791 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800792 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800793 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
794 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800795}
796
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800797TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_PriorityTest) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800798 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800799 std::vector<RefreshRateConfigs::InputConfig> configs{
800 {{HWC_CONFIG_ID_30, HWC_GROUP_ID_0, VSYNC_30},
801 {HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
802 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
803 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800804 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800805
806 RefreshRate expected30Config = {HWC_CONFIG_ID_30, VSYNC_30, HWC_GROUP_ID_0, "30fps", 30};
807 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
808 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
809
810 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
811 LayerRequirement{.weight = 1.0f}};
812 auto& lr1 = layers[0];
813 auto& lr2 = layers[1];
814
815 lr1.vote = LayerVoteType::Min;
816 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800817 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800818 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
819 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800820
821 lr1.vote = LayerVoteType::Min;
822 lr2.vote = LayerVoteType::Heuristic;
823 lr2.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800824 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800825 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
826 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800827
828 lr1.vote = LayerVoteType::Min;
Ady Abraham71c437d2020-01-31 15:56:57 -0800829 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800830 lr2.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800831 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800832 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
833 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800834
835 lr1.vote = LayerVoteType::Max;
836 lr2.vote = LayerVoteType::Heuristic;
837 lr2.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800838 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800839 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
840 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800841
842 lr1.vote = LayerVoteType::Max;
Ady Abraham71c437d2020-01-31 15:56:57 -0800843 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800844 lr2.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800845 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800846 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
847 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800848
849 lr1.vote = LayerVoteType::Heuristic;
850 lr1.desiredRefreshRate = 15.0f;
851 lr2.vote = LayerVoteType::Heuristic;
852 lr2.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800853 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800854 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
855 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800856
857 lr1.vote = LayerVoteType::Heuristic;
858 lr1.desiredRefreshRate = 30.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800859 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800860 lr2.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800861 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800862 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
863 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800864}
865
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800866TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_24FpsVideo) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800867 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800868 std::vector<RefreshRateConfigs::InputConfig> configs{
869 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
870 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
871 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800872 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800873
874 RefreshRate expected30Config = {HWC_CONFIG_ID_30, VSYNC_30, HWC_GROUP_ID_0, "30fps", 30};
875 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
876 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
877
878 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
879 auto& lr = layers[0];
880
Ady Abraham71c437d2020-01-31 15:56:57 -0800881 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800882 for (float fps = 23.0f; fps < 25.0f; fps += 0.1f) {
883 lr.desiredRefreshRate = fps;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800884 const auto& refreshRate =
Ady Abraham6fb599b2020-03-05 13:48:22 -0800885 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
886 &ignored);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800887 printf("%.2fHz chooses %s\n", fps, refreshRate.name.c_str());
888 EXPECT_EQ(expected60Config, refreshRate);
889 }
890}
891
892TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getRefreshRateForContent_Explicit) {
893 std::vector<RefreshRateConfigs::InputConfig> configs{
894 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
895 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
896 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800897 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800898
899 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
900 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
901
902 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
903 LayerRequirement{.weight = 1.0f}};
904 auto& lr1 = layers[0];
905 auto& lr2 = layers[1];
906
907 lr1.vote = LayerVoteType::Heuristic;
908 lr1.desiredRefreshRate = 60.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800909 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800910 lr2.desiredRefreshRate = 90.0f;
911 EXPECT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(layers));
912
913 lr1.vote = LayerVoteType::Heuristic;
914 lr1.desiredRefreshRate = 90.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800915 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800916 lr2.desiredRefreshRate = 60.0f;
917 EXPECT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(layers));
918}
919
920TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getRefreshRateForContentV2_Explicit) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800921 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800922 std::vector<RefreshRateConfigs::InputConfig> configs{
923 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
924 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
925 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800926 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800927
928 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
929 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
930
931 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
932 LayerRequirement{.weight = 1.0f}};
933 auto& lr1 = layers[0];
934 auto& lr2 = layers[1];
935
936 lr1.vote = LayerVoteType::Heuristic;
937 lr1.desiredRefreshRate = 60.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800938 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800939 lr2.desiredRefreshRate = 90.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800940 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800941 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
942 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800943
944 lr1.vote = LayerVoteType::ExplicitDefault;
945 lr1.desiredRefreshRate = 90.0f;
946 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
947 lr2.desiredRefreshRate = 60.0f;
948 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800949 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
950 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800951
952 lr1.vote = LayerVoteType::Heuristic;
953 lr1.desiredRefreshRate = 90.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800954 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800955 lr2.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800956 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800957 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
958 &ignored));
Ady Abraham2139f732019-11-13 18:56:40 -0800959}
960
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800961TEST_F(RefreshRateConfigsTest, testInPolicy) {
962 RefreshRate expectedDefaultConfig = {HWC_CONFIG_ID_60, VSYNC_60_POINT_4, HWC_GROUP_ID_0,
963 "60fps", 60};
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800964 ASSERT_TRUE(expectedDefaultConfig.inPolicy(60.000004f, 60.000004f));
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800965 ASSERT_TRUE(expectedDefaultConfig.inPolicy(59.0f, 60.1f));
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800966 ASSERT_FALSE(expectedDefaultConfig.inPolicy(75.0f, 90.0f));
967 ASSERT_FALSE(expectedDefaultConfig.inPolicy(60.0011f, 90.0f));
968 ASSERT_FALSE(expectedDefaultConfig.inPolicy(50.0f, 59.998f));
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800969}
970
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800971TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_75HzContent) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800972 bool ignored;
Ady Abrahamf6b77072020-01-30 14:22:54 -0800973 std::vector<RefreshRateConfigs::InputConfig> configs{
974 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
975 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
976 auto refreshRateConfigs =
Ana Krulec3f6a2062020-01-23 15:48:01 -0800977 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abrahamf6b77072020-01-30 14:22:54 -0800978
979 RefreshRate expected30Config = {HWC_CONFIG_ID_30, VSYNC_30, HWC_GROUP_ID_0, "30fps", 30};
980 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
981 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
982
983 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
984 auto& lr = layers[0];
985
Ady Abraham71c437d2020-01-31 15:56:57 -0800986 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abrahamf6b77072020-01-30 14:22:54 -0800987 for (float fps = 75.0f; fps < 100.0f; fps += 0.1f) {
988 lr.desiredRefreshRate = fps;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800989 const auto& refreshRate =
Ady Abraham6fb599b2020-03-05 13:48:22 -0800990 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
991 &ignored);
Ady Abrahamf6b77072020-01-30 14:22:54 -0800992 printf("%.2fHz chooses %s\n", fps, refreshRate.name.c_str());
993 EXPECT_EQ(expected90Config, refreshRate);
994 }
995}
996
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800997TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_Multiples) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800998 bool ignored;
Ady Abraham34702102020-02-10 14:12:05 -0800999 std::vector<RefreshRateConfigs::InputConfig> configs{
1000 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
1001 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
1002 auto refreshRateConfigs =
1003 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
1004
1005 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
1006 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
1007
1008 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
1009 LayerRequirement{.weight = 1.0f}};
1010 auto& lr1 = layers[0];
1011 auto& lr2 = layers[1];
1012
1013 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1014 lr1.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001015 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -08001016 lr2.vote = LayerVoteType::Heuristic;
1017 lr2.desiredRefreshRate = 90.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001018 lr2.name = "90Hz Heuristic";
1019 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001020 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1021 &ignored));
Ady Abraham34702102020-02-10 14:12:05 -08001022
1023 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1024 lr1.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001025 lr1.name = "60Hz ExplicitExactOrMultiple";
1026 lr2.vote = LayerVoteType::ExplicitDefault;
1027 lr2.desiredRefreshRate = 90.0f;
1028 lr2.name = "90Hz ExplicitDefault";
1029 EXPECT_EQ(expected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001030 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1031 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001032
1033 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1034 lr1.desiredRefreshRate = 60.0f;
1035 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -08001036 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001037 lr2.name = "Max";
1038 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001039 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1040 &ignored));
Ady Abraham34702102020-02-10 14:12:05 -08001041
1042 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1043 lr1.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001044 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -08001045 lr2.vote = LayerVoteType::Heuristic;
1046 lr2.desiredRefreshRate = 90.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001047 lr2.name = "90Hz Heuristic";
1048 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001049 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1050 &ignored));
Ady Abraham34702102020-02-10 14:12:05 -08001051
1052 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1053 lr1.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001054 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -08001055 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001056 lr2.name = "Max";
1057 EXPECT_EQ(expected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001058 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1059 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001060}
1061
1062TEST_F(RefreshRateConfigsTest, scrollWhileWatching60fps_60_90) {
Ady Abraham6fb599b2020-03-05 13:48:22 -08001063 bool ignored;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001064 std::vector<RefreshRateConfigs::InputConfig> configs{
1065 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
1066 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
1067 auto refreshRateConfigs =
1068 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
1069
1070 RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60};
1071 RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90};
1072
1073 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
1074 LayerRequirement{.weight = 1.0f}};
1075 auto& lr1 = layers[0];
1076 auto& lr2 = layers[1];
1077
1078 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1079 lr1.desiredRefreshRate = 60.0f;
1080 lr1.name = "60Hz ExplicitExactOrMultiple";
1081 lr2.vote = LayerVoteType::NoVote;
1082 lr2.name = "NoVote";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001083 EXPECT_EQ(expected60Config,
1084 refreshRateConfigs->getRefreshRateForContentV2(layers, false, &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001085
1086 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1087 lr1.desiredRefreshRate = 60.0f;
1088 lr1.name = "60Hz ExplicitExactOrMultiple";
1089 lr2.vote = LayerVoteType::NoVote;
1090 lr2.name = "NoVote";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001091 EXPECT_EQ(expected90Config,
1092 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001093
1094 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1095 lr1.desiredRefreshRate = 60.0f;
1096 lr1.name = "60Hz ExplicitExactOrMultiple";
1097 lr2.vote = LayerVoteType::Max;
1098 lr2.name = "Max";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001099 EXPECT_EQ(expected90Config,
1100 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001101
1102 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1103 lr1.desiredRefreshRate = 60.0f;
1104 lr1.name = "60Hz ExplicitExactOrMultiple";
1105 lr2.vote = LayerVoteType::Max;
1106 lr2.name = "Max";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001107 EXPECT_EQ(expected90Config,
1108 refreshRateConfigs->getRefreshRateForContentV2(layers, false, &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001109
1110 // The other layer starts to provide buffers
1111 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1112 lr1.desiredRefreshRate = 60.0f;
1113 lr1.name = "60Hz ExplicitExactOrMultiple";
1114 lr2.vote = LayerVoteType::Heuristic;
1115 lr2.desiredRefreshRate = 90.0f;
1116 lr2.name = "90Hz Heuristic";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001117 EXPECT_EQ(expected90Config,
1118 refreshRateConfigs->getRefreshRateForContentV2(layers, false, &ignored));
1119}
1120
1121TEST_F(RefreshRateConfigsTest, touchConsidered) {
1122 bool touchConsidered;
1123 std::vector<RefreshRateConfigs::InputConfig> configs{
1124 {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60},
1125 {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}};
1126 auto refreshRateConfigs =
1127 std::make_unique<RefreshRateConfigs>(configs, /*currentConfigId=*/HWC_CONFIG_ID_60);
1128
1129 refreshRateConfigs->getRefreshRateForContentV2({}, false, &touchConsidered);
1130 EXPECT_EQ(false, touchConsidered);
1131
1132 refreshRateConfigs->getRefreshRateForContentV2({}, true, &touchConsidered);
1133 EXPECT_EQ(true, touchConsidered);
1134
1135 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
1136 LayerRequirement{.weight = 1.0f}};
1137 auto& lr1 = layers[0];
1138 auto& lr2 = layers[1];
1139
1140 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1141 lr1.desiredRefreshRate = 60.0f;
1142 lr1.name = "60Hz ExplicitExactOrMultiple";
1143 lr2.vote = LayerVoteType::Heuristic;
1144 lr2.name = "NoVote";
1145 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &touchConsidered);
1146 EXPECT_EQ(true, touchConsidered);
1147
1148 lr1.vote = LayerVoteType::ExplicitDefault;
1149 lr1.desiredRefreshRate = 60.0f;
1150 lr1.name = "60Hz ExplicitExactOrMultiple";
1151 lr2.vote = LayerVoteType::Heuristic;
1152 lr2.name = "NoVote";
1153 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &touchConsidered);
1154 EXPECT_EQ(false, touchConsidered);
1155
1156 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1157 lr1.desiredRefreshRate = 60.0f;
1158 lr1.name = "60Hz ExplicitExactOrMultiple";
1159 lr2.vote = LayerVoteType::Heuristic;
1160 lr2.name = "NoVote";
1161 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &touchConsidered);
1162 EXPECT_EQ(true, touchConsidered);
1163
1164 lr1.vote = LayerVoteType::ExplicitDefault;
1165 lr1.desiredRefreshRate = 60.0f;
1166 lr1.name = "60Hz ExplicitExactrMultiple";
1167 lr2.vote = LayerVoteType::Heuristic;
1168 lr2.name = "NoVote";
1169 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &touchConsidered);
1170 EXPECT_EQ(false, touchConsidered);
Ady Abraham34702102020-02-10 14:12:05 -08001171}
1172
Alec Mouri0a1cc962019-03-14 12:33:02 -07001173} // namespace
1174} // namespace scheduler
1175} // namespace android