blob: 27c181db8892d7e09e03f2904d7d64e2639d77df [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
Marin Shalamanov3ea1d602020-12-16 19:59:39 +010028#include <ui/Size.h>
29
Ady Abraham6fb599b2020-03-05 13:48:22 -080030#include "../../Scheduler/RefreshRateConfigs.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070031#include "DisplayHardware/HWC2.h"
32#include "Scheduler/RefreshRateConfigs.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070033
34using namespace std::chrono_literals;
Alec Mouri0a1cc962019-03-14 12:33:02 -070035
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
Marin Shalamanov3ea1d602020-12-16 19:59:39 +010084 DisplayModePtr mConfig60 = createConfig(HWC_CONFIG_ID_60, 0, Fps(60.0f).getPeriodNsecs());
85 DisplayModePtr mConfig90 = createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs());
86 DisplayModePtr mConfig90DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010087 createConfig(HWC_CONFIG_ID_90, 1, Fps(90.0f).getPeriodNsecs());
Marin Shalamanov3ea1d602020-12-16 19:59:39 +010088 DisplayModePtr mConfig90DifferentResolution =
89 createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs(), ui::Size(111, 222));
90 DisplayModePtr mConfig72 = createConfig(HWC_CONFIG_ID_72, 0, Fps(72.0f).getPeriodNsecs());
91 DisplayModePtr mConfig72DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010092 createConfig(HWC_CONFIG_ID_72, 1, Fps(72.0f).getPeriodNsecs());
Marin Shalamanov3ea1d602020-12-16 19:59:39 +010093 DisplayModePtr mConfig120 = createConfig(HWC_CONFIG_ID_120, 0, Fps(120.0f).getPeriodNsecs());
94 DisplayModePtr mConfig120DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010095 createConfig(HWC_CONFIG_ID_120, 1, Fps(120.0f).getPeriodNsecs());
Marin Shalamanov3ea1d602020-12-16 19:59:39 +010096 DisplayModePtr mConfig30 = createConfig(HWC_CONFIG_ID_30, 0, Fps(30.0f).getPeriodNsecs());
97 DisplayModePtr mConfig30DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010098 createConfig(HWC_CONFIG_ID_30, 1, Fps(30.0f).getPeriodNsecs());
Marin Shalamanov3ea1d602020-12-16 19:59:39 +010099 DisplayModePtr mConfig25DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100100 createConfig(HWC_CONFIG_ID_25, 1, Fps(25.0f).getPeriodNsecs());
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100101 DisplayModePtr mConfig50 = createConfig(HWC_CONFIG_ID_50, 0, Fps(50.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -0700102
103 // Test device configurations
Marin Shalamanov46084422020-10-13 12:33:42 +0200104 // The positions of the configs in the arrays below MUST match their IDs. For example,
105 // the first config should always be 60Hz, the second 90Hz etc.
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100106 DisplayModes m60OnlyConfigDevice = {mConfig60};
107 DisplayModes m60_90Device = {mConfig60, mConfig90};
108 DisplayModes m60_90DeviceWithDifferentGroups = {mConfig60, mConfig90DifferentGroup};
109 DisplayModes m60_90DeviceWithDifferentResolutions = {mConfig60, mConfig90DifferentResolution};
110 DisplayModes m60_72_90Device = {mConfig60, mConfig90, mConfig72};
111 DisplayModes m60_90_72_120Device = {mConfig60, mConfig90, mConfig72, mConfig120};
112 DisplayModes m30_60_72_90_120Device = {mConfig60, mConfig90, mConfig72, mConfig120, mConfig30};
113 DisplayModes m30_60Device = {mConfig60, mConfig90DifferentGroup, mConfig72DifferentGroup,
114 mConfig120DifferentGroup, mConfig30};
115 DisplayModes m30_60_72_90Device = {mConfig60, mConfig90, mConfig72, mConfig120DifferentGroup,
116 mConfig30};
117 DisplayModes m30_60_90Device = {mConfig60, mConfig90, mConfig72DifferentGroup,
118 mConfig120DifferentGroup, mConfig30};
119 DisplayModes m25_30_50_60Device = {mConfig60,
120 mConfig90,
121 mConfig72DifferentGroup,
122 mConfig120DifferentGroup,
123 mConfig30DifferentGroup,
124 mConfig25DifferentGroup,
125 mConfig50};
Ady Abrahamabc27602020-04-08 17:20:29 -0700126
127 // Expected RefreshRate objects
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100128 RefreshRate mExpected60Config = {HWC_CONFIG_ID_60, mConfig60, Fps(60),
Ady Abrahamabc27602020-04-08 17:20:29 -0700129 RefreshRate::ConstructorTag(0)};
130 RefreshRate mExpectedAlmost60Config = {HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100131 createConfig(HWC_CONFIG_ID_60, 0, 16666665), Fps(60),
Ady Abrahamabc27602020-04-08 17:20:29 -0700132 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100133 RefreshRate mExpected90Config = {HWC_CONFIG_ID_90, mConfig90, Fps(90),
Ady Abrahamabc27602020-04-08 17:20:29 -0700134 RefreshRate::ConstructorTag(0)};
135 RefreshRate mExpected90DifferentGroupConfig = {HWC_CONFIG_ID_90, mConfig90DifferentGroup,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100136 Fps(90), RefreshRate::ConstructorTag(0)};
Ady Abrahamabc27602020-04-08 17:20:29 -0700137 RefreshRate mExpected90DifferentResolutionConfig = {HWC_CONFIG_ID_90,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100138 mConfig90DifferentResolution, Fps(90),
Ady Abrahamabc27602020-04-08 17:20:29 -0700139 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100140 RefreshRate mExpected72Config = {HWC_CONFIG_ID_72, mConfig72, Fps(72.0f),
Ady Abrahamabc27602020-04-08 17:20:29 -0700141 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100142 RefreshRate mExpected30Config = {HWC_CONFIG_ID_30, mConfig30, Fps(30),
Ady Abrahamabc27602020-04-08 17:20:29 -0700143 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100144 RefreshRate mExpected120Config = {HWC_CONFIG_ID_120, mConfig120, Fps(120),
Ady Abrahamabc27602020-04-08 17:20:29 -0700145 RefreshRate::ConstructorTag(0)};
Ady Abrahamabc27602020-04-08 17:20:29 -0700146private:
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100147 DisplayModePtr createConfig(HwcConfigIndexType configId, int32_t configGroup,
148 int64_t vsyncPeriod, ui::Size resolution = ui::Size());
Alec Mouri0a1cc962019-03-14 12:33:02 -0700149};
150
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100151using Builder = DisplayMode::Builder;
Ady Abrahamabc27602020-04-08 17:20:29 -0700152
Alec Mouri0a1cc962019-03-14 12:33:02 -0700153RefreshRateConfigsTest::RefreshRateConfigsTest() {
154 const ::testing::TestInfo* const test_info =
155 ::testing::UnitTest::GetInstance()->current_test_info();
156 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
157}
158
159RefreshRateConfigsTest::~RefreshRateConfigsTest() {
160 const ::testing::TestInfo* const test_info =
161 ::testing::UnitTest::GetInstance()->current_test_info();
162 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
163}
164
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100165DisplayModePtr RefreshRateConfigsTest::createConfig(HwcConfigIndexType configId,
166 int32_t configGroup, int64_t vsyncPeriod,
167 ui::Size resolution) {
168 return DisplayMode::Builder(hal::HWConfigId(configId.value()))
Ady Abrahamabc27602020-04-08 17:20:29 -0700169 .setVsyncPeriod(int32_t(vsyncPeriod))
170 .setConfigGroup(configGroup)
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100171 .setHeight(resolution.height)
172 .setWidth(resolution.width)
Ady Abrahamabc27602020-04-08 17:20:29 -0700173 .build();
174}
175
Alec Mouri0a1cc962019-03-14 12:33:02 -0700176namespace {
177/* ------------------------------------------------------------------------
178 * Test cases
179 */
Ady Abraham2139f732019-11-13 18:56:40 -0800180TEST_F(RefreshRateConfigsTest, oneDeviceConfig_SwitchingSupported) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700181 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700182 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
183 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700184}
185
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100186TEST_F(RefreshRateConfigsTest, invalidPolicy) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100187 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700188 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
189 /*currentConfigId=*/HWC_CONFIG_ID_60);
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100190 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy(
191 {HwcConfigIndexType(10), {Fps(60), Fps(60)}}),
192 0);
193 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(20), Fps(40)}}),
194 0);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100195}
196
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700197TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700198 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700199 std::make_unique<RefreshRateConfigs>(m60_90Device,
200 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700201
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100202 const auto& minRate = getMinSupportedRefreshRate(*refreshRateConfigs);
203 const auto& performanceRate = getMaxSupportedRefreshRate(*refreshRateConfigs);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700204
Ady Abrahamabc27602020-04-08 17:20:29 -0700205 ASSERT_EQ(mExpected60Config, minRate);
206 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800207
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100208 const auto& minRateByPolicy = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800209 const auto& performanceRateByPolicy = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800210 ASSERT_EQ(minRateByPolicy, minRate);
211 ASSERT_EQ(performanceRateByPolicy, performanceRate);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700212}
Ady Abraham2139f732019-11-13 18:56:40 -0800213
214TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentGroups) {
Ady Abraham2139f732019-11-13 18:56:40 -0800215 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700216 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
217 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800218
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100219 const auto& minRate = getMinRefreshRateByPolicy(*refreshRateConfigs);
220 const auto& performanceRate = getMaxSupportedRefreshRate(*refreshRateConfigs);
221 const auto& minRate60 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800222 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800223
Ady Abrahamabc27602020-04-08 17:20:29 -0700224 ASSERT_EQ(mExpected60Config, minRate);
225 ASSERT_EQ(mExpected60Config, minRate60);
226 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800227
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100228 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
229 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800230 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
231
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100232 const auto& minRate90 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800233 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800234
Ady Abrahamabc27602020-04-08 17:20:29 -0700235 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate);
236 ASSERT_EQ(mExpected90DifferentGroupConfig, minRate90);
237 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate90);
238}
239
240TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentResolutions) {
241 auto refreshRateConfigs =
242 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentResolutions,
243 /*currentConfigId=*/HWC_CONFIG_ID_60);
244
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100245 const auto& minRate = getMinRefreshRateByPolicy(*refreshRateConfigs);
246 const auto& performanceRate = getMaxSupportedRefreshRate(*refreshRateConfigs);
247 const auto& minRate60 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abrahamabc27602020-04-08 17:20:29 -0700248 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
249
250 ASSERT_EQ(mExpected60Config, minRate);
251 ASSERT_EQ(mExpected60Config, minRate60);
252 ASSERT_EQ(mExpected60Config, performanceRate60);
253
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100254 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
255 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700256 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
257
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100258 const auto& minRate90 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abrahamabc27602020-04-08 17:20:29 -0700259 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
260
261 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate);
262 ASSERT_EQ(mExpected90DifferentResolutionConfig, minRate90);
263 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate90);
Ady Abraham2139f732019-11-13 18:56:40 -0800264}
265
266TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_policyChange) {
Ady Abraham2139f732019-11-13 18:56:40 -0800267 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700268 std::make_unique<RefreshRateConfigs>(m60_90Device,
269 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ana Krulec3f6a2062020-01-23 15:48:01 -0800270
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100271 auto minRate = getMinRefreshRateByPolicy(*refreshRateConfigs);
272 auto performanceRate = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800273
Ady Abrahamabc27602020-04-08 17:20:29 -0700274 ASSERT_EQ(mExpected60Config, minRate);
275 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800276
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100277 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
278 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800279
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100280 auto minRate60 = getMinRefreshRateByPolicy(*refreshRateConfigs);
281 auto performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abrahamabc27602020-04-08 17:20:29 -0700282 ASSERT_EQ(mExpected60Config, minRate60);
283 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800284}
285
286TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getCurrentRefreshRate) {
Ady Abraham2139f732019-11-13 18:56:40 -0800287 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700288 std::make_unique<RefreshRateConfigs>(m60_90Device,
289 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800290 {
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100291 auto current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700292 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800293 }
294
295 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
296 {
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100297 auto current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700298 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800299 }
300
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100301 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
302 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800303 {
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100304 auto current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700305 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800306 }
307}
308
Steven Thomasbb374322020-04-28 22:47:16 -0700309TEST_F(RefreshRateConfigsTest, getBestRefreshRate_noLayers) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700310 auto refreshRateConfigs =
311 std::make_unique<RefreshRateConfigs>(m60_72_90Device, /*currentConfigId=*/
312 HWC_CONFIG_ID_72);
Ana Krulec3d367c82020-02-25 15:02:01 -0800313
Steven Thomasdebafed2020-05-18 17:30:35 -0700314 // If there are no layers we select the default frame rate, which is the max of the primary
315 // range.
Ana Krulec3d367c82020-02-25 15:02:01 -0800316 auto layers = std::vector<LayerRequirement>{};
Steven Thomasdebafed2020-05-18 17:30:35 -0700317 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700318 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800319
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100320 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
321 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700322 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700323 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800324}
325
Steven Thomasbb374322020-04-28 22:47:16 -0700326TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800327 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700328 std::make_unique<RefreshRateConfigs>(m60_90Device,
329 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800330
331 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
332 auto& lr = layers[0];
333
334 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800335 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700336 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700337 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800338
339 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800340 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700341 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700342 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800343
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100344 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800345 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800346 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700347 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700348 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800349
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100350 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800351 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700352 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700353 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800354
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100355 lr.desiredRefreshRate = Fps(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800356 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700357 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700358 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800359
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100360 lr.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800361 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700362 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700363 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800364
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100365 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800366 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700367 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700368 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800369
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800370 lr.name = "";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100371 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
372 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800373
374 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700375 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700376 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800377
378 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700379 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700380 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800381
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100382 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800383 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700384 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700385 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800386
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100387 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700388 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700389 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800390
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100391 lr.desiredRefreshRate = Fps(45.0f);
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
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100395 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700396 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700397 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800398
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100399 lr.desiredRefreshRate = Fps(24.0f);
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
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100403 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
404 {HWC_CONFIG_ID_90, {Fps(90.0f), Fps(90.0f)}}),
405 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800406
407 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700408 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700409 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800410
411 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700412 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700413 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800414
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100415 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800416 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700417 EXPECT_EQ(mExpected90Config,
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(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700421 EXPECT_EQ(mExpected90Config,
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(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700425 EXPECT_EQ(mExpected90Config,
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 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700429 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700430 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800431
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100432 lr.desiredRefreshRate = Fps(24.0f);
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
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100436 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
437 {HWC_CONFIG_ID_60, {Fps(0.0f), Fps(120.0f)}}),
438 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800439 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700440 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700441 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800442
443 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700444 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700445 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800446
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100447 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800448 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700449 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700450 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800451
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100452 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700453 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700454 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800455
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100456 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700457 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700458 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800459
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100460 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700461 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700462 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800463
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100464 lr.desiredRefreshRate = Fps(24.0f);
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
Steven Thomasbb374322020-04-28 22:47:16 -0700469TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800470 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700471 std::make_unique<RefreshRateConfigs>(m60_72_90Device,
472 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800473
474 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
475 auto& lr = layers[0];
476
477 lr.vote = LayerVoteType::Min;
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
481 lr.vote = LayerVoteType::Max;
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(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800486 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700487 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700488 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800489
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100490 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700491 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700492 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800493
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100494 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700495 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700496 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800497
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100498 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700499 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700500 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800501
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100502 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700503 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700504 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800505}
506
Steven Thomasbb374322020-04-28 22:47:16 -0700507TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90_120) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800508 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700509 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
510 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800511
512 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
513 LayerRequirement{.weight = 1.0f}};
514 auto& lr1 = layers[0];
515 auto& lr2 = layers[1];
516
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100517 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800518 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100519 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800520 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700521 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700522 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800523
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100524 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800525 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100526 lr2.desiredRefreshRate = Fps(48.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800527 lr2.vote = LayerVoteType::Heuristic;
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
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100531 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800532 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100533 lr2.desiredRefreshRate = Fps(48.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800534 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700535 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700536 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800537}
538
Steven Thomasbb374322020-04-28 22:47:16 -0700539TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_90_120_DifferentTypes) {
Ady Abraham71c437d2020-01-31 15:56:57 -0800540 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700541 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
542 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham71c437d2020-01-31 15:56:57 -0800543
544 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
545 LayerRequirement{.weight = 1.0f}};
546 auto& lr1 = layers[0];
547 auto& lr2 = layers[1];
548
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100549 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800550 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800551 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100552 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800553 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800554 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700555 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700556 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800557
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100558 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800559 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800560 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100561 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800562 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800563 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700564 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700565 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800566
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100567 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800568 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800569 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100570 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800571 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800572 lr2.name = "60Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700573 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700574 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800575
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100576 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800577 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800578 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100579 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800580 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800581 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700582 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700583 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800584
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100585 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800586 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
587 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100588 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800589 lr2.vote = LayerVoteType::ExplicitDefault;
590 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700591 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700592 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800593
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100594 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800595 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800596 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100597 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800598 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800599 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700600 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700601 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800602
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100603 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800604 lr1.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800605 lr1.name = "24Hz Heuristic";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100606 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800607 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800608 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700609 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700610 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800611
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100612 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800613 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800614 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100615 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800616 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800617 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700618 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700619 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800620
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100621 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800622 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800623 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100624 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800625 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800626 lr2.name = "90Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700627 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700628 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800629}
630
Steven Thomasbb374322020-04-28 22:47:16 -0700631TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800632 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700633 std::make_unique<RefreshRateConfigs>(m30_60Device,
634 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800635
636 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
637 auto& lr = layers[0];
638
639 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700640 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700641 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800642
643 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700644 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700645 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800646
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100647 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800648 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700649 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700650 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800651
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100652 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700653 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700654 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800655
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100656 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700657 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700658 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800659
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100660 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700661 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700662 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800663
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100664 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700665 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700666 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800667}
668
Steven Thomasbb374322020-04-28 22:47:16 -0700669TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800670 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700671 std::make_unique<RefreshRateConfigs>(m30_60_72_90Device,
672 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800673
674 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
675 auto& lr = layers[0];
676
677 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800678 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700679 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700680 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800681
682 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800683 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700684 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700685 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800686
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100687 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800688 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800689 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700690 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700691 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800692
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100693 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800694 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700695 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700696 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700697 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700698 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800699
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100700 lr.desiredRefreshRate = Fps(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800701 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700702 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700703 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700704 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700705 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800706
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100707 lr.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800708 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700709 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700710 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700711 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700712 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800713
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100714 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800715 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700716 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700717 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700718 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700719 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800720
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100721 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800722 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
723 lr.name = "24Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700724 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700725 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700726 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700727 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800728}
729
Steven Thomasbb374322020-04-28 22:47:16 -0700730TEST_F(RefreshRateConfigsTest, getBestRefreshRate_PriorityTest) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800731 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700732 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
733 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800734
735 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
736 LayerRequirement{.weight = 1.0f}};
737 auto& lr1 = layers[0];
738 auto& lr2 = layers[1];
739
740 lr1.vote = LayerVoteType::Min;
741 lr2.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700742 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700743 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800744
745 lr1.vote = LayerVoteType::Min;
746 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100747 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700748 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700749 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800750
751 lr1.vote = LayerVoteType::Min;
Ady Abraham71c437d2020-01-31 15:56:57 -0800752 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100753 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700754 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700755 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800756
757 lr1.vote = LayerVoteType::Max;
758 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100759 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700760 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700761 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800762
763 lr1.vote = LayerVoteType::Max;
Ady Abraham71c437d2020-01-31 15:56:57 -0800764 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100765 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700766 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700767 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800768
769 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100770 lr1.desiredRefreshRate = Fps(15.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800771 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100772 lr2.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700773 EXPECT_EQ(mExpected90Config,
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::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100777 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800778 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100779 lr2.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700780 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700781 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800782}
783
Steven Thomasbb374322020-04-28 22:47:16 -0700784TEST_F(RefreshRateConfigsTest, getBestRefreshRate_24FpsVideo) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800785 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700786 std::make_unique<RefreshRateConfigs>(m60_90Device,
787 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800788
789 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
790 auto& lr = layers[0];
791
Ady Abraham71c437d2020-01-31 15:56:57 -0800792 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800793 for (float fps = 23.0f; fps < 25.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100794 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800795 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700796 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700797 EXPECT_EQ(mExpected60Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abraham8a82ba62020-01-17 12:43:17 -0800798 }
799}
800
Steven Thomasbb374322020-04-28 22:47:16 -0700801TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getBestRefreshRate_Explicit) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800802 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700803 std::make_unique<RefreshRateConfigs>(m60_90Device,
804 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800805
806 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
807 LayerRequirement{.weight = 1.0f}};
808 auto& lr1 = layers[0];
809 auto& lr2 = layers[1];
810
811 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100812 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800813 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100814 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700815 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700816 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800817
818 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100819 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800820 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100821 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700822 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700823 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800824
825 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100826 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800827 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100828 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700829 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700830 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham2139f732019-11-13 18:56:40 -0800831}
832
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800833TEST_F(RefreshRateConfigsTest, testInPolicy) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100834 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(60.000004f), Fps(60.000004f)));
835 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(59.0f), Fps(60.1f)));
836 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(75.0f), Fps(90.0f)));
837 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(60.0011f), Fps(90.0f)));
838 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(50.0f), Fps(59.998f)));
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800839}
840
Steven Thomasbb374322020-04-28 22:47:16 -0700841TEST_F(RefreshRateConfigsTest, getBestRefreshRate_75HzContent) {
Ady Abrahamf6b77072020-01-30 14:22:54 -0800842 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700843 std::make_unique<RefreshRateConfigs>(m60_90Device,
844 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abrahamf6b77072020-01-30 14:22:54 -0800845
846 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
847 auto& lr = layers[0];
848
Ady Abraham71c437d2020-01-31 15:56:57 -0800849 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abrahamf6b77072020-01-30 14:22:54 -0800850 for (float fps = 75.0f; fps < 100.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100851 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800852 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700853 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700854 EXPECT_EQ(mExpected90Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abrahamf6b77072020-01-30 14:22:54 -0800855 }
856}
857
Steven Thomasbb374322020-04-28 22:47:16 -0700858TEST_F(RefreshRateConfigsTest, getBestRefreshRate_Multiples) {
Ady Abraham34702102020-02-10 14:12:05 -0800859 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700860 std::make_unique<RefreshRateConfigs>(m60_90Device,
861 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham34702102020-02-10 14:12:05 -0800862
863 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
864 LayerRequirement{.weight = 1.0f}};
865 auto& lr1 = layers[0];
866 auto& lr2 = layers[1];
867
868 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100869 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800870 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800871 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100872 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800873 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700874 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700875 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800876
877 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100878 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800879 lr1.name = "60Hz ExplicitExactOrMultiple";
880 lr2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100881 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800882 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700883 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700884 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800885
886 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100887 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800888 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800889 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800890 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700891 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700892 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800893
894 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100895 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800896 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800897 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100898 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800899 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700900 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700901 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800902
903 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100904 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800905 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800906 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800907 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700908 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700909 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800910}
911
912TEST_F(RefreshRateConfigsTest, scrollWhileWatching60fps_60_90) {
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800913 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700914 std::make_unique<RefreshRateConfigs>(m60_90Device,
915 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800916
917 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
918 LayerRequirement{.weight = 1.0f}};
919 auto& lr1 = layers[0];
920 auto& lr2 = layers[1];
921
922 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100923 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800924 lr1.name = "60Hz ExplicitExactOrMultiple";
925 lr2.vote = LayerVoteType::NoVote;
926 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700927 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700928 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800929
930 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100931 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800932 lr1.name = "60Hz ExplicitExactOrMultiple";
933 lr2.vote = LayerVoteType::NoVote;
934 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700935 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700936 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800937
938 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100939 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800940 lr1.name = "60Hz ExplicitExactOrMultiple";
941 lr2.vote = LayerVoteType::Max;
942 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700943 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700944 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800945
946 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100947 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800948 lr1.name = "60Hz ExplicitExactOrMultiple";
949 lr2.vote = LayerVoteType::Max;
950 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700951 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700952 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800953
954 // The other layer starts to provide buffers
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::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100959 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800960 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700961 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700962 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham6fb599b2020-03-05 13:48:22 -0800963}
964
965TEST_F(RefreshRateConfigsTest, touchConsidered) {
Ady Abrahamdfd62162020-06-10 16:11:56 -0700966 RefreshRateConfigs::GlobalSignals consideredSignals;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800967 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700968 std::make_unique<RefreshRateConfigs>(m60_90Device,
969 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800970
Ady Abrahamdfd62162020-06-10 16:11:56 -0700971 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false}, &consideredSignals);
972 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800973
Ady Abrahamdfd62162020-06-10 16:11:56 -0700974 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = false}, &consideredSignals);
975 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800976
977 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
978 LayerRequirement{.weight = 1.0f}};
979 auto& lr1 = layers[0];
980 auto& lr2 = layers[1];
981
982 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100983 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800984 lr1.name = "60Hz ExplicitExactOrMultiple";
985 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100986 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -0700987 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -0700988 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
989 &consideredSignals);
990 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800991
992 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100993 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800994 lr1.name = "60Hz ExplicitExactOrMultiple";
995 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100996 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -0700997 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -0700998 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
999 &consideredSignals);
1000 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001001
1002 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001003 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001004 lr1.name = "60Hz ExplicitExactOrMultiple";
1005 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001006 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001007 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001008 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1009 &consideredSignals);
1010 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001011
1012 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001013 lr1.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001014 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001015 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001016 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001017 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001018 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1019 &consideredSignals);
1020 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham34702102020-02-10 14:12:05 -08001021}
1022
Steven Thomasbb374322020-04-28 22:47:16 -07001023TEST_F(RefreshRateConfigsTest, getBestRefreshRate_ExplicitDefault) {
Ady Abrahamabc27602020-04-08 17:20:29 -07001024 auto refreshRateConfigs =
1025 std::make_unique<RefreshRateConfigs>(m60_90_72_120Device, /*currentConfigId=*/
1026 HWC_CONFIG_ID_60);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001027
1028 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1029 auto& lr = layers[0];
1030
1031 // Prepare a table with the vote and the expected refresh rate
1032 const std::vector<std::pair<float, float>> testCases = {
1033 {130, 120}, {120, 120}, {119, 120}, {110, 120},
1034
1035 {100, 90}, {90, 90}, {89, 90},
1036
1037 {80, 72}, {73, 72}, {72, 72}, {71, 72}, {70, 72},
1038
1039 {65, 60}, {60, 60}, {59, 60}, {58, 60},
1040
1041 {55, 90}, {50, 90}, {45, 90},
1042
1043 {42, 120}, {40, 120}, {39, 120},
1044
1045 {37, 72}, {36, 72}, {35, 72},
1046
1047 {30, 60},
1048 };
1049
1050 for (const auto& test : testCases) {
1051 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001052 lr.desiredRefreshRate = Fps(test.first);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001053
1054 std::stringstream ss;
1055 ss << "ExplicitDefault " << test.first << " fps";
1056 lr.name = ss.str();
1057
1058 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -07001059 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001060 EXPECT_TRUE(refreshRate.getFps().equalsWithMargin(Fps(test.second)))
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001061 << "Expecting " << test.first << "fps => " << test.second << "Hz";
1062 }
Alec Mouri0a1cc962019-03-14 12:33:02 -07001063}
1064
Alec Mouri11232a22020-05-14 18:06:25 -07001065TEST_F(RefreshRateConfigsTest,
1066 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresTouchFlag) {
1067 auto refreshRateConfigs =
1068 std::make_unique<RefreshRateConfigs>(m60_90Device,
1069 /*currentConfigId=*/HWC_CONFIG_ID_90);
1070
1071 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001072 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001073 0);
1074
1075 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1076 auto& lr = layers[0];
1077
Ady Abrahamdfd62162020-06-10 16:11:56 -07001078 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001079 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001080 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001081 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001082 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001083 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001084 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = true},
1085 &consideredSignals));
1086 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001087}
1088
1089TEST_F(RefreshRateConfigsTest,
1090 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresIdleFlag) {
1091 auto refreshRateConfigs =
1092 std::make_unique<RefreshRateConfigs>(m60_90Device,
1093 /*currentConfigId=*/HWC_CONFIG_ID_60);
1094
1095 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001096 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001097 0);
1098
1099 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1100 auto& lr = layers[0];
1101
Alec Mouri11232a22020-05-14 18:06:25 -07001102 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001103 lr.desiredRefreshRate = Fps(90.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001104 lr.name = "90Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001105 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001106 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001107 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = true}));
Alec Mouri11232a22020-05-14 18:06:25 -07001108}
1109
1110TEST_F(RefreshRateConfigsTest,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001111 getBestRefreshRate_withDisplayManagerRequestingSingleRate_onlySwitchesRatesForExplicitFocusedLayers) {
Alec Mouri11232a22020-05-14 18:06:25 -07001112 auto refreshRateConfigs =
1113 std::make_unique<RefreshRateConfigs>(m60_90Device,
1114 /*currentConfigId=*/HWC_CONFIG_ID_90);
1115
1116 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001117 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001118 0);
1119
Ady Abrahamdfd62162020-06-10 16:11:56 -07001120 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001121 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001122 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false},
1123 &consideredSignals));
1124 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001125
1126 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1127 auto& lr = layers[0];
1128
1129 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001130 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001131 lr.name = "60Hz ExplicitExactOrMultiple";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001132 lr.focused = false;
1133 EXPECT_EQ(mExpected90Config,
1134 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1135
1136 lr.focused = true;
Ady Abraham20c029c2020-07-06 12:58:05 -07001137 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001138 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001139
1140 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001141 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001142 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001143 lr.focused = false;
1144 EXPECT_EQ(mExpected90Config,
1145 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1146
1147 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001148 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001149 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001150
1151 lr.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001152 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001153 lr.name = "60Hz Heuristic";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001154 lr.focused = false;
1155 EXPECT_EQ(mExpected90Config,
1156 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1157
1158 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001159 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001160 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001161
1162 lr.vote = LayerVoteType::Max;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001163 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001164 lr.name = "60Hz Max";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001165 lr.focused = false;
1166 EXPECT_EQ(mExpected90Config,
1167 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1168
1169 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001170 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001171 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001172
1173 lr.vote = LayerVoteType::Min;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001174 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001175 lr.name = "60Hz Min";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001176 lr.focused = false;
1177 EXPECT_EQ(mExpected90Config,
1178 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1179
1180 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001181 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001182 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001183}
1184
Steven Thomasd4071902020-03-24 16:02:53 -07001185TEST_F(RefreshRateConfigsTest, groupSwitching) {
Steven Thomasd4071902020-03-24 16:02:53 -07001186 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -07001187 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
1188 /*currentConfigId=*/HWC_CONFIG_ID_60);
Steven Thomasd4071902020-03-24 16:02:53 -07001189
1190 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1191 auto& layer = layers[0];
1192 layer.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001193 layer.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001194 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Steven Thomasd4071902020-03-24 16:02:53 -07001195 layer.name = "90Hz ExplicitDefault";
Marin Shalamanov46084422020-10-13 12:33:42 +02001196 layer.focused = true;
Steven Thomasd4071902020-03-24 16:02:53 -07001197
Steven Thomasd4071902020-03-24 16:02:53 -07001198 ASSERT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001199 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001200 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001201
1202 RefreshRateConfigs::Policy policy;
1203 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1204 policy.allowGroupSwitching = true;
1205 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1206 ASSERT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001207 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001208 .getConfigId());
Marin Shalamanov46084422020-10-13 12:33:42 +02001209
1210 // Verify that we won't change the group if seamless switch is required.
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001211 layer.seamlessness = Seamlessness::OnlySeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001212 ASSERT_EQ(HWC_CONFIG_ID_60,
1213 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1214 .getConfigId());
1215
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001216 // 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 +02001217 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001218 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001219 layer.name = "60Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001220 layer.seamlessness = Seamlessness::OnlySeamless;
1221 ASSERT_EQ(HWC_CONFIG_ID_90,
1222 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1223 .getConfigId());
1224
1225 // Verify that if the current config is in another group and there are no layers with
1226 // seamlessness=SeamedAndSeamless we'll go back to the default group.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001227 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001228 layer.name = "60Hz ExplicitDefault";
1229 layer.seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001230 ASSERT_EQ(HWC_CONFIG_ID_60,
1231 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1232 .getConfigId());
1233
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001234 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1235 // seamlessness=OnlySeamless can't change the config group.
Marin Shalamanov46084422020-10-13 12:33:42 +02001236 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001237 layer.seamlessness = Seamlessness::OnlySeamless;
1238
1239 layers.push_back(LayerRequirement{.weight = 0.5f});
1240 auto& layer2 = layers[layers.size() - 1];
Marin Shalamanov46084422020-10-13 12:33:42 +02001241 layer2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001242 layer2.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001243 layer2.name = "90Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001244 layer2.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001245 layer2.focused = false;
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001246
1247 ASSERT_EQ(HWC_CONFIG_ID_90,
1248 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1249 .getConfigId());
1250
1251 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1252 // seamlessness=Default can't change the config group.
1253 layers[0].seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001254 ASSERT_EQ(HWC_CONFIG_ID_90,
1255 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1256 .getConfigId());
1257}
1258
1259TEST_F(RefreshRateConfigsTest, nonSeamlessVotePrefersSeamlessSwitches) {
1260 auto refreshRateConfigs =
1261 std::make_unique<RefreshRateConfigs>(m30_60Device,
1262 /*currentConfigId=*/HWC_CONFIG_ID_60);
1263
1264 // Allow group switching.
1265 RefreshRateConfigs::Policy policy;
1266 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1267 policy.allowGroupSwitching = true;
1268 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1269
1270 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1271 auto& layer = layers[0];
1272 layer.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001273 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001274 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001275 layer.name = "60Hz ExplicitExactOrMultiple";
1276 layer.focused = true;
1277
1278 ASSERT_EQ(HWC_CONFIG_ID_60,
1279 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1280 .getConfigId());
1281
1282 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
1283 ASSERT_EQ(HWC_CONFIG_ID_120,
1284 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1285 .getConfigId());
1286}
1287
1288TEST_F(RefreshRateConfigsTest, nonSeamlessExactAndSeamlessMultipleLayers) {
1289 auto refreshRateConfigs =
1290 std::make_unique<RefreshRateConfigs>(m25_30_50_60Device,
1291 /*currentConfigId=*/HWC_CONFIG_ID_60);
1292
1293 // Allow group switching.
1294 RefreshRateConfigs::Policy policy;
1295 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1296 policy.allowGroupSwitching = true;
1297 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1298
1299 auto layers = std::vector<
1300 LayerRequirement>{LayerRequirement{.name = "60Hz ExplicitDefault",
1301 .vote = LayerVoteType::ExplicitDefault,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001302 .desiredRefreshRate = Fps(60.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001303 .seamlessness = Seamlessness::SeamedAndSeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001304 .weight = 0.5f,
1305 .focused = false},
1306 LayerRequirement{.name = "25Hz ExplicitExactOrMultiple",
1307 .vote = LayerVoteType::ExplicitExactOrMultiple,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001308 .desiredRefreshRate = Fps(25.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001309 .seamlessness = Seamlessness::OnlySeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001310 .weight = 1.0f,
1311 .focused = true}};
1312 auto& seamedLayer = layers[0];
1313
1314 ASSERT_EQ(HWC_CONFIG_ID_50,
1315 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1316 .getConfigId());
1317
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001318 seamedLayer.name = "30Hz ExplicitDefault", seamedLayer.desiredRefreshRate = Fps(30.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001319 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_30);
1320
1321 ASSERT_EQ(HWC_CONFIG_ID_25,
1322 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1323 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001324}
1325
Steven Thomasf734df42020-04-13 21:09:28 -07001326TEST_F(RefreshRateConfigsTest, primaryVsAppRequestPolicy) {
1327 auto refreshRateConfigs =
Alec Mouri11232a22020-05-14 18:06:25 -07001328 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
Steven Thomasf734df42020-04-13 21:09:28 -07001329 /*currentConfigId=*/HWC_CONFIG_ID_60);
1330
1331 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1332 layers[0].name = "Test layer";
1333
Steven Thomasbb374322020-04-28 22:47:16 -07001334 // Return the config ID from calling getBestRefreshRate() for a single layer with the
Steven Thomasf734df42020-04-13 21:09:28 -07001335 // given voteType and fps.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001336 auto getFrameRate = [&](LayerVoteType voteType, Fps fps, bool touchActive = false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001337 bool focused = true) -> HwcConfigIndexType {
Steven Thomasf734df42020-04-13 21:09:28 -07001338 layers[0].vote = voteType;
1339 layers[0].desiredRefreshRate = fps;
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001340 layers[0].focused = focused;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001341 return refreshRateConfigs->getBestRefreshRate(layers, {.touch = touchActive, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001342 .getConfigId();
1343 };
1344
1345 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001346 {HWC_CONFIG_ID_60, {Fps(30.f), Fps(60.f)}, {Fps(30.f), Fps(90.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001347 0);
Steven Thomasf734df42020-04-13 21:09:28 -07001348 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001349 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001350 .getConfigId());
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001351 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1352 EXPECT_EQ(HWC_CONFIG_ID_30, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1353 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1354 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1355 EXPECT_EQ(HWC_CONFIG_ID_90, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1356 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001357
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001358 // Layers not focused are not allowed to override primary config
1359 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001360 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001361 /*focused=*/false));
1362 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001363 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001364 /*focused=*/false));
1365
Steven Thomasf734df42020-04-13 21:09:28 -07001366 // Touch boost should be restricted to the primary range.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001367 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001368 // When we're higher than the primary range max due to a layer frame rate setting, touch boost
1369 // shouldn't drag us back down to the primary range max.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001370 EXPECT_EQ(HWC_CONFIG_ID_90,
1371 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/true));
Ady Abraham20c029c2020-07-06 12:58:05 -07001372 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001373 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001374
1375 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001376 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(60.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001377 0);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001378 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1379 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1380 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1381 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1382 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1383 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001384}
1385
Steven Thomasbb374322020-04-28 22:47:16 -07001386TEST_F(RefreshRateConfigsTest, idle) {
1387 auto refreshRateConfigs =
1388 std::make_unique<RefreshRateConfigs>(m60_90Device,
1389 /*currentConfigId=*/HWC_CONFIG_ID_60);
1390
1391 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1392 layers[0].name = "Test layer";
1393
Ady Abrahamdfd62162020-06-10 16:11:56 -07001394 const auto getIdleFrameRate = [&](LayerVoteType voteType,
1395 bool touchActive) -> HwcConfigIndexType {
Steven Thomasbb374322020-04-28 22:47:16 -07001396 layers[0].vote = voteType;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001397 layers[0].desiredRefreshRate = Fps(90.f);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001398 RefreshRateConfigs::GlobalSignals consideredSignals;
1399 const auto configId =
1400 refreshRateConfigs
1401 ->getBestRefreshRate(layers, {.touch = touchActive, .idle = true},
1402 &consideredSignals)
1403 .getConfigId();
1404 // Refresh rate will be chosen by either touch state or idle state
1405 EXPECT_EQ(!touchActive, consideredSignals.idle);
1406 return configId;
Steven Thomasbb374322020-04-28 22:47:16 -07001407 };
1408
1409 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001410 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Steven Thomasbb374322020-04-28 22:47:16 -07001411 0);
1412
1413 // Idle should be lower priority than touch boost.
Ady Abrahamdfd62162020-06-10 16:11:56 -07001414 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/true));
1415 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/true));
1416 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/true));
1417 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/true));
1418 EXPECT_EQ(HWC_CONFIG_ID_90,
1419 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/true));
1420 EXPECT_EQ(HWC_CONFIG_ID_90,
1421 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/true));
Steven Thomasbb374322020-04-28 22:47:16 -07001422
1423 // With no layers, idle should still be lower priority than touch boost.
Steven Thomasbb374322020-04-28 22:47:16 -07001424 EXPECT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001425 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001426 .getConfigId());
1427
1428 // Idle should be higher precedence than other layer frame rate considerations.
1429 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001430 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/false));
1431 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/false));
1432 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/false));
1433 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/false));
1434 EXPECT_EQ(HWC_CONFIG_ID_60,
1435 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/false));
1436 EXPECT_EQ(HWC_CONFIG_ID_60,
1437 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/false));
Steven Thomasbb374322020-04-28 22:47:16 -07001438
1439 // Idle should be applied rather than the current config when there are no layers.
1440 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001441 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001442 .getConfigId());
1443}
1444
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001445TEST_F(RefreshRateConfigsTest, findClosestKnownFrameRate) {
1446 auto refreshRateConfigs =
1447 std::make_unique<RefreshRateConfigs>(m60_90Device,
1448 /*currentConfigId=*/HWC_CONFIG_ID_60);
1449
1450 for (float fps = 1.0f; fps <= 120.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001451 const auto knownFrameRate = findClosestKnownFrameRate(*refreshRateConfigs, Fps(fps));
1452 Fps expectedFrameRate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001453 if (fps < 26.91f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001454 expectedFrameRate = Fps(24.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001455 } else if (fps < 37.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001456 expectedFrameRate = Fps(30.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001457 } else if (fps < 52.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001458 expectedFrameRate = Fps(45.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001459 } else if (fps < 66.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001460 expectedFrameRate = Fps(60.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001461 } else if (fps < 81.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001462 expectedFrameRate = Fps(72.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001463 } else {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001464 expectedFrameRate = Fps(90.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001465 }
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001466 EXPECT_TRUE(expectedFrameRate.equalsWithMargin(knownFrameRate))
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001467 << "findClosestKnownFrameRate(" << fps << ") = " << knownFrameRate;
1468 }
1469}
1470
1471TEST_F(RefreshRateConfigsTest, getBestRefreshRate_KnownFrameRate) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001472 auto refreshRateConfigs =
1473 std::make_unique<RefreshRateConfigs>(m60_90Device,
1474 /*currentConfigId=*/HWC_CONFIG_ID_60);
1475
1476 struct ExpectedRate {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001477 Fps rate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001478 const RefreshRate& expected;
1479 };
1480
1481 /* clang-format off */
1482 std::vector<ExpectedRate> knownFrameRatesExpectations = {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001483 {Fps(24.0f), mExpected60Config},
1484 {Fps(30.0f), mExpected60Config},
1485 {Fps(45.0f), mExpected90Config},
1486 {Fps(60.0f), mExpected60Config},
1487 {Fps(72.0f), mExpected90Config},
1488 {Fps(90.0f), mExpected90Config},
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001489 };
1490 /* clang-format on */
1491
1492 // Make sure the test tests all the known frame rate
1493 const auto knownFrameRateList = getKnownFrameRate(*refreshRateConfigs);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001494 const auto equal =
1495 std::equal(knownFrameRateList.begin(), knownFrameRateList.end(),
1496 knownFrameRatesExpectations.begin(),
1497 [](Fps a, const ExpectedRate& b) { return a.equalsWithMargin(b.rate); });
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001498 EXPECT_TRUE(equal);
1499
1500 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1501 auto& layer = layers[0];
1502 layer.vote = LayerVoteType::Heuristic;
1503 for (const auto& expectedRate : knownFrameRatesExpectations) {
1504 layer.desiredRefreshRate = expectedRate.rate;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001505 const auto& refreshRate =
1506 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001507 EXPECT_EQ(expectedRate.expected, refreshRate);
1508 }
1509}
1510
Ana Krulecb9afd792020-06-11 13:16:15 -07001511TEST_F(RefreshRateConfigsTest, testComparisonOperator) {
1512 EXPECT_TRUE(mExpected60Config < mExpected90Config);
1513 EXPECT_FALSE(mExpected60Config < mExpected60Config);
1514 EXPECT_FALSE(mExpected90Config < mExpected90Config);
1515}
1516
1517TEST_F(RefreshRateConfigsTest, testKernelIdleTimerAction) {
1518 using KernelIdleTimerAction = scheduler::RefreshRateConfigs::KernelIdleTimerAction;
1519
1520 auto refreshRateConfigs =
1521 std::make_unique<RefreshRateConfigs>(m60_90Device,
1522 /*currentConfigId=*/HWC_CONFIG_ID_90);
1523 // SetPolicy(60, 90), current 90Hz => TurnOn.
1524 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1525
1526 // SetPolicy(60, 90), current 60Hz => TurnOn.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001527 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(90)}}),
1528 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001529 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1530
1531 // SetPolicy(60, 60), current 60Hz => NoChange, avoid extra calls.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001532 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
1533 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001534 EXPECT_EQ(KernelIdleTimerAction::NoChange, refreshRateConfigs->getIdleTimerAction());
1535
1536 // SetPolicy(90, 90), current 90Hz => TurnOff.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001537 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
1538 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001539 EXPECT_EQ(KernelIdleTimerAction::TurnOff, refreshRateConfigs->getIdleTimerAction());
1540}
1541
Ady Abraham0bb6a472020-10-12 10:22:13 -07001542TEST_F(RefreshRateConfigsTest, RefreshRateDividerForUid) {
1543 auto refreshRateConfigs =
1544 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
1545 /*currentConfigId=*/HWC_CONFIG_ID_30);
Ady Abraham62a0be22020-12-08 16:54:10 -08001546
1547 const auto frameRate = Fps(30.f);
1548 EXPECT_EQ(1, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001549
1550 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_60);
Ady Abraham62a0be22020-12-08 16:54:10 -08001551 EXPECT_EQ(2, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001552
1553 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_72);
Ady Abraham62a0be22020-12-08 16:54:10 -08001554 EXPECT_EQ(0, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001555
1556 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001557 EXPECT_EQ(3, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001558
1559 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
Ady Abraham62a0be22020-12-08 16:54:10 -08001560 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham62f216c2020-10-13 19:07:23 -07001561
1562 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001563 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.5f)));
1564 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.6f)));
1565}
1566
1567TEST_F(RefreshRateConfigsTest, populatePreferredFrameRate_noLayers) {
1568 auto refreshRateConfigs =
1569 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1570 HWC_CONFIG_ID_120);
1571
1572 auto layers = std::vector<LayerRequirement>{};
1573 ASSERT_TRUE(refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f)).empty());
1574}
1575
1576TEST_F(RefreshRateConfigsTest, getFrameRateOverrides_60on120) {
1577 auto refreshRateConfigs =
1578 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1579 HWC_CONFIG_ID_120);
1580
1581 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1582 layers[0].name = "Test layer";
1583 layers[0].ownerUid = 1234;
1584 layers[0].desiredRefreshRate = Fps(60.0f);
1585 layers[0].vote = LayerVoteType::ExplicitDefault;
1586 auto frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1587 ASSERT_EQ(1, frameRateOverrides.size());
1588 ASSERT_EQ(1, frameRateOverrides.count(1234));
1589 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1590
1591 layers[0].vote = LayerVoteType::ExplicitExactOrMultiple;
1592 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1593 ASSERT_EQ(1, frameRateOverrides.size());
1594 ASSERT_EQ(1, frameRateOverrides.count(1234));
1595 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1596
1597 layers[0].vote = LayerVoteType::NoVote;
1598 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1599 ASSERT_TRUE(frameRateOverrides.empty());
1600
1601 layers[0].vote = LayerVoteType::Min;
1602 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1603 ASSERT_TRUE(frameRateOverrides.empty());
1604
1605 layers[0].vote = LayerVoteType::Max;
1606 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1607 ASSERT_TRUE(frameRateOverrides.empty());
1608
1609 layers[0].vote = LayerVoteType::Heuristic;
1610 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1611 ASSERT_TRUE(frameRateOverrides.empty());
1612}
1613
1614TEST_F(RefreshRateConfigsTest, populatePreferredFrameRate_twoUids) {
1615 auto refreshRateConfigs =
1616 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1617 HWC_CONFIG_ID_120);
1618
1619 auto layers = std::vector<LayerRequirement>{
1620 LayerRequirement{.ownerUid = 1234, .weight = 1.0f},
1621 LayerRequirement{.ownerUid = 5678, .weight = 1.0f},
1622 };
1623
1624 layers[0].name = "Test layer 1234";
1625 layers[0].desiredRefreshRate = Fps(60.0f);
1626 layers[0].vote = LayerVoteType::ExplicitDefault;
1627
1628 layers[1].name = "Test layer 5678";
1629 layers[1].desiredRefreshRate = Fps(30.0f);
1630 layers[1].vote = LayerVoteType::ExplicitDefault;
1631 auto frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1632
1633 ASSERT_EQ(2, frameRateOverrides.size());
1634 ASSERT_EQ(1, frameRateOverrides.count(1234));
1635 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1636 ASSERT_EQ(1, frameRateOverrides.count(5678));
1637 ASSERT_EQ(30.0f, frameRateOverrides.at(5678).getValue());
1638
1639 layers[1].vote = LayerVoteType::Heuristic;
1640 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1641 ASSERT_EQ(1, frameRateOverrides.size());
1642 ASSERT_EQ(1, frameRateOverrides.count(1234));
1643 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1644
1645 layers[1].ownerUid = 1234;
1646 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1647 ASSERT_TRUE(frameRateOverrides.empty());
Ady Abraham0bb6a472020-10-12 10:22:13 -07001648}
1649
Alec Mouri0a1cc962019-03-14 12:33:02 -07001650} // namespace
1651} // namespace scheduler
1652} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001653
1654// TODO(b/129481165): remove the #pragma below and fix conversion issues
1655#pragma clang diagnostic pop // ignored "-Wextra"