blob: 081396833444ea624c386a39c76b6da43db32506 [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
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wextra"
20
Alec Mouri0a1cc962019-03-14 12:33:02 -070021#undef LOG_TAG
22#define LOG_TAG "SchedulerUnittests"
23
24#include <gmock/gmock.h>
25#include <log/log.h>
26#include <thread>
27
Ady Abraham6fb599b2020-03-05 13:48:22 -080028#include "../../Scheduler/RefreshRateConfigs.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070029#include "DisplayHardware/HWC2.h"
30#include "Scheduler/RefreshRateConfigs.h"
Ady Abrahamabc27602020-04-08 17:20:29 -070031#include "mock/DisplayHardware/MockDisplay.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070032
33using namespace std::chrono_literals;
34using testing::_;
35
36namespace android {
Marin Shalamanove8a663d2020-11-24 17:48:00 +010037
Alec Mouri0a1cc962019-03-14 12:33:02 -070038namespace scheduler {
39
Peiyong Line9d809e2020-04-14 13:10:48 -070040namespace hal = android::hardware::graphics::composer::hal;
41
Alec Mouri0a1cc962019-03-14 12:33:02 -070042using RefreshRate = RefreshRateConfigs::RefreshRate;
Ady Abraham8a82ba62020-01-17 12:43:17 -080043using LayerVoteType = RefreshRateConfigs::LayerVoteType;
44using LayerRequirement = RefreshRateConfigs::LayerRequirement;
Alec Mouri0a1cc962019-03-14 12:33:02 -070045
46class RefreshRateConfigsTest : public testing::Test {
47protected:
Alec Mouri0a1cc962019-03-14 12:33:02 -070048 RefreshRateConfigsTest();
49 ~RefreshRateConfigsTest();
Ady Abrahamabc27602020-04-08 17:20:29 -070050
Marin Shalamanove8a663d2020-11-24 17:48:00 +010051 Fps findClosestKnownFrameRate(const RefreshRateConfigs& refreshRateConfigs, Fps frameRate) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -070052 return refreshRateConfigs.findClosestKnownFrameRate(frameRate);
53 }
54
Marin Shalamanove8a663d2020-11-24 17:48:00 +010055 std::vector<Fps> getKnownFrameRate(const RefreshRateConfigs& refreshRateConfigs) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -070056 return refreshRateConfigs.mKnownFrameRates;
57 }
58
Marin Shalamanoveadf2e72020-12-10 15:35:28 +010059 RefreshRate getMinRefreshRateByPolicy(const RefreshRateConfigs& refreshRateConfigs) {
60 std::lock_guard lock(refreshRateConfigs.mLock);
61 return refreshRateConfigs.getMinRefreshRateByPolicyLocked();
62 }
63
64 RefreshRate getMinSupportedRefreshRate(const RefreshRateConfigs& refreshRateConfigs) {
65 std::lock_guard lock(refreshRateConfigs.mLock);
66 return *refreshRateConfigs.mMinSupportedRefreshRate;
67 }
68
69 RefreshRate getMaxSupportedRefreshRate(const RefreshRateConfigs& refreshRateConfigs) {
70 std::lock_guard lock(refreshRateConfigs.mLock);
71 return *refreshRateConfigs.mMaxSupportedRefreshRate;
72 }
73
Ady Abrahamabc27602020-04-08 17:20:29 -070074 // Test config IDs
75 static inline const HwcConfigIndexType HWC_CONFIG_ID_60 = HwcConfigIndexType(0);
76 static inline const HwcConfigIndexType HWC_CONFIG_ID_90 = HwcConfigIndexType(1);
77 static inline const HwcConfigIndexType HWC_CONFIG_ID_72 = HwcConfigIndexType(2);
78 static inline const HwcConfigIndexType HWC_CONFIG_ID_120 = HwcConfigIndexType(3);
79 static inline const HwcConfigIndexType HWC_CONFIG_ID_30 = HwcConfigIndexType(4);
Marin Shalamanov46084422020-10-13 12:33:42 +020080 static inline const HwcConfigIndexType HWC_CONFIG_ID_25 = HwcConfigIndexType(5);
81 static inline const HwcConfigIndexType HWC_CONFIG_ID_50 = HwcConfigIndexType(6);
Ady Abrahamabc27602020-04-08 17:20:29 -070082
83 // Test configs
84 std::shared_ptr<const HWC2::Display::Config> mConfig60 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010085 createConfig(HWC_CONFIG_ID_60, 0, Fps(60.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070086 std::shared_ptr<const HWC2::Display::Config> mConfig90 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010087 createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070088 std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010089 createConfig(HWC_CONFIG_ID_90, 1, Fps(90.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070090 std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentResolution =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010091 createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs(), 111, 222);
Ady Abrahamabc27602020-04-08 17:20:29 -070092 std::shared_ptr<const HWC2::Display::Config> mConfig72 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010093 createConfig(HWC_CONFIG_ID_72, 0, Fps(72.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070094 std::shared_ptr<const HWC2::Display::Config> mConfig72DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010095 createConfig(HWC_CONFIG_ID_72, 1, Fps(72.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070096 std::shared_ptr<const HWC2::Display::Config> mConfig120 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010097 createConfig(HWC_CONFIG_ID_120, 0, Fps(120.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070098 std::shared_ptr<const HWC2::Display::Config> mConfig120DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010099 createConfig(HWC_CONFIG_ID_120, 1, Fps(120.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -0700100 std::shared_ptr<const HWC2::Display::Config> mConfig30 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100101 createConfig(HWC_CONFIG_ID_30, 0, Fps(30.0f).getPeriodNsecs());
Marin Shalamanov46084422020-10-13 12:33:42 +0200102 std::shared_ptr<const HWC2::Display::Config> mConfig30DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100103 createConfig(HWC_CONFIG_ID_30, 1, Fps(30.0f).getPeriodNsecs());
Marin Shalamanov46084422020-10-13 12:33:42 +0200104 std::shared_ptr<const HWC2::Display::Config> mConfig25DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100105 createConfig(HWC_CONFIG_ID_25, 1, Fps(25.0f).getPeriodNsecs());
Marin Shalamanov46084422020-10-13 12:33:42 +0200106 std::shared_ptr<const HWC2::Display::Config> mConfig50 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100107 createConfig(HWC_CONFIG_ID_50, 0, Fps(50.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -0700108
109 // Test device configurations
Marin Shalamanov46084422020-10-13 12:33:42 +0200110 // The positions of the configs in the arrays below MUST match their IDs. For example,
111 // the first config should always be 60Hz, the second 90Hz etc.
Ady Abrahamabc27602020-04-08 17:20:29 -0700112 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60OnlyConfigDevice = {mConfig60};
113 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90Device = {mConfig60, mConfig90};
114 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentGroups =
115 {mConfig60, mConfig90DifferentGroup};
116 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentResolutions =
117 {mConfig60, mConfig90DifferentResolution};
118 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_72_90Device = {mConfig60,
119 mConfig90,
120 mConfig72};
121 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90_72_120Device = {mConfig60,
122 mConfig90,
123 mConfig72,
124 mConfig120};
125 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90_120Device = {mConfig60,
126 mConfig90,
127 mConfig72,
128 mConfig120,
129 mConfig30};
130 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60Device =
131 {mConfig60, mConfig90DifferentGroup, mConfig72DifferentGroup, mConfig120DifferentGroup,
132 mConfig30};
133 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90Device =
134 {mConfig60, mConfig90, mConfig72, mConfig120DifferentGroup, mConfig30};
135 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_90Device =
136 {mConfig60, mConfig90, mConfig72DifferentGroup, mConfig120DifferentGroup, mConfig30};
Marin Shalamanov46084422020-10-13 12:33:42 +0200137 std::vector<std::shared_ptr<const HWC2::Display::Config>> m25_30_50_60Device =
138 {mConfig60,
139 mConfig90,
140 mConfig72DifferentGroup,
141 mConfig120DifferentGroup,
142 mConfig30DifferentGroup,
143 mConfig25DifferentGroup,
144 mConfig50};
Ady Abrahamabc27602020-04-08 17:20:29 -0700145
146 // Expected RefreshRate objects
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100147 RefreshRate mExpected60Config = {HWC_CONFIG_ID_60, mConfig60, Fps(60),
Ady Abrahamabc27602020-04-08 17:20:29 -0700148 RefreshRate::ConstructorTag(0)};
149 RefreshRate mExpectedAlmost60Config = {HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100150 createConfig(HWC_CONFIG_ID_60, 0, 16666665), Fps(60),
Ady Abrahamabc27602020-04-08 17:20:29 -0700151 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100152 RefreshRate mExpected90Config = {HWC_CONFIG_ID_90, mConfig90, Fps(90),
Ady Abrahamabc27602020-04-08 17:20:29 -0700153 RefreshRate::ConstructorTag(0)};
154 RefreshRate mExpected90DifferentGroupConfig = {HWC_CONFIG_ID_90, mConfig90DifferentGroup,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100155 Fps(90), RefreshRate::ConstructorTag(0)};
Ady Abrahamabc27602020-04-08 17:20:29 -0700156 RefreshRate mExpected90DifferentResolutionConfig = {HWC_CONFIG_ID_90,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100157 mConfig90DifferentResolution, Fps(90),
Ady Abrahamabc27602020-04-08 17:20:29 -0700158 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100159 RefreshRate mExpected72Config = {HWC_CONFIG_ID_72, mConfig72, Fps(72.0f),
Ady Abrahamabc27602020-04-08 17:20:29 -0700160 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100161 RefreshRate mExpected30Config = {HWC_CONFIG_ID_30, mConfig30, Fps(30),
Ady Abrahamabc27602020-04-08 17:20:29 -0700162 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100163 RefreshRate mExpected120Config = {HWC_CONFIG_ID_120, mConfig120, Fps(120),
Ady Abrahamabc27602020-04-08 17:20:29 -0700164 RefreshRate::ConstructorTag(0)};
165
166 Hwc2::mock::Display mDisplay;
167
168private:
169 std::shared_ptr<const HWC2::Display::Config> createConfig(HwcConfigIndexType configId,
170 int32_t configGroup,
171 int64_t vsyncPeriod,
172 int32_t hight = -1,
173 int32_t width = -1);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700174};
175
Ady Abrahamabc27602020-04-08 17:20:29 -0700176using Builder = HWC2::Display::Config::Builder;
177
Alec Mouri0a1cc962019-03-14 12:33:02 -0700178RefreshRateConfigsTest::RefreshRateConfigsTest() {
179 const ::testing::TestInfo* const test_info =
180 ::testing::UnitTest::GetInstance()->current_test_info();
181 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
182}
183
184RefreshRateConfigsTest::~RefreshRateConfigsTest() {
185 const ::testing::TestInfo* const test_info =
186 ::testing::UnitTest::GetInstance()->current_test_info();
187 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
188}
189
Ady Abrahamabc27602020-04-08 17:20:29 -0700190std::shared_ptr<const HWC2::Display::Config> RefreshRateConfigsTest::createConfig(
191 HwcConfigIndexType configId, int32_t configGroup, int64_t vsyncPeriod, int32_t hight,
192 int32_t width) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700193 return HWC2::Display::Config::Builder(mDisplay, hal::HWConfigId(configId.value()))
Ady Abrahamabc27602020-04-08 17:20:29 -0700194 .setVsyncPeriod(int32_t(vsyncPeriod))
195 .setConfigGroup(configGroup)
196 .setHeight(hight)
197 .setWidth(width)
198 .build();
199}
200
Alec Mouri0a1cc962019-03-14 12:33:02 -0700201namespace {
202/* ------------------------------------------------------------------------
203 * Test cases
204 */
Ady Abraham2139f732019-11-13 18:56:40 -0800205TEST_F(RefreshRateConfigsTest, oneDeviceConfig_SwitchingSupported) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700206 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700207 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
208 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700209}
210
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100211TEST_F(RefreshRateConfigsTest, invalidPolicy) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100212 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700213 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
214 /*currentConfigId=*/HWC_CONFIG_ID_60);
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100215 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy(
216 {HwcConfigIndexType(10), {Fps(60), Fps(60)}}),
217 0);
218 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(20), Fps(40)}}),
219 0);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100220}
221
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700222TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700223 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700224 std::make_unique<RefreshRateConfigs>(m60_90Device,
225 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700226
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100227 const auto& minRate = getMinSupportedRefreshRate(*refreshRateConfigs);
228 const auto& performanceRate = getMaxSupportedRefreshRate(*refreshRateConfigs);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700229
Ady Abrahamabc27602020-04-08 17:20:29 -0700230 ASSERT_EQ(mExpected60Config, minRate);
231 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800232
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100233 const auto& minRateByPolicy = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800234 const auto& performanceRateByPolicy = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800235 ASSERT_EQ(minRateByPolicy, minRate);
236 ASSERT_EQ(performanceRateByPolicy, performanceRate);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700237}
Ady Abraham2139f732019-11-13 18:56:40 -0800238
239TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentGroups) {
Ady Abraham2139f732019-11-13 18:56:40 -0800240 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700241 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
242 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800243
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100244 const auto& minRate = getMinRefreshRateByPolicy(*refreshRateConfigs);
245 const auto& performanceRate = getMaxSupportedRefreshRate(*refreshRateConfigs);
246 const auto& minRate60 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800247 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800248
Ady Abrahamabc27602020-04-08 17:20:29 -0700249 ASSERT_EQ(mExpected60Config, minRate);
250 ASSERT_EQ(mExpected60Config, minRate60);
251 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800252
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100253 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
254 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800255 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
256
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100257 const auto& minRate90 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800258 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800259
Ady Abrahamabc27602020-04-08 17:20:29 -0700260 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate);
261 ASSERT_EQ(mExpected90DifferentGroupConfig, minRate90);
262 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate90);
263}
264
265TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentResolutions) {
266 auto refreshRateConfigs =
267 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentResolutions,
268 /*currentConfigId=*/HWC_CONFIG_ID_60);
269
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100270 const auto& minRate = getMinRefreshRateByPolicy(*refreshRateConfigs);
271 const auto& performanceRate = getMaxSupportedRefreshRate(*refreshRateConfigs);
272 const auto& minRate60 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abrahamabc27602020-04-08 17:20:29 -0700273 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
274
275 ASSERT_EQ(mExpected60Config, minRate);
276 ASSERT_EQ(mExpected60Config, minRate60);
277 ASSERT_EQ(mExpected60Config, performanceRate60);
278
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100279 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
280 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700281 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
282
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100283 const auto& minRate90 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abrahamabc27602020-04-08 17:20:29 -0700284 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
285
286 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate);
287 ASSERT_EQ(mExpected90DifferentResolutionConfig, minRate90);
288 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate90);
Ady Abraham2139f732019-11-13 18:56:40 -0800289}
290
291TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_policyChange) {
Ady Abraham2139f732019-11-13 18:56:40 -0800292 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700293 std::make_unique<RefreshRateConfigs>(m60_90Device,
294 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ana Krulec3f6a2062020-01-23 15:48:01 -0800295
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100296 auto minRate = getMinRefreshRateByPolicy(*refreshRateConfigs);
297 auto performanceRate = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800298
Ady Abrahamabc27602020-04-08 17:20:29 -0700299 ASSERT_EQ(mExpected60Config, minRate);
300 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800301
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100302 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
303 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800304
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100305 auto minRate60 = getMinRefreshRateByPolicy(*refreshRateConfigs);
306 auto performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abrahamabc27602020-04-08 17:20:29 -0700307 ASSERT_EQ(mExpected60Config, minRate60);
308 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800309}
310
311TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getCurrentRefreshRate) {
Ady Abraham2139f732019-11-13 18:56:40 -0800312 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700313 std::make_unique<RefreshRateConfigs>(m60_90Device,
314 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800315 {
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100316 auto current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700317 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800318 }
319
320 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
321 {
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100322 auto current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700323 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800324 }
325
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100326 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
327 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800328 {
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100329 auto current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700330 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800331 }
332}
333
Steven Thomasbb374322020-04-28 22:47:16 -0700334TEST_F(RefreshRateConfigsTest, getBestRefreshRate_noLayers) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700335 auto refreshRateConfigs =
336 std::make_unique<RefreshRateConfigs>(m60_72_90Device, /*currentConfigId=*/
337 HWC_CONFIG_ID_72);
Ana Krulec3d367c82020-02-25 15:02:01 -0800338
Steven Thomasdebafed2020-05-18 17:30:35 -0700339 // If there are no layers we select the default frame rate, which is the max of the primary
340 // range.
Ana Krulec3d367c82020-02-25 15:02:01 -0800341 auto layers = std::vector<LayerRequirement>{};
Steven Thomasdebafed2020-05-18 17:30:35 -0700342 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700343 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800344
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100345 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
346 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700347 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700348 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800349}
350
Steven Thomasbb374322020-04-28 22:47:16 -0700351TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800352 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700353 std::make_unique<RefreshRateConfigs>(m60_90Device,
354 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800355
356 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
357 auto& lr = layers[0];
358
359 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800360 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700361 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700362 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800363
364 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800365 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700366 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700367 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800368
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100369 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800370 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800371 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700372 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700373 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800374
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100375 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800376 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700377 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700378 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800379
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100380 lr.desiredRefreshRate = Fps(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800381 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700382 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700383 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800384
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100385 lr.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800386 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700387 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700388 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800389
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100390 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800391 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700392 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700393 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800394
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800395 lr.name = "";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100396 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
397 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800398
399 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700400 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700401 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800402
403 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700404 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700405 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800406
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100407 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800408 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700409 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700410 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800411
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100412 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700413 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700414 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800415
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100416 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700417 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700418 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800419
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100420 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700421 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700422 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800423
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100424 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700425 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700426 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800427
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100428 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
429 {HWC_CONFIG_ID_90, {Fps(90.0f), Fps(90.0f)}}),
430 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800431
432 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700433 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700434 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800435
436 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700437 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700438 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800439
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100440 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800441 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700442 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700443 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800444
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100445 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700446 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700447 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800448
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100449 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700450 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700451 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800452
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100453 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700454 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700455 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800456
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100457 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700458 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700459 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800460
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100461 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
462 {HWC_CONFIG_ID_60, {Fps(0.0f), Fps(120.0f)}}),
463 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800464 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700465 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700466 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800467
468 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700469 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700470 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800471
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100472 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800473 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700474 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700475 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800476
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100477 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700478 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700479 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800480
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100481 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700482 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700483 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800484
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100485 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700486 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700487 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800488
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100489 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700490 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700491 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800492}
493
Steven Thomasbb374322020-04-28 22:47:16 -0700494TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800495 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700496 std::make_unique<RefreshRateConfigs>(m60_72_90Device,
497 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800498
499 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
500 auto& lr = layers[0];
501
502 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700503 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700504 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800505
506 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700507 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700508 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800509
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100510 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800511 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700512 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700513 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800514
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100515 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700516 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700517 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800518
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100519 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700520 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700521 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800522
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100523 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700524 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700525 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800526
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100527 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700528 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700529 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800530}
531
Steven Thomasbb374322020-04-28 22:47:16 -0700532TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90_120) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800533 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700534 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
535 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800536
537 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
538 LayerRequirement{.weight = 1.0f}};
539 auto& lr1 = layers[0];
540 auto& lr2 = layers[1];
541
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100542 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800543 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100544 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800545 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700546 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700547 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800548
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100549 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800550 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100551 lr2.desiredRefreshRate = Fps(48.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800552 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700553 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700554 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800555
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100556 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800557 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100558 lr2.desiredRefreshRate = Fps(48.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800559 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700560 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700561 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800562}
563
Steven Thomasbb374322020-04-28 22:47:16 -0700564TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_90_120_DifferentTypes) {
Ady Abraham71c437d2020-01-31 15:56:57 -0800565 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700566 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
567 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham71c437d2020-01-31 15:56:57 -0800568
569 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
570 LayerRequirement{.weight = 1.0f}};
571 auto& lr1 = layers[0];
572 auto& lr2 = layers[1];
573
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100574 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800575 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800576 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100577 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800578 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800579 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700580 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700581 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800582
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100583 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800584 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800585 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100586 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800587 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800588 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700589 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700590 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800591
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100592 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800593 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800594 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100595 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800596 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800597 lr2.name = "60Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700598 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700599 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800600
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100601 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800602 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800603 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100604 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800605 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800606 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700607 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700608 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800609
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100610 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800611 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
612 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100613 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800614 lr2.vote = LayerVoteType::ExplicitDefault;
615 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700616 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700617 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800618
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100619 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800620 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800621 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100622 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800623 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800624 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700625 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700626 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800627
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100628 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800629 lr1.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800630 lr1.name = "24Hz Heuristic";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100631 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800632 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800633 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700634 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700635 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800636
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100637 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800638 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800639 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100640 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800641 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800642 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700643 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700644 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800645
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100646 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800647 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800648 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100649 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800650 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800651 lr2.name = "90Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700652 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700653 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800654}
655
Steven Thomasbb374322020-04-28 22:47:16 -0700656TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800657 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700658 std::make_unique<RefreshRateConfigs>(m30_60Device,
659 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800660
661 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
662 auto& lr = layers[0];
663
664 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700665 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700666 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800667
668 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700669 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700670 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800671
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100672 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800673 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700674 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700675 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800676
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100677 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700678 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700679 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800680
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100681 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700682 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700683 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800684
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100685 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700686 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700687 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800688
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100689 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700690 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700691 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800692}
693
Steven Thomasbb374322020-04-28 22:47:16 -0700694TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800695 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700696 std::make_unique<RefreshRateConfigs>(m30_60_72_90Device,
697 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800698
699 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
700 auto& lr = layers[0];
701
702 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800703 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700704 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700705 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800706
707 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800708 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700709 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700710 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800711
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100712 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800713 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800714 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700715 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700716 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800717
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100718 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800719 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700720 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700721 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700722 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700723 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800724
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100725 lr.desiredRefreshRate = Fps(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800726 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700727 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700728 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700729 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700730 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800731
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100732 lr.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800733 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700734 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700735 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700736 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700737 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800738
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100739 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800740 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700741 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700742 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700743 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700744 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800745
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100746 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800747 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
748 lr.name = "24Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700749 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700750 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700751 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700752 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800753}
754
Steven Thomasbb374322020-04-28 22:47:16 -0700755TEST_F(RefreshRateConfigsTest, getBestRefreshRate_PriorityTest) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800756 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700757 std::make_unique<RefreshRateConfigs>(m30_60_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 LayerRequirement{.weight = 1.0f}};
762 auto& lr1 = layers[0];
763 auto& lr2 = layers[1];
764
765 lr1.vote = LayerVoteType::Min;
766 lr2.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700767 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700768 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800769
770 lr1.vote = LayerVoteType::Min;
771 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100772 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700773 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700774 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800775
776 lr1.vote = LayerVoteType::Min;
Ady Abraham71c437d2020-01-31 15:56:57 -0800777 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100778 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700779 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700780 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800781
782 lr1.vote = LayerVoteType::Max;
783 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100784 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700785 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700786 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800787
788 lr1.vote = LayerVoteType::Max;
Ady Abraham71c437d2020-01-31 15:56:57 -0800789 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100790 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700791 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700792 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800793
794 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100795 lr1.desiredRefreshRate = Fps(15.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800796 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100797 lr2.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700798 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700799 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800800
801 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100802 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800803 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100804 lr2.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700805 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700806 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800807}
808
Steven Thomasbb374322020-04-28 22:47:16 -0700809TEST_F(RefreshRateConfigsTest, getBestRefreshRate_24FpsVideo) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800810 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700811 std::make_unique<RefreshRateConfigs>(m60_90Device,
812 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800813
814 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
815 auto& lr = layers[0];
816
Ady Abraham71c437d2020-01-31 15:56:57 -0800817 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800818 for (float fps = 23.0f; fps < 25.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100819 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800820 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700821 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700822 EXPECT_EQ(mExpected60Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abraham8a82ba62020-01-17 12:43:17 -0800823 }
824}
825
Steven Thomasbb374322020-04-28 22:47:16 -0700826TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getBestRefreshRate_Explicit) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800827 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700828 std::make_unique<RefreshRateConfigs>(m60_90Device,
829 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800830
831 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
832 LayerRequirement{.weight = 1.0f}};
833 auto& lr1 = layers[0];
834 auto& lr2 = layers[1];
835
836 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100837 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800838 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100839 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700840 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700841 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800842
843 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100844 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800845 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100846 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700847 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700848 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800849
850 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100851 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800852 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100853 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700854 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700855 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham2139f732019-11-13 18:56:40 -0800856}
857
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800858TEST_F(RefreshRateConfigsTest, testInPolicy) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100859 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(60.000004f), Fps(60.000004f)));
860 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(59.0f), Fps(60.1f)));
861 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(75.0f), Fps(90.0f)));
862 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(60.0011f), Fps(90.0f)));
863 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(50.0f), Fps(59.998f)));
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800864}
865
Steven Thomasbb374322020-04-28 22:47:16 -0700866TEST_F(RefreshRateConfigsTest, getBestRefreshRate_75HzContent) {
Ady Abrahamf6b77072020-01-30 14:22:54 -0800867 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700868 std::make_unique<RefreshRateConfigs>(m60_90Device,
869 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abrahamf6b77072020-01-30 14:22:54 -0800870
871 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
872 auto& lr = layers[0];
873
Ady Abraham71c437d2020-01-31 15:56:57 -0800874 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abrahamf6b77072020-01-30 14:22:54 -0800875 for (float fps = 75.0f; fps < 100.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100876 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800877 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700878 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700879 EXPECT_EQ(mExpected90Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abrahamf6b77072020-01-30 14:22:54 -0800880 }
881}
882
Steven Thomasbb374322020-04-28 22:47:16 -0700883TEST_F(RefreshRateConfigsTest, getBestRefreshRate_Multiples) {
Ady Abraham34702102020-02-10 14:12:05 -0800884 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700885 std::make_unique<RefreshRateConfigs>(m60_90Device,
886 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham34702102020-02-10 14:12:05 -0800887
888 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
889 LayerRequirement{.weight = 1.0f}};
890 auto& lr1 = layers[0];
891 auto& lr2 = layers[1];
892
893 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100894 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800895 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800896 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100897 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800898 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700899 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700900 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800901
902 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100903 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800904 lr1.name = "60Hz ExplicitExactOrMultiple";
905 lr2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100906 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800907 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700908 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700909 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800910
911 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100912 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800913 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800914 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800915 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700916 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700917 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800918
919 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100920 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800921 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800922 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100923 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800924 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700925 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700926 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800927
928 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100929 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800930 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800931 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800932 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700933 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700934 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800935}
936
937TEST_F(RefreshRateConfigsTest, scrollWhileWatching60fps_60_90) {
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800938 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700939 std::make_unique<RefreshRateConfigs>(m60_90Device,
940 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800941
942 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
943 LayerRequirement{.weight = 1.0f}};
944 auto& lr1 = layers[0];
945 auto& lr2 = layers[1];
946
947 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100948 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800949 lr1.name = "60Hz ExplicitExactOrMultiple";
950 lr2.vote = LayerVoteType::NoVote;
951 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700952 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700953 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800954
955 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100956 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800957 lr1.name = "60Hz ExplicitExactOrMultiple";
958 lr2.vote = LayerVoteType::NoVote;
959 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700960 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700961 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800962
963 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100964 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800965 lr1.name = "60Hz ExplicitExactOrMultiple";
966 lr2.vote = LayerVoteType::Max;
967 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700968 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700969 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800970
971 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100972 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800973 lr1.name = "60Hz ExplicitExactOrMultiple";
974 lr2.vote = LayerVoteType::Max;
975 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700976 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700977 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800978
979 // The other layer starts to provide buffers
980 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100981 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800982 lr1.name = "60Hz ExplicitExactOrMultiple";
983 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100984 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800985 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700986 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700987 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham6fb599b2020-03-05 13:48:22 -0800988}
989
990TEST_F(RefreshRateConfigsTest, touchConsidered) {
Ady Abrahamdfd62162020-06-10 16:11:56 -0700991 RefreshRateConfigs::GlobalSignals consideredSignals;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800992 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700993 std::make_unique<RefreshRateConfigs>(m60_90Device,
994 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800995
Ady Abrahamdfd62162020-06-10 16:11:56 -0700996 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false}, &consideredSignals);
997 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800998
Ady Abrahamdfd62162020-06-10 16:11:56 -0700999 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = false}, &consideredSignals);
1000 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001001
1002 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
1003 LayerRequirement{.weight = 1.0f}};
1004 auto& lr1 = layers[0];
1005 auto& lr2 = layers[1];
1006
1007 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001008 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001009 lr1.name = "60Hz ExplicitExactOrMultiple";
1010 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001011 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001012 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001013 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1014 &consideredSignals);
1015 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001016
1017 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001018 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001019 lr1.name = "60Hz ExplicitExactOrMultiple";
1020 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001021 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001022 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001023 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1024 &consideredSignals);
1025 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001026
1027 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001028 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001029 lr1.name = "60Hz ExplicitExactOrMultiple";
1030 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001031 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001032 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001033 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1034 &consideredSignals);
1035 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001036
1037 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001038 lr1.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001039 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001040 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001041 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001042 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001043 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1044 &consideredSignals);
1045 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham34702102020-02-10 14:12:05 -08001046}
1047
Steven Thomasbb374322020-04-28 22:47:16 -07001048TEST_F(RefreshRateConfigsTest, getBestRefreshRate_ExplicitDefault) {
Ady Abrahamabc27602020-04-08 17:20:29 -07001049 auto refreshRateConfigs =
1050 std::make_unique<RefreshRateConfigs>(m60_90_72_120Device, /*currentConfigId=*/
1051 HWC_CONFIG_ID_60);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001052
1053 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1054 auto& lr = layers[0];
1055
1056 // Prepare a table with the vote and the expected refresh rate
1057 const std::vector<std::pair<float, float>> testCases = {
1058 {130, 120}, {120, 120}, {119, 120}, {110, 120},
1059
1060 {100, 90}, {90, 90}, {89, 90},
1061
1062 {80, 72}, {73, 72}, {72, 72}, {71, 72}, {70, 72},
1063
1064 {65, 60}, {60, 60}, {59, 60}, {58, 60},
1065
1066 {55, 90}, {50, 90}, {45, 90},
1067
1068 {42, 120}, {40, 120}, {39, 120},
1069
1070 {37, 72}, {36, 72}, {35, 72},
1071
1072 {30, 60},
1073 };
1074
1075 for (const auto& test : testCases) {
1076 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001077 lr.desiredRefreshRate = Fps(test.first);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001078
1079 std::stringstream ss;
1080 ss << "ExplicitDefault " << test.first << " fps";
1081 lr.name = ss.str();
1082
1083 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -07001084 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001085 EXPECT_TRUE(refreshRate.getFps().equalsWithMargin(Fps(test.second)))
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001086 << "Expecting " << test.first << "fps => " << test.second << "Hz";
1087 }
Alec Mouri0a1cc962019-03-14 12:33:02 -07001088}
1089
Alec Mouri11232a22020-05-14 18:06:25 -07001090TEST_F(RefreshRateConfigsTest,
1091 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresTouchFlag) {
1092 auto refreshRateConfigs =
1093 std::make_unique<RefreshRateConfigs>(m60_90Device,
1094 /*currentConfigId=*/HWC_CONFIG_ID_90);
1095
1096 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001097 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001098 0);
1099
1100 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1101 auto& lr = layers[0];
1102
Ady Abrahamdfd62162020-06-10 16:11:56 -07001103 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001104 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001105 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001106 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001107 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001108 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001109 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = true},
1110 &consideredSignals));
1111 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001112}
1113
1114TEST_F(RefreshRateConfigsTest,
1115 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresIdleFlag) {
1116 auto refreshRateConfigs =
1117 std::make_unique<RefreshRateConfigs>(m60_90Device,
1118 /*currentConfigId=*/HWC_CONFIG_ID_60);
1119
1120 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001121 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001122 0);
1123
1124 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1125 auto& lr = layers[0];
1126
Alec Mouri11232a22020-05-14 18:06:25 -07001127 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001128 lr.desiredRefreshRate = Fps(90.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001129 lr.name = "90Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001130 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001131 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001132 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = true}));
Alec Mouri11232a22020-05-14 18:06:25 -07001133}
1134
1135TEST_F(RefreshRateConfigsTest,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001136 getBestRefreshRate_withDisplayManagerRequestingSingleRate_onlySwitchesRatesForExplicitFocusedLayers) {
Alec Mouri11232a22020-05-14 18:06:25 -07001137 auto refreshRateConfigs =
1138 std::make_unique<RefreshRateConfigs>(m60_90Device,
1139 /*currentConfigId=*/HWC_CONFIG_ID_90);
1140
1141 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001142 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001143 0);
1144
Ady Abrahamdfd62162020-06-10 16:11:56 -07001145 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001146 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001147 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false},
1148 &consideredSignals));
1149 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001150
1151 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1152 auto& lr = layers[0];
1153
1154 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001155 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001156 lr.name = "60Hz ExplicitExactOrMultiple";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001157 lr.focused = false;
1158 EXPECT_EQ(mExpected90Config,
1159 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1160
1161 lr.focused = true;
Ady Abraham20c029c2020-07-06 12:58:05 -07001162 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001163 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001164
1165 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001166 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001167 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001168 lr.focused = false;
1169 EXPECT_EQ(mExpected90Config,
1170 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1171
1172 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001173 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001174 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001175
1176 lr.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001177 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001178 lr.name = "60Hz Heuristic";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001179 lr.focused = false;
1180 EXPECT_EQ(mExpected90Config,
1181 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1182
1183 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001184 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001185 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001186
1187 lr.vote = LayerVoteType::Max;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001188 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001189 lr.name = "60Hz Max";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001190 lr.focused = false;
1191 EXPECT_EQ(mExpected90Config,
1192 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1193
1194 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001195 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001196 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001197
1198 lr.vote = LayerVoteType::Min;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001199 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001200 lr.name = "60Hz Min";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001201 lr.focused = false;
1202 EXPECT_EQ(mExpected90Config,
1203 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1204
1205 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001206 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001207 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001208}
1209
Steven Thomasd4071902020-03-24 16:02:53 -07001210TEST_F(RefreshRateConfigsTest, groupSwitching) {
Steven Thomasd4071902020-03-24 16:02:53 -07001211 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -07001212 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
1213 /*currentConfigId=*/HWC_CONFIG_ID_60);
Steven Thomasd4071902020-03-24 16:02:53 -07001214
1215 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1216 auto& layer = layers[0];
1217 layer.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001218 layer.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001219 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Steven Thomasd4071902020-03-24 16:02:53 -07001220 layer.name = "90Hz ExplicitDefault";
Marin Shalamanov46084422020-10-13 12:33:42 +02001221 layer.focused = true;
Steven Thomasd4071902020-03-24 16:02:53 -07001222
Steven Thomasd4071902020-03-24 16:02:53 -07001223 ASSERT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001224 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001225 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001226
1227 RefreshRateConfigs::Policy policy;
1228 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1229 policy.allowGroupSwitching = true;
1230 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1231 ASSERT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001232 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001233 .getConfigId());
Marin Shalamanov46084422020-10-13 12:33:42 +02001234
1235 // Verify that we won't change the group if seamless switch is required.
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001236 layer.seamlessness = Seamlessness::OnlySeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001237 ASSERT_EQ(HWC_CONFIG_ID_60,
1238 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1239 .getConfigId());
1240
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001241 // Verify that we won't do a seamless switch if we request the same mode as the default
Marin Shalamanov46084422020-10-13 12:33:42 +02001242 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001243 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001244 layer.name = "60Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001245 layer.seamlessness = Seamlessness::OnlySeamless;
1246 ASSERT_EQ(HWC_CONFIG_ID_90,
1247 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1248 .getConfigId());
1249
1250 // Verify that if the current config is in another group and there are no layers with
1251 // seamlessness=SeamedAndSeamless we'll go back to the default group.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001252 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001253 layer.name = "60Hz ExplicitDefault";
1254 layer.seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001255 ASSERT_EQ(HWC_CONFIG_ID_60,
1256 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1257 .getConfigId());
1258
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001259 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1260 // seamlessness=OnlySeamless can't change the config group.
Marin Shalamanov46084422020-10-13 12:33:42 +02001261 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001262 layer.seamlessness = Seamlessness::OnlySeamless;
1263
1264 layers.push_back(LayerRequirement{.weight = 0.5f});
1265 auto& layer2 = layers[layers.size() - 1];
Marin Shalamanov46084422020-10-13 12:33:42 +02001266 layer2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001267 layer2.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001268 layer2.name = "90Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001269 layer2.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001270 layer2.focused = false;
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001271
1272 ASSERT_EQ(HWC_CONFIG_ID_90,
1273 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1274 .getConfigId());
1275
1276 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1277 // seamlessness=Default can't change the config group.
1278 layers[0].seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001279 ASSERT_EQ(HWC_CONFIG_ID_90,
1280 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1281 .getConfigId());
1282}
1283
1284TEST_F(RefreshRateConfigsTest, nonSeamlessVotePrefersSeamlessSwitches) {
1285 auto refreshRateConfigs =
1286 std::make_unique<RefreshRateConfigs>(m30_60Device,
1287 /*currentConfigId=*/HWC_CONFIG_ID_60);
1288
1289 // Allow group switching.
1290 RefreshRateConfigs::Policy policy;
1291 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1292 policy.allowGroupSwitching = true;
1293 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1294
1295 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1296 auto& layer = layers[0];
1297 layer.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001298 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001299 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001300 layer.name = "60Hz ExplicitExactOrMultiple";
1301 layer.focused = true;
1302
1303 ASSERT_EQ(HWC_CONFIG_ID_60,
1304 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1305 .getConfigId());
1306
1307 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
1308 ASSERT_EQ(HWC_CONFIG_ID_120,
1309 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1310 .getConfigId());
1311}
1312
1313TEST_F(RefreshRateConfigsTest, nonSeamlessExactAndSeamlessMultipleLayers) {
1314 auto refreshRateConfigs =
1315 std::make_unique<RefreshRateConfigs>(m25_30_50_60Device,
1316 /*currentConfigId=*/HWC_CONFIG_ID_60);
1317
1318 // Allow group switching.
1319 RefreshRateConfigs::Policy policy;
1320 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1321 policy.allowGroupSwitching = true;
1322 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1323
1324 auto layers = std::vector<
1325 LayerRequirement>{LayerRequirement{.name = "60Hz ExplicitDefault",
1326 .vote = LayerVoteType::ExplicitDefault,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001327 .desiredRefreshRate = Fps(60.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001328 .seamlessness = Seamlessness::SeamedAndSeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001329 .weight = 0.5f,
1330 .focused = false},
1331 LayerRequirement{.name = "25Hz ExplicitExactOrMultiple",
1332 .vote = LayerVoteType::ExplicitExactOrMultiple,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001333 .desiredRefreshRate = Fps(25.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001334 .seamlessness = Seamlessness::OnlySeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001335 .weight = 1.0f,
1336 .focused = true}};
1337 auto& seamedLayer = layers[0];
1338
1339 ASSERT_EQ(HWC_CONFIG_ID_50,
1340 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1341 .getConfigId());
1342
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001343 seamedLayer.name = "30Hz ExplicitDefault", seamedLayer.desiredRefreshRate = Fps(30.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001344 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_30);
1345
1346 ASSERT_EQ(HWC_CONFIG_ID_25,
1347 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1348 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001349}
1350
Steven Thomasf734df42020-04-13 21:09:28 -07001351TEST_F(RefreshRateConfigsTest, primaryVsAppRequestPolicy) {
1352 auto refreshRateConfigs =
Alec Mouri11232a22020-05-14 18:06:25 -07001353 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
Steven Thomasf734df42020-04-13 21:09:28 -07001354 /*currentConfigId=*/HWC_CONFIG_ID_60);
1355
1356 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1357 layers[0].name = "Test layer";
1358
Steven Thomasbb374322020-04-28 22:47:16 -07001359 // Return the config ID from calling getBestRefreshRate() for a single layer with the
Steven Thomasf734df42020-04-13 21:09:28 -07001360 // given voteType and fps.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001361 auto getFrameRate = [&](LayerVoteType voteType, Fps fps, bool touchActive = false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001362 bool focused = true) -> HwcConfigIndexType {
Steven Thomasf734df42020-04-13 21:09:28 -07001363 layers[0].vote = voteType;
1364 layers[0].desiredRefreshRate = fps;
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001365 layers[0].focused = focused;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001366 return refreshRateConfigs->getBestRefreshRate(layers, {.touch = touchActive, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001367 .getConfigId();
1368 };
1369
1370 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001371 {HWC_CONFIG_ID_60, {Fps(30.f), Fps(60.f)}, {Fps(30.f), Fps(90.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001372 0);
Steven Thomasf734df42020-04-13 21:09:28 -07001373 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001374 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001375 .getConfigId());
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001376 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1377 EXPECT_EQ(HWC_CONFIG_ID_30, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1378 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1379 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1380 EXPECT_EQ(HWC_CONFIG_ID_90, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1381 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001382
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001383 // Layers not focused are not allowed to override primary config
1384 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001385 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001386 /*focused=*/false));
1387 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001388 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001389 /*focused=*/false));
1390
Steven Thomasf734df42020-04-13 21:09:28 -07001391 // Touch boost should be restricted to the primary range.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001392 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001393 // When we're higher than the primary range max due to a layer frame rate setting, touch boost
1394 // shouldn't drag us back down to the primary range max.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001395 EXPECT_EQ(HWC_CONFIG_ID_90,
1396 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/true));
Ady Abraham20c029c2020-07-06 12:58:05 -07001397 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001398 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001399
1400 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001401 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(60.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001402 0);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001403 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1404 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1405 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1406 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1407 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1408 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001409}
1410
Steven Thomasbb374322020-04-28 22:47:16 -07001411TEST_F(RefreshRateConfigsTest, idle) {
1412 auto refreshRateConfigs =
1413 std::make_unique<RefreshRateConfigs>(m60_90Device,
1414 /*currentConfigId=*/HWC_CONFIG_ID_60);
1415
1416 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1417 layers[0].name = "Test layer";
1418
Ady Abrahamdfd62162020-06-10 16:11:56 -07001419 const auto getIdleFrameRate = [&](LayerVoteType voteType,
1420 bool touchActive) -> HwcConfigIndexType {
Steven Thomasbb374322020-04-28 22:47:16 -07001421 layers[0].vote = voteType;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001422 layers[0].desiredRefreshRate = Fps(90.f);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001423 RefreshRateConfigs::GlobalSignals consideredSignals;
1424 const auto configId =
1425 refreshRateConfigs
1426 ->getBestRefreshRate(layers, {.touch = touchActive, .idle = true},
1427 &consideredSignals)
1428 .getConfigId();
1429 // Refresh rate will be chosen by either touch state or idle state
1430 EXPECT_EQ(!touchActive, consideredSignals.idle);
1431 return configId;
Steven Thomasbb374322020-04-28 22:47:16 -07001432 };
1433
1434 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001435 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Steven Thomasbb374322020-04-28 22:47:16 -07001436 0);
1437
1438 // Idle should be lower priority than touch boost.
Ady Abrahamdfd62162020-06-10 16:11:56 -07001439 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/true));
1440 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/true));
1441 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/true));
1442 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/true));
1443 EXPECT_EQ(HWC_CONFIG_ID_90,
1444 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/true));
1445 EXPECT_EQ(HWC_CONFIG_ID_90,
1446 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/true));
Steven Thomasbb374322020-04-28 22:47:16 -07001447
1448 // With no layers, idle should still be lower priority than touch boost.
Steven Thomasbb374322020-04-28 22:47:16 -07001449 EXPECT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001450 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001451 .getConfigId());
1452
1453 // Idle should be higher precedence than other layer frame rate considerations.
1454 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001455 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/false));
1456 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/false));
1457 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/false));
1458 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/false));
1459 EXPECT_EQ(HWC_CONFIG_ID_60,
1460 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/false));
1461 EXPECT_EQ(HWC_CONFIG_ID_60,
1462 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/false));
Steven Thomasbb374322020-04-28 22:47:16 -07001463
1464 // Idle should be applied rather than the current config when there are no layers.
1465 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001466 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001467 .getConfigId());
1468}
1469
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001470TEST_F(RefreshRateConfigsTest, findClosestKnownFrameRate) {
1471 auto refreshRateConfigs =
1472 std::make_unique<RefreshRateConfigs>(m60_90Device,
1473 /*currentConfigId=*/HWC_CONFIG_ID_60);
1474
1475 for (float fps = 1.0f; fps <= 120.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001476 const auto knownFrameRate = findClosestKnownFrameRate(*refreshRateConfigs, Fps(fps));
1477 Fps expectedFrameRate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001478 if (fps < 26.91f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001479 expectedFrameRate = Fps(24.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001480 } else if (fps < 37.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001481 expectedFrameRate = Fps(30.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001482 } else if (fps < 52.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001483 expectedFrameRate = Fps(45.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001484 } else if (fps < 66.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001485 expectedFrameRate = Fps(60.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001486 } else if (fps < 81.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001487 expectedFrameRate = Fps(72.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001488 } else {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001489 expectedFrameRate = Fps(90.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001490 }
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001491 EXPECT_TRUE(expectedFrameRate.equalsWithMargin(knownFrameRate))
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001492 << "findClosestKnownFrameRate(" << fps << ") = " << knownFrameRate;
1493 }
1494}
1495
1496TEST_F(RefreshRateConfigsTest, getBestRefreshRate_KnownFrameRate) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001497 auto refreshRateConfigs =
1498 std::make_unique<RefreshRateConfigs>(m60_90Device,
1499 /*currentConfigId=*/HWC_CONFIG_ID_60);
1500
1501 struct ExpectedRate {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001502 Fps rate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001503 const RefreshRate& expected;
1504 };
1505
1506 /* clang-format off */
1507 std::vector<ExpectedRate> knownFrameRatesExpectations = {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001508 {Fps(24.0f), mExpected60Config},
1509 {Fps(30.0f), mExpected60Config},
1510 {Fps(45.0f), mExpected90Config},
1511 {Fps(60.0f), mExpected60Config},
1512 {Fps(72.0f), mExpected90Config},
1513 {Fps(90.0f), mExpected90Config},
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001514 };
1515 /* clang-format on */
1516
1517 // Make sure the test tests all the known frame rate
1518 const auto knownFrameRateList = getKnownFrameRate(*refreshRateConfigs);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001519 const auto equal =
1520 std::equal(knownFrameRateList.begin(), knownFrameRateList.end(),
1521 knownFrameRatesExpectations.begin(),
1522 [](Fps a, const ExpectedRate& b) { return a.equalsWithMargin(b.rate); });
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001523 EXPECT_TRUE(equal);
1524
1525 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1526 auto& layer = layers[0];
1527 layer.vote = LayerVoteType::Heuristic;
1528 for (const auto& expectedRate : knownFrameRatesExpectations) {
1529 layer.desiredRefreshRate = expectedRate.rate;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001530 const auto& refreshRate =
1531 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001532 EXPECT_EQ(expectedRate.expected, refreshRate);
1533 }
1534}
1535
Ana Krulecb9afd792020-06-11 13:16:15 -07001536TEST_F(RefreshRateConfigsTest, testComparisonOperator) {
1537 EXPECT_TRUE(mExpected60Config < mExpected90Config);
1538 EXPECT_FALSE(mExpected60Config < mExpected60Config);
1539 EXPECT_FALSE(mExpected90Config < mExpected90Config);
1540}
1541
1542TEST_F(RefreshRateConfigsTest, testKernelIdleTimerAction) {
1543 using KernelIdleTimerAction = scheduler::RefreshRateConfigs::KernelIdleTimerAction;
1544
1545 auto refreshRateConfigs =
1546 std::make_unique<RefreshRateConfigs>(m60_90Device,
1547 /*currentConfigId=*/HWC_CONFIG_ID_90);
1548 // SetPolicy(60, 90), current 90Hz => TurnOn.
1549 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1550
1551 // SetPolicy(60, 90), current 60Hz => TurnOn.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001552 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(90)}}),
1553 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001554 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1555
1556 // SetPolicy(60, 60), current 60Hz => NoChange, avoid extra calls.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001557 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
1558 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001559 EXPECT_EQ(KernelIdleTimerAction::NoChange, refreshRateConfigs->getIdleTimerAction());
1560
1561 // SetPolicy(90, 90), current 90Hz => TurnOff.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001562 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
1563 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001564 EXPECT_EQ(KernelIdleTimerAction::TurnOff, refreshRateConfigs->getIdleTimerAction());
1565}
1566
Ady Abraham0bb6a472020-10-12 10:22:13 -07001567TEST_F(RefreshRateConfigsTest, RefreshRateDividerForUid) {
1568 auto refreshRateConfigs =
1569 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
1570 /*currentConfigId=*/HWC_CONFIG_ID_30);
Ady Abraham62a0be22020-12-08 16:54:10 -08001571
1572 const auto frameRate = Fps(30.f);
1573 EXPECT_EQ(1, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001574
1575 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_60);
Ady Abraham62a0be22020-12-08 16:54:10 -08001576 EXPECT_EQ(2, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001577
1578 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_72);
Ady Abraham62a0be22020-12-08 16:54:10 -08001579 EXPECT_EQ(0, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001580
1581 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001582 EXPECT_EQ(3, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001583
1584 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
Ady Abraham62a0be22020-12-08 16:54:10 -08001585 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham62f216c2020-10-13 19:07:23 -07001586
1587 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001588 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.5f)));
1589 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.6f)));
1590}
1591
1592TEST_F(RefreshRateConfigsTest, populatePreferredFrameRate_noLayers) {
1593 auto refreshRateConfigs =
1594 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1595 HWC_CONFIG_ID_120);
1596
1597 auto layers = std::vector<LayerRequirement>{};
1598 ASSERT_TRUE(refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f)).empty());
1599}
1600
1601TEST_F(RefreshRateConfigsTest, getFrameRateOverrides_60on120) {
1602 auto refreshRateConfigs =
1603 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1604 HWC_CONFIG_ID_120);
1605
1606 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1607 layers[0].name = "Test layer";
1608 layers[0].ownerUid = 1234;
1609 layers[0].desiredRefreshRate = Fps(60.0f);
1610 layers[0].vote = LayerVoteType::ExplicitDefault;
1611 auto frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1612 ASSERT_EQ(1, frameRateOverrides.size());
1613 ASSERT_EQ(1, frameRateOverrides.count(1234));
1614 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1615
1616 layers[0].vote = LayerVoteType::ExplicitExactOrMultiple;
1617 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1618 ASSERT_EQ(1, frameRateOverrides.size());
1619 ASSERT_EQ(1, frameRateOverrides.count(1234));
1620 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1621
1622 layers[0].vote = LayerVoteType::NoVote;
1623 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1624 ASSERT_TRUE(frameRateOverrides.empty());
1625
1626 layers[0].vote = LayerVoteType::Min;
1627 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1628 ASSERT_TRUE(frameRateOverrides.empty());
1629
1630 layers[0].vote = LayerVoteType::Max;
1631 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1632 ASSERT_TRUE(frameRateOverrides.empty());
1633
1634 layers[0].vote = LayerVoteType::Heuristic;
1635 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1636 ASSERT_TRUE(frameRateOverrides.empty());
1637}
1638
1639TEST_F(RefreshRateConfigsTest, populatePreferredFrameRate_twoUids) {
1640 auto refreshRateConfigs =
1641 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1642 HWC_CONFIG_ID_120);
1643
1644 auto layers = std::vector<LayerRequirement>{
1645 LayerRequirement{.ownerUid = 1234, .weight = 1.0f},
1646 LayerRequirement{.ownerUid = 5678, .weight = 1.0f},
1647 };
1648
1649 layers[0].name = "Test layer 1234";
1650 layers[0].desiredRefreshRate = Fps(60.0f);
1651 layers[0].vote = LayerVoteType::ExplicitDefault;
1652
1653 layers[1].name = "Test layer 5678";
1654 layers[1].desiredRefreshRate = Fps(30.0f);
1655 layers[1].vote = LayerVoteType::ExplicitDefault;
1656 auto frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1657
1658 ASSERT_EQ(2, frameRateOverrides.size());
1659 ASSERT_EQ(1, frameRateOverrides.count(1234));
1660 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1661 ASSERT_EQ(1, frameRateOverrides.count(5678));
1662 ASSERT_EQ(30.0f, frameRateOverrides.at(5678).getValue());
1663
1664 layers[1].vote = LayerVoteType::Heuristic;
1665 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1666 ASSERT_EQ(1, frameRateOverrides.size());
1667 ASSERT_EQ(1, frameRateOverrides.count(1234));
1668 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1669
1670 layers[1].ownerUid = 1234;
1671 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1672 ASSERT_TRUE(frameRateOverrides.empty());
Ady Abraham0bb6a472020-10-12 10:22:13 -07001673}
1674
Alec Mouri0a1cc962019-03-14 12:33:02 -07001675} // namespace
1676} // namespace scheduler
1677} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001678
1679// TODO(b/129481165): remove the #pragma below and fix conversion issues
1680#pragma clang diagnostic pop // ignored "-Wextra"