blob: 2ceb89c3e38b4b30f96f341aef9661e0d6eefa63 [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"
Ady Abrahamabc27602020-04-08 17:20:29 -070027#include "mock/DisplayHardware/MockDisplay.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070028
29using namespace std::chrono_literals;
30using testing::_;
31
32namespace android {
33namespace scheduler {
34
Peiyong Line9d809e2020-04-14 13:10:48 -070035namespace hal = android::hardware::graphics::composer::hal;
36
Alec Mouri0a1cc962019-03-14 12:33:02 -070037using RefreshRate = RefreshRateConfigs::RefreshRate;
Ady Abraham8a82ba62020-01-17 12:43:17 -080038using LayerVoteType = RefreshRateConfigs::LayerVoteType;
39using LayerRequirement = RefreshRateConfigs::LayerRequirement;
Alec Mouri0a1cc962019-03-14 12:33:02 -070040
41class RefreshRateConfigsTest : public testing::Test {
42protected:
Alec Mouri0a1cc962019-03-14 12:33:02 -070043 RefreshRateConfigsTest();
44 ~RefreshRateConfigsTest();
Ady Abrahamabc27602020-04-08 17:20:29 -070045
46 // Test config IDs
47 static inline const HwcConfigIndexType HWC_CONFIG_ID_60 = HwcConfigIndexType(0);
48 static inline const HwcConfigIndexType HWC_CONFIG_ID_90 = HwcConfigIndexType(1);
49 static inline const HwcConfigIndexType HWC_CONFIG_ID_72 = HwcConfigIndexType(2);
50 static inline const HwcConfigIndexType HWC_CONFIG_ID_120 = HwcConfigIndexType(3);
51 static inline const HwcConfigIndexType HWC_CONFIG_ID_30 = HwcConfigIndexType(4);
52
53 // Test configs
54 std::shared_ptr<const HWC2::Display::Config> mConfig60 =
55 createConfig(HWC_CONFIG_ID_60, 0, static_cast<int64_t>(1e9f / 60));
56 std::shared_ptr<const HWC2::Display::Config> mConfig90 =
57 createConfig(HWC_CONFIG_ID_90, 0, static_cast<int64_t>(1e9f / 90));
58 std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentGroup =
59 createConfig(HWC_CONFIG_ID_90, 1, static_cast<int64_t>(1e9f / 90));
60 std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentResolution =
61 createConfig(HWC_CONFIG_ID_90, 0, static_cast<int64_t>(1e9f / 90), 111, 222);
62 std::shared_ptr<const HWC2::Display::Config> mConfig72 =
63 createConfig(HWC_CONFIG_ID_72, 0, static_cast<int64_t>(1e9f / 72));
64 std::shared_ptr<const HWC2::Display::Config> mConfig72DifferentGroup =
65 createConfig(HWC_CONFIG_ID_72, 1, static_cast<int64_t>(1e9f / 72));
66 std::shared_ptr<const HWC2::Display::Config> mConfig120 =
67 createConfig(HWC_CONFIG_ID_120, 0, static_cast<int64_t>(1e9f / 120));
68 std::shared_ptr<const HWC2::Display::Config> mConfig120DifferentGroup =
69 createConfig(HWC_CONFIG_ID_120, 1, static_cast<int64_t>(1e9f / 120));
70 std::shared_ptr<const HWC2::Display::Config> mConfig30 =
71 createConfig(HWC_CONFIG_ID_30, 0, static_cast<int64_t>(1e9f / 30));
72
73 // Test device configurations
74 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60OnlyConfigDevice = {mConfig60};
75 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90Device = {mConfig60, mConfig90};
76 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentGroups =
77 {mConfig60, mConfig90DifferentGroup};
78 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentResolutions =
79 {mConfig60, mConfig90DifferentResolution};
80 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_72_90Device = {mConfig60,
81 mConfig90,
82 mConfig72};
83 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90_72_120Device = {mConfig60,
84 mConfig90,
85 mConfig72,
86 mConfig120};
87 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90_120Device = {mConfig60,
88 mConfig90,
89 mConfig72,
90 mConfig120,
91 mConfig30};
92 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60Device =
93 {mConfig60, mConfig90DifferentGroup, mConfig72DifferentGroup, mConfig120DifferentGroup,
94 mConfig30};
95 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90Device =
96 {mConfig60, mConfig90, mConfig72, mConfig120DifferentGroup, mConfig30};
97 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_90Device =
98 {mConfig60, mConfig90, mConfig72DifferentGroup, mConfig120DifferentGroup, mConfig30};
99
100 // Expected RefreshRate objects
101 RefreshRate mExpected60Config = {HWC_CONFIG_ID_60, mConfig60, "60fps", 60,
102 RefreshRate::ConstructorTag(0)};
103 RefreshRate mExpectedAlmost60Config = {HWC_CONFIG_ID_60,
104 createConfig(HWC_CONFIG_ID_60, 0, 16666665), "60fps", 60,
105 RefreshRate::ConstructorTag(0)};
106 RefreshRate mExpected90Config = {HWC_CONFIG_ID_90, mConfig90, "90fps", 90,
107 RefreshRate::ConstructorTag(0)};
108 RefreshRate mExpected90DifferentGroupConfig = {HWC_CONFIG_ID_90, mConfig90DifferentGroup,
109 "90fps", 90, RefreshRate::ConstructorTag(0)};
110 RefreshRate mExpected90DifferentResolutionConfig = {HWC_CONFIG_ID_90,
111 mConfig90DifferentResolution, "90fps", 90,
112 RefreshRate::ConstructorTag(0)};
113 RefreshRate mExpected72Config = {HWC_CONFIG_ID_72, mConfig72, "72fps", 72,
114 RefreshRate::ConstructorTag(0)};
115 RefreshRate mExpected30Config = {HWC_CONFIG_ID_30, mConfig30, "30fps", 30,
116 RefreshRate::ConstructorTag(0)};
117 RefreshRate mExpected120Config = {HWC_CONFIG_ID_120, mConfig120, "120fps", 120,
118 RefreshRate::ConstructorTag(0)};
119
120 Hwc2::mock::Display mDisplay;
121
122private:
123 std::shared_ptr<const HWC2::Display::Config> createConfig(HwcConfigIndexType configId,
124 int32_t configGroup,
125 int64_t vsyncPeriod,
126 int32_t hight = -1,
127 int32_t width = -1);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700128};
129
Ady Abrahamabc27602020-04-08 17:20:29 -0700130using Builder = HWC2::Display::Config::Builder;
131
Alec Mouri0a1cc962019-03-14 12:33:02 -0700132RefreshRateConfigsTest::RefreshRateConfigsTest() {
133 const ::testing::TestInfo* const test_info =
134 ::testing::UnitTest::GetInstance()->current_test_info();
135 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
136}
137
138RefreshRateConfigsTest::~RefreshRateConfigsTest() {
139 const ::testing::TestInfo* const test_info =
140 ::testing::UnitTest::GetInstance()->current_test_info();
141 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
142}
143
Ady Abrahamabc27602020-04-08 17:20:29 -0700144std::shared_ptr<const HWC2::Display::Config> RefreshRateConfigsTest::createConfig(
145 HwcConfigIndexType configId, int32_t configGroup, int64_t vsyncPeriod, int32_t hight,
146 int32_t width) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700147 return HWC2::Display::Config::Builder(mDisplay, hal::HWConfigId(configId.value()))
Ady Abrahamabc27602020-04-08 17:20:29 -0700148 .setVsyncPeriod(int32_t(vsyncPeriod))
149 .setConfigGroup(configGroup)
150 .setHeight(hight)
151 .setWidth(width)
152 .build();
153}
154
Alec Mouri0a1cc962019-03-14 12:33:02 -0700155namespace {
156/* ------------------------------------------------------------------------
157 * Test cases
158 */
Ady Abraham2139f732019-11-13 18:56:40 -0800159TEST_F(RefreshRateConfigsTest, oneDeviceConfig_SwitchingSupported) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700160 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700161 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
162 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700163}
164
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100165TEST_F(RefreshRateConfigsTest, invalidPolicy) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100166 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700167 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
168 /*currentConfigId=*/HWC_CONFIG_ID_60);
Steven Thomasd4071902020-03-24 16:02:53 -0700169 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy({HwcConfigIndexType(10), 60, 60}), 0);
170 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, 20, 40}), 0);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100171}
172
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700173TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700174 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700175 std::make_unique<RefreshRateConfigs>(m60_90Device,
176 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700177
Ady Abraham2e1dd892020-03-05 13:48:36 -0800178 const auto& minRate = refreshRateConfigs->getMinRefreshRate();
179 const auto& performanceRate = refreshRateConfigs->getMaxRefreshRate();
Alec Mouri0a1cc962019-03-14 12:33:02 -0700180
Ady Abrahamabc27602020-04-08 17:20:29 -0700181 ASSERT_EQ(mExpected60Config, minRate);
182 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800183
Ady Abraham2e1dd892020-03-05 13:48:36 -0800184 const auto& minRateByPolicy = refreshRateConfigs->getMinRefreshRateByPolicy();
185 const auto& performanceRateByPolicy = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800186 ASSERT_EQ(minRateByPolicy, minRate);
187 ASSERT_EQ(performanceRateByPolicy, performanceRate);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700188}
Ady Abraham2139f732019-11-13 18:56:40 -0800189
190TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentGroups) {
Ady Abraham2139f732019-11-13 18:56:40 -0800191 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700192 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
193 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800194
Ady Abraham2e1dd892020-03-05 13:48:36 -0800195 const auto& minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
196 const auto& performanceRate = refreshRateConfigs->getMaxRefreshRate();
197 const auto& minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
198 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800199
Ady Abrahamabc27602020-04-08 17:20:29 -0700200 ASSERT_EQ(mExpected60Config, minRate);
201 ASSERT_EQ(mExpected60Config, minRate60);
202 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800203
Steven Thomasd4071902020-03-24 16:02:53 -0700204 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, 60, 90}), 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800205 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
206
Ady Abraham2e1dd892020-03-05 13:48:36 -0800207 const auto& minRate90 = refreshRateConfigs->getMinRefreshRateByPolicy();
208 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800209
Ady Abrahamabc27602020-04-08 17:20:29 -0700210 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate);
211 ASSERT_EQ(mExpected90DifferentGroupConfig, minRate90);
212 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate90);
213}
214
215TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentResolutions) {
216 auto refreshRateConfigs =
217 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentResolutions,
218 /*currentConfigId=*/HWC_CONFIG_ID_60);
219
220 const auto& minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
221 const auto& performanceRate = refreshRateConfigs->getMaxRefreshRate();
222 const auto& minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
223 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
224
225 ASSERT_EQ(mExpected60Config, minRate);
226 ASSERT_EQ(mExpected60Config, minRate60);
227 ASSERT_EQ(mExpected60Config, performanceRate60);
228
229 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, 60, 90}), 0);
230 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
231
232 const auto& minRate90 = refreshRateConfigs->getMinRefreshRateByPolicy();
233 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
234
235 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate);
236 ASSERT_EQ(mExpected90DifferentResolutionConfig, minRate90);
237 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate90);
Ady Abraham2139f732019-11-13 18:56:40 -0800238}
239
240TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_policyChange) {
Ady Abraham2139f732019-11-13 18:56:40 -0800241 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700242 std::make_unique<RefreshRateConfigs>(m60_90Device,
243 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ana Krulec3f6a2062020-01-23 15:48:01 -0800244
Ady Abraham2e1dd892020-03-05 13:48:36 -0800245 auto& minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
246 auto& performanceRate = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800247
Ady Abrahamabc27602020-04-08 17:20:29 -0700248 ASSERT_EQ(mExpected60Config, minRate);
249 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800250
Steven Thomasd4071902020-03-24 16:02:53 -0700251 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, 60, 60}), 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800252
Ady Abraham2e1dd892020-03-05 13:48:36 -0800253 auto& minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
254 auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abrahamabc27602020-04-08 17:20:29 -0700255 ASSERT_EQ(mExpected60Config, minRate60);
256 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800257}
258
259TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getCurrentRefreshRate) {
Ady Abraham2139f732019-11-13 18:56:40 -0800260 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700261 std::make_unique<RefreshRateConfigs>(m60_90Device,
262 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800263 {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800264 auto& current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700265 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800266 }
267
268 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
269 {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800270 auto& current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700271 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800272 }
273
Steven Thomasd4071902020-03-24 16:02:53 -0700274 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, 90, 90}), 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800275 {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800276 auto& current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700277 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800278 }
279}
280
281TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getRefreshRateForContent) {
Ady Abraham2139f732019-11-13 18:56:40 -0800282 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700283 std::make_unique<RefreshRateConfigs>(m60_90Device,
284 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800285
Ady Abraham8a82ba62020-01-17 12:43:17 -0800286 const auto makeLayerRequirements = [](float refreshRate) -> std::vector<LayerRequirement> {
287 return {{"testLayer", LayerVoteType::Heuristic, refreshRate, 1.0f}};
288 };
289
Ady Abrahamabc27602020-04-08 17:20:29 -0700290 EXPECT_EQ(mExpected90Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800291 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(90.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700292 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800293 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(60.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700294 EXPECT_EQ(mExpected90Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800295 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(45.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700296 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800297 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(30.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700298 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800299 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(24.0f)));
Ady Abraham2139f732019-11-13 18:56:40 -0800300
Steven Thomasd4071902020-03-24 16:02:53 -0700301 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, 60, 60}), 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700302 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800303 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(90.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700304 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800305 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(60.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700306 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800307 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(45.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700308 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800309 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(30.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700310 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800311 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(24.0f)));
Ady Abraham2139f732019-11-13 18:56:40 -0800312
Steven Thomasd4071902020-03-24 16:02:53 -0700313 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, 90, 90}), 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700314 EXPECT_EQ(mExpected90Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800315 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(90.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700316 EXPECT_EQ(mExpected90Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800317 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(60.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700318 EXPECT_EQ(mExpected90Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800319 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(45.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700320 EXPECT_EQ(mExpected90Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800321 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(30.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700322 EXPECT_EQ(mExpected90Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800323 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(24.0f)));
Steven Thomasd4071902020-03-24 16:02:53 -0700324 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, 0, 120}), 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700325 EXPECT_EQ(mExpected90Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800326 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(90.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700327 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800328 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(60.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700329 EXPECT_EQ(mExpected90Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800330 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(45.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700331 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800332 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(30.0f)));
Ady Abrahamabc27602020-04-08 17:20:29 -0700333 EXPECT_EQ(mExpected60Config,
Ady Abraham8a82ba62020-01-17 12:43:17 -0800334 refreshRateConfigs->getRefreshRateForContent(makeLayerRequirements(24.0f)));
335}
336
Ana Krulec3d367c82020-02-25 15:02:01 -0800337TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_noLayers) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800338 bool ignored;
Ady Abrahamabc27602020-04-08 17:20:29 -0700339 auto refreshRateConfigs =
340 std::make_unique<RefreshRateConfigs>(m60_72_90Device, /*currentConfigId=*/
341 HWC_CONFIG_ID_72);
Ana Krulec3d367c82020-02-25 15:02:01 -0800342
343 // If there are not layers, there is not content detection, so return the current
344 // refresh rate.
345 auto layers = std::vector<LayerRequirement>{};
Ady Abrahamabc27602020-04-08 17:20:29 -0700346 EXPECT_EQ(mExpected72Config,
Ana Krulec3d367c82020-02-25 15:02:01 -0800347 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/
Ady Abraham6fb599b2020-03-05 13:48:22 -0800348 false, &ignored));
Ana Krulec3d367c82020-02-25 15:02:01 -0800349
350 // Current refresh rate can always be changed.
351 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_60);
Ady Abrahamabc27602020-04-08 17:20:29 -0700352 EXPECT_EQ(mExpected60Config,
Ana Krulec3d367c82020-02-25 15:02:01 -0800353 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/
Ady Abraham6fb599b2020-03-05 13:48:22 -0800354 false, &ignored));
Ana Krulec3d367c82020-02-25 15:02:01 -0800355}
356
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800357TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_60_90) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800358 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800359 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700360 std::make_unique<RefreshRateConfigs>(m60_90Device,
361 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800362
363 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
364 auto& lr = layers[0];
365
366 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800367 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700368 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800369 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
370 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800371
372 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800373 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700374 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800375 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
376 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800377
378 lr.desiredRefreshRate = 90.0f;
379 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800380 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700381 EXPECT_EQ(mExpected90Config,
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 = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800386 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700387 EXPECT_EQ(mExpected60Config,
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 = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800392 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700393 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800394 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
395 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800396
397 lr.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800398 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700399 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800400 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
401 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800402
403 lr.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800404 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700405 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800406 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
407 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800408
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800409 lr.name = "";
Steven Thomasd4071902020-03-24 16:02:53 -0700410 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, 60, 60}), 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800411
412 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700413 EXPECT_EQ(mExpected60Config,
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 Abrahamabc27602020-04-08 17:20:29 -0700418 EXPECT_EQ(mExpected60Config,
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 Abrahamabc27602020-04-08 17:20:29 -0700424 EXPECT_EQ(mExpected60Config,
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 Abrahamabc27602020-04-08 17:20:29 -0700429 EXPECT_EQ(mExpected60Config,
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 Abrahamabc27602020-04-08 17:20:29 -0700434 EXPECT_EQ(mExpected60Config,
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 Abrahamabc27602020-04-08 17:20:29 -0700439 EXPECT_EQ(mExpected60Config,
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 Abrahamabc27602020-04-08 17:20:29 -0700444 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800445 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
446 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800447
Steven Thomasd4071902020-03-24 16:02:53 -0700448 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, 90, 90}), 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800449
450 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700451 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800452 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
453 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800454
455 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700456 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800457 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
458 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800459
460 lr.desiredRefreshRate = 90.0f;
461 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700462 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800463 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
464 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800465
466 lr.desiredRefreshRate = 60.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700467 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800468 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
469 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800470
471 lr.desiredRefreshRate = 45.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700472 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800473 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
474 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800475
476 lr.desiredRefreshRate = 30.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700477 EXPECT_EQ(mExpected90Config,
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 = 24.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700482 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800483 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
484 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800485
Steven Thomasd4071902020-03-24 16:02:53 -0700486 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, 0, 120}), 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800487 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700488 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800489 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
490 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800491
492 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700493 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800494 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
495 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800496
497 lr.desiredRefreshRate = 90.0f;
498 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700499 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800500 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
501 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800502
503 lr.desiredRefreshRate = 60.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700504 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800505 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
506 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800507
508 lr.desiredRefreshRate = 45.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700509 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800510 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
511 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800512
513 lr.desiredRefreshRate = 30.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700514 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800515 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
516 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800517
518 lr.desiredRefreshRate = 24.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700519 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800520 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
521 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800522}
523
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800524TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_60_72_90) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800525 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800526 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700527 std::make_unique<RefreshRateConfigs>(m60_72_90Device,
528 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800529
530 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
531 auto& lr = layers[0];
532
533 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700534 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800535 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
536 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800537
538 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700539 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800540 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
541 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800542
543 lr.desiredRefreshRate = 90.0f;
544 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700545 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800546 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
547 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800548
549 lr.desiredRefreshRate = 60.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700550 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800551 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
552 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800553
554 lr.desiredRefreshRate = 45.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700555 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800556 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
557 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800558
559 lr.desiredRefreshRate = 30.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700560 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800561 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
562 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800563
564 lr.desiredRefreshRate = 24.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700565 EXPECT_EQ(mExpected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800566 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
567 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800568}
569
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800570TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_30_60_72_90_120) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800571 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800572 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700573 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
574 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800575
576 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
577 LayerRequirement{.weight = 1.0f}};
578 auto& lr1 = layers[0];
579 auto& lr2 = layers[1];
580
581 lr1.desiredRefreshRate = 24.0f;
582 lr1.vote = LayerVoteType::Heuristic;
583 lr2.desiredRefreshRate = 60.0f;
584 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700585 EXPECT_EQ(mExpected120Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800586 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
587 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800588
589 lr1.desiredRefreshRate = 24.0f;
590 lr1.vote = LayerVoteType::Heuristic;
591 lr2.desiredRefreshRate = 48.0f;
592 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700593 EXPECT_EQ(mExpected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800594 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
595 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800596
597 lr1.desiredRefreshRate = 24.0f;
598 lr1.vote = LayerVoteType::Heuristic;
599 lr2.desiredRefreshRate = 48.0f;
600 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700601 EXPECT_EQ(mExpected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800602 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
603 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800604}
605
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800606TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_30_60_90_120_DifferentTypes) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800607 bool ignored;
Ady Abraham71c437d2020-01-31 15:56:57 -0800608 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700609 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
610 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham71c437d2020-01-31 15:56:57 -0800611
612 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
613 LayerRequirement{.weight = 1.0f}};
614 auto& lr1 = layers[0];
615 auto& lr2 = layers[1];
616
617 lr1.desiredRefreshRate = 24.0f;
618 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800619 lr1.name = "24Hz ExplicitDefault";
Ady Abraham71c437d2020-01-31 15:56:57 -0800620 lr2.desiredRefreshRate = 60.0f;
621 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800622 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700623 EXPECT_EQ(mExpected120Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800624 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
625 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800626
627 lr1.desiredRefreshRate = 24.0f;
628 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800629 lr1.name = "24Hz ExplicitExactOrMultiple";
Ady Abraham71c437d2020-01-31 15:56:57 -0800630 lr2.desiredRefreshRate = 60.0f;
631 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800632 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700633 EXPECT_EQ(mExpected120Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800634 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
635 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800636
637 lr1.desiredRefreshRate = 24.0f;
638 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800639 lr1.name = "24Hz ExplicitExactOrMultiple";
Ady Abraham71c437d2020-01-31 15:56:57 -0800640 lr2.desiredRefreshRate = 60.0f;
641 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800642 lr2.name = "60Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700643 EXPECT_EQ(mExpected120Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800644 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
645 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800646
647 lr1.desiredRefreshRate = 24.0f;
648 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800649 lr1.name = "24Hz ExplicitExactOrMultiple";
Ady Abraham71c437d2020-01-31 15:56:57 -0800650 lr2.desiredRefreshRate = 90.0f;
651 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800652 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700653 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800654 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
655 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800656
657 lr1.desiredRefreshRate = 24.0f;
658 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
659 lr1.name = "24Hz ExplicitExactOrMultiple";
660 lr2.desiredRefreshRate = 90.0f;
661 lr2.vote = LayerVoteType::ExplicitDefault;
662 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700663 EXPECT_EQ(mExpected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800664 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
665 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800666
667 lr1.desiredRefreshRate = 24.0f;
668 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800669 lr1.name = "24Hz ExplicitDefault";
Ady Abraham71c437d2020-01-31 15:56:57 -0800670 lr2.desiredRefreshRate = 90.0f;
671 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800672 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700673 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800674 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
675 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800676
677 lr1.desiredRefreshRate = 24.0f;
678 lr1.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800679 lr1.name = "24Hz Heuristic";
Ady Abraham71c437d2020-01-31 15:56:57 -0800680 lr2.desiredRefreshRate = 90.0f;
681 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800682 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700683 EXPECT_EQ(mExpected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800684 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
685 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800686
687 lr1.desiredRefreshRate = 24.0f;
688 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800689 lr1.name = "24Hz ExplicitExactOrMultiple";
Ady Abraham71c437d2020-01-31 15:56:57 -0800690 lr2.desiredRefreshRate = 90.0f;
691 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800692 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700693 EXPECT_EQ(mExpected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800694 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
695 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800696
697 lr1.desiredRefreshRate = 24.0f;
698 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800699 lr1.name = "24Hz ExplicitDefault";
Ady Abraham71c437d2020-01-31 15:56:57 -0800700 lr2.desiredRefreshRate = 90.0f;
701 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800702 lr2.name = "90Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700703 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800704 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
705 &ignored));
Ady Abraham71c437d2020-01-31 15:56:57 -0800706}
707
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800708TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_30_60) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800709 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800710 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700711 std::make_unique<RefreshRateConfigs>(m30_60Device,
712 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800713
714 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
715 auto& lr = layers[0];
716
717 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700718 EXPECT_EQ(mExpected30Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800719 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
720 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800721
722 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700723 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800724 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
725 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800726
727 lr.desiredRefreshRate = 90.0f;
728 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700729 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800730 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
731 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800732
733 lr.desiredRefreshRate = 60.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700734 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800735 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
736 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800737
738 lr.desiredRefreshRate = 45.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700739 EXPECT_EQ(mExpected60Config,
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 = 30.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700744 EXPECT_EQ(mExpected30Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800745 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
746 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800747
748 lr.desiredRefreshRate = 24.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700749 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800750 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
751 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800752}
753
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800754TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_30_60_72_90) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800755 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800756 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700757 std::make_unique<RefreshRateConfigs>(m30_60_72_90Device,
758 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800759
760 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
761 auto& lr = layers[0];
762
763 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800764 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700765 EXPECT_EQ(mExpected30Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800766 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
767 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800768
769 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800770 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700771 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800772 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
773 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800774
775 lr.desiredRefreshRate = 90.0f;
776 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800777 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700778 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800779 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
780 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800781
782 lr.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800783 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700784 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800785 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
786 &ignored));
Ady Abrahamabc27602020-04-08 17:20:29 -0700787 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800788 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
789 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800790
791 lr.desiredRefreshRate = 45.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800792 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700793 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800794 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
795 &ignored));
Ady Abrahamabc27602020-04-08 17:20:29 -0700796 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800797 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
798 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800799
800 lr.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800801 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700802 EXPECT_EQ(mExpected30Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800803 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
804 &ignored));
Ady Abrahamabc27602020-04-08 17:20:29 -0700805 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800806 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
807 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800808
809 lr.desiredRefreshRate = 24.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800810 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700811 EXPECT_EQ(mExpected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800812 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
813 &ignored));
Ady Abrahamabc27602020-04-08 17:20:29 -0700814 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800815 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
816 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800817
818 lr.desiredRefreshRate = 24.0f;
819 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
820 lr.name = "24Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700821 EXPECT_EQ(mExpected72Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800822 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
823 &ignored));
Ady Abrahamabc27602020-04-08 17:20:29 -0700824 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800825 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ true,
826 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800827}
828
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800829TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_PriorityTest) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800830 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800831 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700832 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
833 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800834
835 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
836 LayerRequirement{.weight = 1.0f}};
837 auto& lr1 = layers[0];
838 auto& lr2 = layers[1];
839
840 lr1.vote = LayerVoteType::Min;
841 lr2.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700842 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800843 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
844 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800845
846 lr1.vote = LayerVoteType::Min;
847 lr2.vote = LayerVoteType::Heuristic;
848 lr2.desiredRefreshRate = 24.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700849 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800850 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
851 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800852
853 lr1.vote = LayerVoteType::Min;
Ady Abraham71c437d2020-01-31 15:56:57 -0800854 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800855 lr2.desiredRefreshRate = 24.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700856 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800857 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
858 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800859
860 lr1.vote = LayerVoteType::Max;
861 lr2.vote = LayerVoteType::Heuristic;
862 lr2.desiredRefreshRate = 60.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700863 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800864 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
865 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800866
867 lr1.vote = LayerVoteType::Max;
Ady Abraham71c437d2020-01-31 15:56:57 -0800868 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800869 lr2.desiredRefreshRate = 60.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700870 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800871 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
872 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800873
874 lr1.vote = LayerVoteType::Heuristic;
875 lr1.desiredRefreshRate = 15.0f;
876 lr2.vote = LayerVoteType::Heuristic;
877 lr2.desiredRefreshRate = 45.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700878 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800879 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
880 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800881
882 lr1.vote = LayerVoteType::Heuristic;
883 lr1.desiredRefreshRate = 30.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800884 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800885 lr2.desiredRefreshRate = 45.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700886 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800887 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
888 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800889}
890
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800891TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_24FpsVideo) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800892 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800893 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700894 std::make_unique<RefreshRateConfigs>(m60_90Device,
895 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800896
897 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
898 auto& lr = layers[0];
899
Ady Abraham71c437d2020-01-31 15:56:57 -0800900 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800901 for (float fps = 23.0f; fps < 25.0f; fps += 0.1f) {
902 lr.desiredRefreshRate = fps;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800903 const auto& refreshRate =
Ady Abraham6fb599b2020-03-05 13:48:22 -0800904 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
905 &ignored);
Ady Abrahamabc27602020-04-08 17:20:29 -0700906 printf("%.2fHz chooses %s\n", fps, refreshRate.getName().c_str());
907 EXPECT_EQ(mExpected60Config, refreshRate);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800908 }
909}
910
911TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getRefreshRateForContent_Explicit) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800912 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700913 std::make_unique<RefreshRateConfigs>(m60_90Device,
914 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800915
916 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
917 LayerRequirement{.weight = 1.0f}};
918 auto& lr1 = layers[0];
919 auto& lr2 = layers[1];
920
921 lr1.vote = LayerVoteType::Heuristic;
922 lr1.desiredRefreshRate = 60.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800923 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800924 lr2.desiredRefreshRate = 90.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700925 EXPECT_EQ(mExpected90Config, refreshRateConfigs->getRefreshRateForContent(layers));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800926
927 lr1.vote = LayerVoteType::Heuristic;
928 lr1.desiredRefreshRate = 90.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800929 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800930 lr2.desiredRefreshRate = 60.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700931 EXPECT_EQ(mExpected60Config, refreshRateConfigs->getRefreshRateForContent(layers));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800932}
933
934TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getRefreshRateForContentV2_Explicit) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800935 bool ignored;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800936 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700937 std::make_unique<RefreshRateConfigs>(m60_90Device,
938 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800939
940 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
941 LayerRequirement{.weight = 1.0f}};
942 auto& lr1 = layers[0];
943 auto& lr2 = layers[1];
944
945 lr1.vote = LayerVoteType::Heuristic;
946 lr1.desiredRefreshRate = 60.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800947 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800948 lr2.desiredRefreshRate = 90.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700949 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800950 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
951 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800952
953 lr1.vote = LayerVoteType::ExplicitDefault;
954 lr1.desiredRefreshRate = 90.0f;
955 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
956 lr2.desiredRefreshRate = 60.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700957 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800958 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
959 &ignored));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800960
961 lr1.vote = LayerVoteType::Heuristic;
962 lr1.desiredRefreshRate = 90.0f;
Ady Abraham71c437d2020-01-31 15:56:57 -0800963 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800964 lr2.desiredRefreshRate = 60.0f;
Ady Abrahamabc27602020-04-08 17:20:29 -0700965 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -0800966 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
967 &ignored));
Ady Abraham2139f732019-11-13 18:56:40 -0800968}
969
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800970TEST_F(RefreshRateConfigsTest, testInPolicy) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700971 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(60.000004f, 60.000004f));
972 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(59.0f, 60.1f));
973 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(75.0f, 90.0f));
974 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(60.0011f, 90.0f));
975 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(50.0f, 59.998f));
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800976}
977
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800978TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_75HzContent) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800979 bool ignored;
Ady Abrahamf6b77072020-01-30 14:22:54 -0800980 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700981 std::make_unique<RefreshRateConfigs>(m60_90Device,
982 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abrahamf6b77072020-01-30 14:22:54 -0800983
984 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
985 auto& lr = layers[0];
986
Ady Abraham71c437d2020-01-31 15:56:57 -0800987 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abrahamf6b77072020-01-30 14:22:54 -0800988 for (float fps = 75.0f; fps < 100.0f; fps += 0.1f) {
989 lr.desiredRefreshRate = fps;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800990 const auto& refreshRate =
Ady Abraham6fb599b2020-03-05 13:48:22 -0800991 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
992 &ignored);
Ady Abrahamabc27602020-04-08 17:20:29 -0700993 printf("%.2fHz chooses %s\n", fps, refreshRate.getName().c_str());
994 EXPECT_EQ(mExpected90Config, refreshRate);
Ady Abrahamf6b77072020-01-30 14:22:54 -0800995 }
996}
997
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800998TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_Multiples) {
Ady Abraham6fb599b2020-03-05 13:48:22 -0800999 bool ignored;
Ady Abraham34702102020-02-10 14:12:05 -08001000 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -07001001 std::make_unique<RefreshRateConfigs>(m60_90Device,
1002 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham34702102020-02-10 14:12:05 -08001003
1004 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
1005 LayerRequirement{.weight = 1.0f}};
1006 auto& lr1 = layers[0];
1007 auto& lr2 = layers[1];
1008
1009 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1010 lr1.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001011 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -08001012 lr2.vote = LayerVoteType::Heuristic;
1013 lr2.desiredRefreshRate = 90.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001014 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -07001015 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001016 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1017 &ignored));
Ady Abraham34702102020-02-10 14:12:05 -08001018
1019 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1020 lr1.desiredRefreshRate = 60.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001021 lr1.name = "60Hz ExplicitExactOrMultiple";
1022 lr2.vote = LayerVoteType::ExplicitDefault;
1023 lr2.desiredRefreshRate = 90.0f;
1024 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -07001025 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001026 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1027 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001028
1029 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1030 lr1.desiredRefreshRate = 60.0f;
1031 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -08001032 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001033 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -07001034 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001035 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1036 &ignored));
Ady Abraham34702102020-02-10 14:12:05 -08001037
1038 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1039 lr1.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001040 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -08001041 lr2.vote = LayerVoteType::Heuristic;
1042 lr2.desiredRefreshRate = 90.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001043 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -07001044 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001045 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1046 &ignored));
Ady Abraham34702102020-02-10 14:12:05 -08001047
1048 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1049 lr1.desiredRefreshRate = 30.0f;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001050 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -08001051 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001052 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -07001053 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001054 refreshRateConfigs->getRefreshRateForContentV2(layers, /*touchActive*/ false,
1055 &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001056}
1057
1058TEST_F(RefreshRateConfigsTest, scrollWhileWatching60fps_60_90) {
Ady Abraham6fb599b2020-03-05 13:48:22 -08001059 bool ignored;
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001060 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -07001061 std::make_unique<RefreshRateConfigs>(m60_90Device,
1062 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001063
1064 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
1065 LayerRequirement{.weight = 1.0f}};
1066 auto& lr1 = layers[0];
1067 auto& lr2 = layers[1];
1068
1069 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1070 lr1.desiredRefreshRate = 60.0f;
1071 lr1.name = "60Hz ExplicitExactOrMultiple";
1072 lr2.vote = LayerVoteType::NoVote;
1073 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -07001074 EXPECT_EQ(mExpected60Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001075 refreshRateConfigs->getRefreshRateForContentV2(layers, false, &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001076
1077 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1078 lr1.desiredRefreshRate = 60.0f;
1079 lr1.name = "60Hz ExplicitExactOrMultiple";
1080 lr2.vote = LayerVoteType::NoVote;
1081 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -07001082 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001083 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001084
1085 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1086 lr1.desiredRefreshRate = 60.0f;
1087 lr1.name = "60Hz ExplicitExactOrMultiple";
1088 lr2.vote = LayerVoteType::Max;
1089 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -07001090 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001091 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001092
1093 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1094 lr1.desiredRefreshRate = 60.0f;
1095 lr1.name = "60Hz ExplicitExactOrMultiple";
1096 lr2.vote = LayerVoteType::Max;
1097 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -07001098 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001099 refreshRateConfigs->getRefreshRateForContentV2(layers, false, &ignored));
Ady Abraham4ccdcb42020-02-11 17:34:34 -08001100
1101 // The other layer starts to provide buffers
1102 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1103 lr1.desiredRefreshRate = 60.0f;
1104 lr1.name = "60Hz ExplicitExactOrMultiple";
1105 lr2.vote = LayerVoteType::Heuristic;
1106 lr2.desiredRefreshRate = 90.0f;
1107 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -07001108 EXPECT_EQ(mExpected90Config,
Ady Abraham6fb599b2020-03-05 13:48:22 -08001109 refreshRateConfigs->getRefreshRateForContentV2(layers, false, &ignored));
1110}
1111
1112TEST_F(RefreshRateConfigsTest, touchConsidered) {
1113 bool touchConsidered;
Ady Abraham6fb599b2020-03-05 13:48:22 -08001114 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -07001115 std::make_unique<RefreshRateConfigs>(m60_90Device,
1116 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001117
1118 refreshRateConfigs->getRefreshRateForContentV2({}, false, &touchConsidered);
1119 EXPECT_EQ(false, touchConsidered);
1120
1121 refreshRateConfigs->getRefreshRateForContentV2({}, true, &touchConsidered);
1122 EXPECT_EQ(true, touchConsidered);
1123
1124 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
1125 LayerRequirement{.weight = 1.0f}};
1126 auto& lr1 = layers[0];
1127 auto& lr2 = layers[1];
1128
1129 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1130 lr1.desiredRefreshRate = 60.0f;
1131 lr1.name = "60Hz ExplicitExactOrMultiple";
1132 lr2.vote = LayerVoteType::Heuristic;
1133 lr2.name = "NoVote";
1134 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &touchConsidered);
1135 EXPECT_EQ(true, touchConsidered);
1136
1137 lr1.vote = LayerVoteType::ExplicitDefault;
1138 lr1.desiredRefreshRate = 60.0f;
1139 lr1.name = "60Hz ExplicitExactOrMultiple";
1140 lr2.vote = LayerVoteType::Heuristic;
1141 lr2.name = "NoVote";
1142 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &touchConsidered);
1143 EXPECT_EQ(false, touchConsidered);
1144
1145 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
1146 lr1.desiredRefreshRate = 60.0f;
1147 lr1.name = "60Hz ExplicitExactOrMultiple";
1148 lr2.vote = LayerVoteType::Heuristic;
1149 lr2.name = "NoVote";
1150 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &touchConsidered);
1151 EXPECT_EQ(true, touchConsidered);
1152
1153 lr1.vote = LayerVoteType::ExplicitDefault;
1154 lr1.desiredRefreshRate = 60.0f;
1155 lr1.name = "60Hz ExplicitExactrMultiple";
1156 lr2.vote = LayerVoteType::Heuristic;
1157 lr2.name = "NoVote";
1158 refreshRateConfigs->getRefreshRateForContentV2(layers, true, &touchConsidered);
1159 EXPECT_EQ(false, touchConsidered);
Ady Abraham34702102020-02-10 14:12:05 -08001160}
1161
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001162TEST_F(RefreshRateConfigsTest, getRefreshRateForContentV2_ExplicitDefault) {
1163 bool ignored;
Ady Abrahamabc27602020-04-08 17:20:29 -07001164 auto refreshRateConfigs =
1165 std::make_unique<RefreshRateConfigs>(m60_90_72_120Device, /*currentConfigId=*/
1166 HWC_CONFIG_ID_60);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001167
1168 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1169 auto& lr = layers[0];
1170
1171 // Prepare a table with the vote and the expected refresh rate
1172 const std::vector<std::pair<float, float>> testCases = {
1173 {130, 120}, {120, 120}, {119, 120}, {110, 120},
1174
1175 {100, 90}, {90, 90}, {89, 90},
1176
1177 {80, 72}, {73, 72}, {72, 72}, {71, 72}, {70, 72},
1178
1179 {65, 60}, {60, 60}, {59, 60}, {58, 60},
1180
1181 {55, 90}, {50, 90}, {45, 90},
1182
1183 {42, 120}, {40, 120}, {39, 120},
1184
1185 {37, 72}, {36, 72}, {35, 72},
1186
1187 {30, 60},
1188 };
1189
1190 for (const auto& test : testCases) {
1191 lr.vote = LayerVoteType::ExplicitDefault;
1192 lr.desiredRefreshRate = test.first;
1193
1194 std::stringstream ss;
1195 ss << "ExplicitDefault " << test.first << " fps";
1196 lr.name = ss.str();
1197
1198 const auto& refreshRate =
1199 refreshRateConfigs->getRefreshRateForContentV2(layers, false, &ignored);
Ady Abrahamabc27602020-04-08 17:20:29 -07001200 EXPECT_FLOAT_EQ(refreshRate.getFps(), test.second)
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001201 << "Expecting " << test.first << "fps => " << test.second << "Hz";
1202 }
Alec Mouri0a1cc962019-03-14 12:33:02 -07001203}
1204
Steven Thomasd4071902020-03-24 16:02:53 -07001205TEST_F(RefreshRateConfigsTest, groupSwitching) {
Steven Thomasd4071902020-03-24 16:02:53 -07001206 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -07001207 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
1208 /*currentConfigId=*/HWC_CONFIG_ID_60);
Steven Thomasd4071902020-03-24 16:02:53 -07001209
1210 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1211 auto& layer = layers[0];
1212 layer.vote = LayerVoteType::ExplicitDefault;
1213 layer.desiredRefreshRate = 90.0f;
1214 layer.name = "90Hz ExplicitDefault";
1215
1216 bool touchConsidered;
1217 ASSERT_EQ(HWC_CONFIG_ID_60,
1218 refreshRateConfigs->getRefreshRateForContentV2(layers, false, &touchConsidered)
Ady Abrahamabc27602020-04-08 17:20:29 -07001219 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001220
1221 RefreshRateConfigs::Policy policy;
1222 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1223 policy.allowGroupSwitching = true;
1224 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1225 ASSERT_EQ(HWC_CONFIG_ID_90,
1226 refreshRateConfigs->getRefreshRateForContentV2(layers, false, &touchConsidered)
Ady Abrahamabc27602020-04-08 17:20:29 -07001227 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001228}
1229
Alec Mouri0a1cc962019-03-14 12:33:02 -07001230} // namespace
1231} // namespace scheduler
1232} // namespace android