blob: 738ded18acfd8742e7ff72e34379518aacaa0b9f [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
Marin Shalamanov23c44202020-12-22 19:09:20 +010075 static inline const DisplayModeId HWC_CONFIG_ID_60 = DisplayModeId(0);
76 static inline const DisplayModeId HWC_CONFIG_ID_90 = DisplayModeId(1);
77 static inline const DisplayModeId HWC_CONFIG_ID_72 = DisplayModeId(2);
78 static inline const DisplayModeId HWC_CONFIG_ID_120 = DisplayModeId(3);
79 static inline const DisplayModeId HWC_CONFIG_ID_30 = DisplayModeId(4);
80 static inline const DisplayModeId HWC_CONFIG_ID_25 = DisplayModeId(5);
81 static inline const DisplayModeId HWC_CONFIG_ID_50 = DisplayModeId(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 Shalamanov23c44202020-12-22 19:09:20 +0100147 DisplayModePtr createConfig(DisplayModeId configId, int32_t configGroup, int64_t vsyncPeriod,
148 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 Shalamanov23c44202020-12-22 19:09:20 +0100165DisplayModePtr RefreshRateConfigsTest::createConfig(DisplayModeId configId, int32_t configGroup,
166 int64_t vsyncPeriod, ui::Size resolution) {
Marin Shalamanov3ea1d602020-12-16 19:59:39 +0100167 return DisplayMode::Builder(hal::HWConfigId(configId.value()))
Marin Shalamanov23c44202020-12-22 19:09:20 +0100168 .setId(configId)
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 Shalamanov23c44202020-12-22 19:09:20 +0100190 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy({DisplayModeId(10), {Fps(60), Fps(60)}}),
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100191 0);
192 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(20), Fps(40)}}),
193 0);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100194}
195
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700196TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700197 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700198 std::make_unique<RefreshRateConfigs>(m60_90Device,
199 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700200
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100201 const auto& minRate = getMinSupportedRefreshRate(*refreshRateConfigs);
202 const auto& performanceRate = getMaxSupportedRefreshRate(*refreshRateConfigs);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700203
Ady Abrahamabc27602020-04-08 17:20:29 -0700204 ASSERT_EQ(mExpected60Config, minRate);
205 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800206
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100207 const auto& minRateByPolicy = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800208 const auto& performanceRateByPolicy = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800209 ASSERT_EQ(minRateByPolicy, minRate);
210 ASSERT_EQ(performanceRateByPolicy, performanceRate);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700211}
Ady Abraham2139f732019-11-13 18:56:40 -0800212
213TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentGroups) {
Ady Abraham2139f732019-11-13 18:56:40 -0800214 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700215 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
216 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800217
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100218 const auto& minRate = getMinRefreshRateByPolicy(*refreshRateConfigs);
219 const auto& performanceRate = getMaxSupportedRefreshRate(*refreshRateConfigs);
220 const auto& minRate60 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800221 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800222
Ady Abrahamabc27602020-04-08 17:20:29 -0700223 ASSERT_EQ(mExpected60Config, minRate);
224 ASSERT_EQ(mExpected60Config, minRate60);
225 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800226
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100227 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
228 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800229 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
230
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100231 const auto& minRate90 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abraham2e1dd892020-03-05 13:48:36 -0800232 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800233
Ady Abrahamabc27602020-04-08 17:20:29 -0700234 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate);
235 ASSERT_EQ(mExpected90DifferentGroupConfig, minRate90);
236 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate90);
237}
238
239TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentResolutions) {
240 auto refreshRateConfigs =
241 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentResolutions,
242 /*currentConfigId=*/HWC_CONFIG_ID_60);
243
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100244 const auto& minRate = getMinRefreshRateByPolicy(*refreshRateConfigs);
245 const auto& performanceRate = getMaxSupportedRefreshRate(*refreshRateConfigs);
246 const auto& minRate60 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abrahamabc27602020-04-08 17:20:29 -0700247 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
248
249 ASSERT_EQ(mExpected60Config, minRate);
250 ASSERT_EQ(mExpected60Config, minRate60);
251 ASSERT_EQ(mExpected60Config, performanceRate60);
252
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100253 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
254 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700255 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
256
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100257 const auto& minRate90 = getMinRefreshRateByPolicy(*refreshRateConfigs);
Ady Abrahamabc27602020-04-08 17:20:29 -0700258 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
259
260 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate);
261 ASSERT_EQ(mExpected90DifferentResolutionConfig, minRate90);
262 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate90);
Ady Abraham2139f732019-11-13 18:56:40 -0800263}
264
265TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_policyChange) {
Ady Abraham2139f732019-11-13 18:56:40 -0800266 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700267 std::make_unique<RefreshRateConfigs>(m60_90Device,
268 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ana Krulec3f6a2062020-01-23 15:48:01 -0800269
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100270 auto minRate = getMinRefreshRateByPolicy(*refreshRateConfigs);
271 auto performanceRate = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800272
Ady Abrahamabc27602020-04-08 17:20:29 -0700273 ASSERT_EQ(mExpected60Config, minRate);
274 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800275
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100276 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
277 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800278
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100279 auto minRate60 = getMinRefreshRateByPolicy(*refreshRateConfigs);
280 auto performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abrahamabc27602020-04-08 17:20:29 -0700281 ASSERT_EQ(mExpected60Config, minRate60);
282 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800283}
284
285TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getCurrentRefreshRate) {
Ady Abraham2139f732019-11-13 18:56:40 -0800286 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700287 std::make_unique<RefreshRateConfigs>(m60_90Device,
288 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800289 {
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100290 auto current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700291 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800292 }
293
294 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
295 {
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100296 auto current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700297 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800298 }
299
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100300 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
301 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800302 {
Marin Shalamanoveadf2e72020-12-10 15:35:28 +0100303 auto current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700304 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800305 }
306}
307
Steven Thomasbb374322020-04-28 22:47:16 -0700308TEST_F(RefreshRateConfigsTest, getBestRefreshRate_noLayers) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700309 auto refreshRateConfigs =
310 std::make_unique<RefreshRateConfigs>(m60_72_90Device, /*currentConfigId=*/
311 HWC_CONFIG_ID_72);
Ana Krulec3d367c82020-02-25 15:02:01 -0800312
Steven Thomasdebafed2020-05-18 17:30:35 -0700313 // If there are no layers we select the default frame rate, which is the max of the primary
314 // range.
Ana Krulec3d367c82020-02-25 15:02:01 -0800315 auto layers = std::vector<LayerRequirement>{};
Steven Thomasdebafed2020-05-18 17:30:35 -0700316 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700317 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800318
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100319 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
320 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700321 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700322 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800323}
324
Steven Thomasbb374322020-04-28 22:47:16 -0700325TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800326 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700327 std::make_unique<RefreshRateConfigs>(m60_90Device,
328 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800329
330 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
331 auto& lr = layers[0];
332
333 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800334 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700335 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700336 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800337
338 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800339 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700340 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700341 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800342
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100343 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800344 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800345 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700346 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700347 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800348
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100349 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800350 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700351 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700352 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800353
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100354 lr.desiredRefreshRate = Fps(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800355 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700356 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700357 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800358
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100359 lr.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800360 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700361 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700362 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800363
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100364 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800365 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700366 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700367 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800368
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800369 lr.name = "";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100370 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
371 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800372
373 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700374 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700375 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800376
377 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700378 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700379 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800380
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100381 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800382 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700383 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700384 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800385
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100386 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700387 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700388 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800389
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100390 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700391 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700392 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800393
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100394 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700395 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700396 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800397
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100398 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700399 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700400 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800401
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100402 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
403 {HWC_CONFIG_ID_90, {Fps(90.0f), Fps(90.0f)}}),
404 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800405
406 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700407 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700408 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800409
410 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700411 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700412 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800413
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100414 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800415 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700416 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700417 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800418
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100419 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700420 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700421 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800422
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100423 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700424 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700425 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800426
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100427 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700428 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700429 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800430
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100431 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700432 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700433 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800434
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100435 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
436 {HWC_CONFIG_ID_60, {Fps(0.0f), Fps(120.0f)}}),
437 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800438 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700439 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700440 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800441
442 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700443 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700444 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800445
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100446 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800447 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700448 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700449 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800450
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100451 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700452 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700453 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800454
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100455 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700456 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700457 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800458
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100459 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700460 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700461 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800462
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100463 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700464 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700465 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800466}
467
Steven Thomasbb374322020-04-28 22:47:16 -0700468TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800469 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700470 std::make_unique<RefreshRateConfigs>(m60_72_90Device,
471 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800472
473 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
474 auto& lr = layers[0];
475
476 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700477 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700478 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800479
480 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700481 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700482 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800483
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100484 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800485 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700486 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700487 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800488
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100489 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700490 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700491 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800492
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100493 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700494 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700495 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800496
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100497 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700498 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700499 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800500
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100501 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700502 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700503 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800504}
505
Steven Thomasbb374322020-04-28 22:47:16 -0700506TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90_120) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800507 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700508 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
509 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800510
511 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
512 LayerRequirement{.weight = 1.0f}};
513 auto& lr1 = layers[0];
514 auto& lr2 = layers[1];
515
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100516 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800517 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100518 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800519 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700520 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700521 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800522
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100523 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800524 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100525 lr2.desiredRefreshRate = Fps(48.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800526 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700527 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700528 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800529
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100530 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800531 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100532 lr2.desiredRefreshRate = Fps(48.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800533 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700534 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700535 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800536}
537
Steven Thomasbb374322020-04-28 22:47:16 -0700538TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_90_120_DifferentTypes) {
Ady Abraham71c437d2020-01-31 15:56:57 -0800539 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700540 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
541 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham71c437d2020-01-31 15:56:57 -0800542
543 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
544 LayerRequirement{.weight = 1.0f}};
545 auto& lr1 = layers[0];
546 auto& lr2 = layers[1];
547
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100548 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800549 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800550 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100551 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800552 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800553 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700554 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700555 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800556
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100557 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800558 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800559 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100560 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800561 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800562 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700563 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700564 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800565
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100566 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800567 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800568 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100569 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800570 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800571 lr2.name = "60Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700572 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700573 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800574
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100575 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800576 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800577 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100578 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800579 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800580 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700581 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700582 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800583
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100584 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800585 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
586 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100587 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800588 lr2.vote = LayerVoteType::ExplicitDefault;
589 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700590 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700591 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800592
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100593 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800594 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800595 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100596 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800597 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800598 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700599 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700600 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800601
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100602 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800603 lr1.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800604 lr1.name = "24Hz Heuristic";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100605 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800606 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800607 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700608 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700609 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800610
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100611 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800612 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800613 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100614 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800615 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800616 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700617 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700618 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800619
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100620 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800621 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800622 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100623 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800624 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800625 lr2.name = "90Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700626 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700627 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800628}
629
Steven Thomasbb374322020-04-28 22:47:16 -0700630TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800631 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700632 std::make_unique<RefreshRateConfigs>(m30_60Device,
633 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800634
635 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
636 auto& lr = layers[0];
637
638 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700639 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700640 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800641
642 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700643 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700644 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800645
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100646 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800647 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700648 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700649 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800650
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100651 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700652 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700653 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800654
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100655 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700656 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700657 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800658
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100659 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700660 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700661 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800662
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100663 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700664 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700665 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800666}
667
Steven Thomasbb374322020-04-28 22:47:16 -0700668TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800669 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700670 std::make_unique<RefreshRateConfigs>(m30_60_72_90Device,
671 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800672
673 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
674 auto& lr = layers[0];
675
676 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800677 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700678 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700679 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800680
681 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800682 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700683 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700684 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800685
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100686 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800687 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800688 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700689 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700690 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800691
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100692 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800693 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700694 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700695 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700696 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700697 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800698
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100699 lr.desiredRefreshRate = Fps(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800700 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700701 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700702 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700703 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700704 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800705
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100706 lr.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800707 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700708 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700709 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700710 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700711 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800712
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100713 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800714 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700715 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700716 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700717 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700718 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800719
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100720 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800721 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
722 lr.name = "24Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700723 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700724 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700725 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700726 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800727}
728
Steven Thomasbb374322020-04-28 22:47:16 -0700729TEST_F(RefreshRateConfigsTest, getBestRefreshRate_PriorityTest) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800730 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700731 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
732 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800733
734 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
735 LayerRequirement{.weight = 1.0f}};
736 auto& lr1 = layers[0];
737 auto& lr2 = layers[1];
738
739 lr1.vote = LayerVoteType::Min;
740 lr2.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700741 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700742 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800743
744 lr1.vote = LayerVoteType::Min;
745 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100746 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700747 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700748 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800749
750 lr1.vote = LayerVoteType::Min;
Ady Abraham71c437d2020-01-31 15:56:57 -0800751 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100752 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700753 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700754 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800755
756 lr1.vote = LayerVoteType::Max;
757 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100758 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700759 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700760 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800761
762 lr1.vote = LayerVoteType::Max;
Ady Abraham71c437d2020-01-31 15:56:57 -0800763 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100764 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700765 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700766 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800767
768 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100769 lr1.desiredRefreshRate = Fps(15.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800770 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100771 lr2.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700772 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700773 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800774
775 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100776 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800777 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100778 lr2.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700779 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700780 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800781}
782
Steven Thomasbb374322020-04-28 22:47:16 -0700783TEST_F(RefreshRateConfigsTest, getBestRefreshRate_24FpsVideo) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800784 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700785 std::make_unique<RefreshRateConfigs>(m60_90Device,
786 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800787
788 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
789 auto& lr = layers[0];
790
Ady Abraham71c437d2020-01-31 15:56:57 -0800791 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800792 for (float fps = 23.0f; fps < 25.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100793 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800794 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700795 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700796 EXPECT_EQ(mExpected60Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abraham8a82ba62020-01-17 12:43:17 -0800797 }
798}
799
Steven Thomasbb374322020-04-28 22:47:16 -0700800TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getBestRefreshRate_Explicit) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800801 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700802 std::make_unique<RefreshRateConfigs>(m60_90Device,
803 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800804
805 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
806 LayerRequirement{.weight = 1.0f}};
807 auto& lr1 = layers[0];
808 auto& lr2 = layers[1];
809
810 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100811 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800812 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100813 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700814 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700815 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800816
817 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100818 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800819 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100820 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700821 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700822 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800823
824 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100825 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800826 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100827 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700828 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700829 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham2139f732019-11-13 18:56:40 -0800830}
831
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800832TEST_F(RefreshRateConfigsTest, testInPolicy) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100833 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(60.000004f), Fps(60.000004f)));
834 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(59.0f), Fps(60.1f)));
835 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(75.0f), Fps(90.0f)));
836 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(60.0011f), Fps(90.0f)));
837 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(50.0f), Fps(59.998f)));
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800838}
839
Steven Thomasbb374322020-04-28 22:47:16 -0700840TEST_F(RefreshRateConfigsTest, getBestRefreshRate_75HzContent) {
Ady Abrahamf6b77072020-01-30 14:22:54 -0800841 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700842 std::make_unique<RefreshRateConfigs>(m60_90Device,
843 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abrahamf6b77072020-01-30 14:22:54 -0800844
845 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
846 auto& lr = layers[0];
847
Ady Abraham71c437d2020-01-31 15:56:57 -0800848 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abrahamf6b77072020-01-30 14:22:54 -0800849 for (float fps = 75.0f; fps < 100.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100850 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800851 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700852 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700853 EXPECT_EQ(mExpected90Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abrahamf6b77072020-01-30 14:22:54 -0800854 }
855}
856
Steven Thomasbb374322020-04-28 22:47:16 -0700857TEST_F(RefreshRateConfigsTest, getBestRefreshRate_Multiples) {
Ady Abraham34702102020-02-10 14:12:05 -0800858 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700859 std::make_unique<RefreshRateConfigs>(m60_90Device,
860 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham34702102020-02-10 14:12:05 -0800861
862 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
863 LayerRequirement{.weight = 1.0f}};
864 auto& lr1 = layers[0];
865 auto& lr2 = layers[1];
866
867 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100868 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800869 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800870 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100871 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800872 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700873 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700874 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800875
876 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100877 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800878 lr1.name = "60Hz ExplicitExactOrMultiple";
879 lr2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100880 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800881 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700882 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700883 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800884
885 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100886 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800887 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800888 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800889 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700890 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700891 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800892
893 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100894 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800895 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800896 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100897 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800898 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700899 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700900 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800901
902 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100903 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800904 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800905 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800906 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700907 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700908 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800909}
910
911TEST_F(RefreshRateConfigsTest, scrollWhileWatching60fps_60_90) {
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800912 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700913 std::make_unique<RefreshRateConfigs>(m60_90Device,
914 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800915
916 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
917 LayerRequirement{.weight = 1.0f}};
918 auto& lr1 = layers[0];
919 auto& lr2 = layers[1];
920
921 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100922 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800923 lr1.name = "60Hz ExplicitExactOrMultiple";
924 lr2.vote = LayerVoteType::NoVote;
925 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700926 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700927 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800928
929 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100930 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800931 lr1.name = "60Hz ExplicitExactOrMultiple";
932 lr2.vote = LayerVoteType::NoVote;
933 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700934 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700935 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800936
937 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100938 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800939 lr1.name = "60Hz ExplicitExactOrMultiple";
940 lr2.vote = LayerVoteType::Max;
941 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700942 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700943 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800944
945 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100946 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800947 lr1.name = "60Hz ExplicitExactOrMultiple";
948 lr2.vote = LayerVoteType::Max;
949 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700950 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700951 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800952
953 // The other layer starts to provide buffers
954 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100955 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800956 lr1.name = "60Hz ExplicitExactOrMultiple";
957 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100958 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800959 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700960 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700961 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham6fb599b2020-03-05 13:48:22 -0800962}
963
964TEST_F(RefreshRateConfigsTest, touchConsidered) {
Ady Abrahamdfd62162020-06-10 16:11:56 -0700965 RefreshRateConfigs::GlobalSignals consideredSignals;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800966 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700967 std::make_unique<RefreshRateConfigs>(m60_90Device,
968 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800969
Ady Abrahamdfd62162020-06-10 16:11:56 -0700970 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false}, &consideredSignals);
971 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800972
Ady Abrahamdfd62162020-06-10 16:11:56 -0700973 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = false}, &consideredSignals);
974 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800975
976 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
977 LayerRequirement{.weight = 1.0f}};
978 auto& lr1 = layers[0];
979 auto& lr2 = layers[1];
980
981 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100982 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800983 lr1.name = "60Hz ExplicitExactOrMultiple";
984 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100985 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -0700986 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -0700987 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
988 &consideredSignals);
989 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800990
991 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100992 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800993 lr1.name = "60Hz ExplicitExactOrMultiple";
994 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100995 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -0700996 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -0700997 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
998 &consideredSignals);
999 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001000
1001 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001002 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001003 lr1.name = "60Hz ExplicitExactOrMultiple";
1004 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001005 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001006 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001007 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1008 &consideredSignals);
1009 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001010
1011 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001012 lr1.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001013 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001014 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001015 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001016 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001017 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1018 &consideredSignals);
1019 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham34702102020-02-10 14:12:05 -08001020}
1021
Steven Thomasbb374322020-04-28 22:47:16 -07001022TEST_F(RefreshRateConfigsTest, getBestRefreshRate_ExplicitDefault) {
Ady Abrahamabc27602020-04-08 17:20:29 -07001023 auto refreshRateConfigs =
1024 std::make_unique<RefreshRateConfigs>(m60_90_72_120Device, /*currentConfigId=*/
1025 HWC_CONFIG_ID_60);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001026
1027 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1028 auto& lr = layers[0];
1029
1030 // Prepare a table with the vote and the expected refresh rate
1031 const std::vector<std::pair<float, float>> testCases = {
1032 {130, 120}, {120, 120}, {119, 120}, {110, 120},
1033
1034 {100, 90}, {90, 90}, {89, 90},
1035
1036 {80, 72}, {73, 72}, {72, 72}, {71, 72}, {70, 72},
1037
1038 {65, 60}, {60, 60}, {59, 60}, {58, 60},
1039
1040 {55, 90}, {50, 90}, {45, 90},
1041
1042 {42, 120}, {40, 120}, {39, 120},
1043
1044 {37, 72}, {36, 72}, {35, 72},
1045
1046 {30, 60},
1047 };
1048
1049 for (const auto& test : testCases) {
1050 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001051 lr.desiredRefreshRate = Fps(test.first);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001052
1053 std::stringstream ss;
1054 ss << "ExplicitDefault " << test.first << " fps";
1055 lr.name = ss.str();
1056
1057 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -07001058 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001059 EXPECT_TRUE(refreshRate.getFps().equalsWithMargin(Fps(test.second)))
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001060 << "Expecting " << test.first << "fps => " << test.second << "Hz";
1061 }
Alec Mouri0a1cc962019-03-14 12:33:02 -07001062}
1063
Alec Mouri11232a22020-05-14 18:06:25 -07001064TEST_F(RefreshRateConfigsTest,
1065 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresTouchFlag) {
1066 auto refreshRateConfigs =
1067 std::make_unique<RefreshRateConfigs>(m60_90Device,
1068 /*currentConfigId=*/HWC_CONFIG_ID_90);
1069
1070 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001071 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001072 0);
1073
1074 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1075 auto& lr = layers[0];
1076
Ady Abrahamdfd62162020-06-10 16:11:56 -07001077 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001078 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001079 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001080 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001081 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001082 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001083 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = true},
1084 &consideredSignals));
1085 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001086}
1087
1088TEST_F(RefreshRateConfigsTest,
1089 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresIdleFlag) {
1090 auto refreshRateConfigs =
1091 std::make_unique<RefreshRateConfigs>(m60_90Device,
1092 /*currentConfigId=*/HWC_CONFIG_ID_60);
1093
1094 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001095 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001096 0);
1097
1098 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1099 auto& lr = layers[0];
1100
Alec Mouri11232a22020-05-14 18:06:25 -07001101 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001102 lr.desiredRefreshRate = Fps(90.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001103 lr.name = "90Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001104 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001105 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001106 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = true}));
Alec Mouri11232a22020-05-14 18:06:25 -07001107}
1108
1109TEST_F(RefreshRateConfigsTest,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001110 getBestRefreshRate_withDisplayManagerRequestingSingleRate_onlySwitchesRatesForExplicitFocusedLayers) {
Alec Mouri11232a22020-05-14 18:06:25 -07001111 auto refreshRateConfigs =
1112 std::make_unique<RefreshRateConfigs>(m60_90Device,
1113 /*currentConfigId=*/HWC_CONFIG_ID_90);
1114
1115 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001116 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001117 0);
1118
Ady Abrahamdfd62162020-06-10 16:11:56 -07001119 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001120 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001121 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false},
1122 &consideredSignals));
1123 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001124
1125 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1126 auto& lr = layers[0];
1127
1128 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001129 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001130 lr.name = "60Hz ExplicitExactOrMultiple";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001131 lr.focused = false;
1132 EXPECT_EQ(mExpected90Config,
1133 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1134
1135 lr.focused = true;
Ady Abraham20c029c2020-07-06 12:58:05 -07001136 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001137 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001138
1139 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001140 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001141 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001142 lr.focused = false;
1143 EXPECT_EQ(mExpected90Config,
1144 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1145
1146 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001147 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001148 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001149
1150 lr.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001151 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001152 lr.name = "60Hz Heuristic";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001153 lr.focused = false;
1154 EXPECT_EQ(mExpected90Config,
1155 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1156
1157 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001158 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001159 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001160
1161 lr.vote = LayerVoteType::Max;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001162 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001163 lr.name = "60Hz Max";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001164 lr.focused = false;
1165 EXPECT_EQ(mExpected90Config,
1166 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1167
1168 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001169 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001170 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001171
1172 lr.vote = LayerVoteType::Min;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001173 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001174 lr.name = "60Hz Min";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001175 lr.focused = false;
1176 EXPECT_EQ(mExpected90Config,
1177 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1178
1179 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001180 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001181 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001182}
1183
Steven Thomasd4071902020-03-24 16:02:53 -07001184TEST_F(RefreshRateConfigsTest, groupSwitching) {
Steven Thomasd4071902020-03-24 16:02:53 -07001185 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -07001186 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
1187 /*currentConfigId=*/HWC_CONFIG_ID_60);
Steven Thomasd4071902020-03-24 16:02:53 -07001188
1189 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1190 auto& layer = layers[0];
1191 layer.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001192 layer.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001193 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Steven Thomasd4071902020-03-24 16:02:53 -07001194 layer.name = "90Hz ExplicitDefault";
Marin Shalamanov46084422020-10-13 12:33:42 +02001195 layer.focused = true;
Steven Thomasd4071902020-03-24 16:02:53 -07001196
Steven Thomasd4071902020-03-24 16:02:53 -07001197 ASSERT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001198 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001199 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001200
1201 RefreshRateConfigs::Policy policy;
1202 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1203 policy.allowGroupSwitching = true;
1204 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1205 ASSERT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001206 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001207 .getConfigId());
Marin Shalamanov46084422020-10-13 12:33:42 +02001208
1209 // Verify that we won't change the group if seamless switch is required.
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001210 layer.seamlessness = Seamlessness::OnlySeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001211 ASSERT_EQ(HWC_CONFIG_ID_60,
1212 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1213 .getConfigId());
1214
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001215 // 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 +02001216 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001217 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001218 layer.name = "60Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001219 layer.seamlessness = Seamlessness::OnlySeamless;
1220 ASSERT_EQ(HWC_CONFIG_ID_90,
1221 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1222 .getConfigId());
1223
1224 // Verify that if the current config is in another group and there are no layers with
1225 // seamlessness=SeamedAndSeamless we'll go back to the default group.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001226 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001227 layer.name = "60Hz ExplicitDefault";
1228 layer.seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001229 ASSERT_EQ(HWC_CONFIG_ID_60,
1230 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1231 .getConfigId());
1232
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001233 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1234 // seamlessness=OnlySeamless can't change the config group.
Marin Shalamanov46084422020-10-13 12:33:42 +02001235 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001236 layer.seamlessness = Seamlessness::OnlySeamless;
1237
1238 layers.push_back(LayerRequirement{.weight = 0.5f});
1239 auto& layer2 = layers[layers.size() - 1];
Marin Shalamanov46084422020-10-13 12:33:42 +02001240 layer2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001241 layer2.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001242 layer2.name = "90Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001243 layer2.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001244 layer2.focused = false;
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001245
1246 ASSERT_EQ(HWC_CONFIG_ID_90,
1247 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1248 .getConfigId());
1249
1250 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1251 // seamlessness=Default can't change the config group.
1252 layers[0].seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001253 ASSERT_EQ(HWC_CONFIG_ID_90,
1254 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1255 .getConfigId());
1256}
1257
1258TEST_F(RefreshRateConfigsTest, nonSeamlessVotePrefersSeamlessSwitches) {
1259 auto refreshRateConfigs =
1260 std::make_unique<RefreshRateConfigs>(m30_60Device,
1261 /*currentConfigId=*/HWC_CONFIG_ID_60);
1262
1263 // Allow group switching.
1264 RefreshRateConfigs::Policy policy;
1265 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1266 policy.allowGroupSwitching = true;
1267 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1268
1269 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1270 auto& layer = layers[0];
1271 layer.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001272 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001273 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001274 layer.name = "60Hz ExplicitExactOrMultiple";
1275 layer.focused = true;
1276
1277 ASSERT_EQ(HWC_CONFIG_ID_60,
1278 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1279 .getConfigId());
1280
1281 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
1282 ASSERT_EQ(HWC_CONFIG_ID_120,
1283 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1284 .getConfigId());
1285}
1286
1287TEST_F(RefreshRateConfigsTest, nonSeamlessExactAndSeamlessMultipleLayers) {
1288 auto refreshRateConfigs =
1289 std::make_unique<RefreshRateConfigs>(m25_30_50_60Device,
1290 /*currentConfigId=*/HWC_CONFIG_ID_60);
1291
1292 // Allow group switching.
1293 RefreshRateConfigs::Policy policy;
1294 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1295 policy.allowGroupSwitching = true;
1296 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1297
1298 auto layers = std::vector<
1299 LayerRequirement>{LayerRequirement{.name = "60Hz ExplicitDefault",
1300 .vote = LayerVoteType::ExplicitDefault,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001301 .desiredRefreshRate = Fps(60.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001302 .seamlessness = Seamlessness::SeamedAndSeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001303 .weight = 0.5f,
1304 .focused = false},
1305 LayerRequirement{.name = "25Hz ExplicitExactOrMultiple",
1306 .vote = LayerVoteType::ExplicitExactOrMultiple,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001307 .desiredRefreshRate = Fps(25.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001308 .seamlessness = Seamlessness::OnlySeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001309 .weight = 1.0f,
1310 .focused = true}};
1311 auto& seamedLayer = layers[0];
1312
1313 ASSERT_EQ(HWC_CONFIG_ID_50,
1314 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1315 .getConfigId());
1316
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001317 seamedLayer.name = "30Hz ExplicitDefault", seamedLayer.desiredRefreshRate = Fps(30.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001318 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_30);
1319
1320 ASSERT_EQ(HWC_CONFIG_ID_25,
1321 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1322 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001323}
1324
Steven Thomasf734df42020-04-13 21:09:28 -07001325TEST_F(RefreshRateConfigsTest, primaryVsAppRequestPolicy) {
1326 auto refreshRateConfigs =
Alec Mouri11232a22020-05-14 18:06:25 -07001327 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
Steven Thomasf734df42020-04-13 21:09:28 -07001328 /*currentConfigId=*/HWC_CONFIG_ID_60);
1329
1330 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1331 layers[0].name = "Test layer";
1332
Steven Thomasbb374322020-04-28 22:47:16 -07001333 // Return the config ID from calling getBestRefreshRate() for a single layer with the
Steven Thomasf734df42020-04-13 21:09:28 -07001334 // given voteType and fps.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001335 auto getFrameRate = [&](LayerVoteType voteType, Fps fps, bool touchActive = false,
Marin Shalamanov23c44202020-12-22 19:09:20 +01001336 bool focused = true) -> DisplayModeId {
Steven Thomasf734df42020-04-13 21:09:28 -07001337 layers[0].vote = voteType;
1338 layers[0].desiredRefreshRate = fps;
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001339 layers[0].focused = focused;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001340 return refreshRateConfigs->getBestRefreshRate(layers, {.touch = touchActive, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001341 .getConfigId();
1342 };
1343
1344 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001345 {HWC_CONFIG_ID_60, {Fps(30.f), Fps(60.f)}, {Fps(30.f), Fps(90.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001346 0);
Steven Thomasf734df42020-04-13 21:09:28 -07001347 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001348 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001349 .getConfigId());
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001350 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1351 EXPECT_EQ(HWC_CONFIG_ID_30, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1352 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1353 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1354 EXPECT_EQ(HWC_CONFIG_ID_90, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1355 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001356
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001357 // Layers not focused are not allowed to override primary config
1358 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001359 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001360 /*focused=*/false));
1361 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001362 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001363 /*focused=*/false));
1364
Steven Thomasf734df42020-04-13 21:09:28 -07001365 // Touch boost should be restricted to the primary range.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001366 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001367 // When we're higher than the primary range max due to a layer frame rate setting, touch boost
1368 // shouldn't drag us back down to the primary range max.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001369 EXPECT_EQ(HWC_CONFIG_ID_90,
1370 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/true));
Ady Abraham20c029c2020-07-06 12:58:05 -07001371 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001372 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001373
1374 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001375 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(60.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001376 0);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001377 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1378 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1379 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1380 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1381 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1382 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001383}
1384
Steven Thomasbb374322020-04-28 22:47:16 -07001385TEST_F(RefreshRateConfigsTest, idle) {
1386 auto refreshRateConfigs =
1387 std::make_unique<RefreshRateConfigs>(m60_90Device,
1388 /*currentConfigId=*/HWC_CONFIG_ID_60);
1389
1390 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1391 layers[0].name = "Test layer";
1392
Marin Shalamanov23c44202020-12-22 19:09:20 +01001393 const auto getIdleFrameRate = [&](LayerVoteType voteType, bool touchActive) -> DisplayModeId {
Steven Thomasbb374322020-04-28 22:47:16 -07001394 layers[0].vote = voteType;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001395 layers[0].desiredRefreshRate = Fps(90.f);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001396 RefreshRateConfigs::GlobalSignals consideredSignals;
1397 const auto configId =
1398 refreshRateConfigs
1399 ->getBestRefreshRate(layers, {.touch = touchActive, .idle = true},
1400 &consideredSignals)
1401 .getConfigId();
1402 // Refresh rate will be chosen by either touch state or idle state
1403 EXPECT_EQ(!touchActive, consideredSignals.idle);
1404 return configId;
Steven Thomasbb374322020-04-28 22:47:16 -07001405 };
1406
1407 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001408 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Steven Thomasbb374322020-04-28 22:47:16 -07001409 0);
1410
1411 // Idle should be lower priority than touch boost.
Ady Abrahamdfd62162020-06-10 16:11:56 -07001412 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/true));
1413 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/true));
1414 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/true));
1415 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/true));
1416 EXPECT_EQ(HWC_CONFIG_ID_90,
1417 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/true));
1418 EXPECT_EQ(HWC_CONFIG_ID_90,
1419 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/true));
Steven Thomasbb374322020-04-28 22:47:16 -07001420
1421 // With no layers, idle should still be lower priority than touch boost.
Steven Thomasbb374322020-04-28 22:47:16 -07001422 EXPECT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001423 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001424 .getConfigId());
1425
1426 // Idle should be higher precedence than other layer frame rate considerations.
1427 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001428 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/false));
1429 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/false));
1430 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/false));
1431 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/false));
1432 EXPECT_EQ(HWC_CONFIG_ID_60,
1433 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/false));
1434 EXPECT_EQ(HWC_CONFIG_ID_60,
1435 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/false));
Steven Thomasbb374322020-04-28 22:47:16 -07001436
1437 // Idle should be applied rather than the current config when there are no layers.
1438 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001439 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001440 .getConfigId());
1441}
1442
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001443TEST_F(RefreshRateConfigsTest, findClosestKnownFrameRate) {
1444 auto refreshRateConfigs =
1445 std::make_unique<RefreshRateConfigs>(m60_90Device,
1446 /*currentConfigId=*/HWC_CONFIG_ID_60);
1447
1448 for (float fps = 1.0f; fps <= 120.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001449 const auto knownFrameRate = findClosestKnownFrameRate(*refreshRateConfigs, Fps(fps));
1450 Fps expectedFrameRate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001451 if (fps < 26.91f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001452 expectedFrameRate = Fps(24.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001453 } else if (fps < 37.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001454 expectedFrameRate = Fps(30.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001455 } else if (fps < 52.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001456 expectedFrameRate = Fps(45.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001457 } else if (fps < 66.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001458 expectedFrameRate = Fps(60.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001459 } else if (fps < 81.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001460 expectedFrameRate = Fps(72.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001461 } else {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001462 expectedFrameRate = Fps(90.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001463 }
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001464 EXPECT_TRUE(expectedFrameRate.equalsWithMargin(knownFrameRate))
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001465 << "findClosestKnownFrameRate(" << fps << ") = " << knownFrameRate;
1466 }
1467}
1468
1469TEST_F(RefreshRateConfigsTest, getBestRefreshRate_KnownFrameRate) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001470 auto refreshRateConfigs =
1471 std::make_unique<RefreshRateConfigs>(m60_90Device,
1472 /*currentConfigId=*/HWC_CONFIG_ID_60);
1473
1474 struct ExpectedRate {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001475 Fps rate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001476 const RefreshRate& expected;
1477 };
1478
1479 /* clang-format off */
1480 std::vector<ExpectedRate> knownFrameRatesExpectations = {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001481 {Fps(24.0f), mExpected60Config},
1482 {Fps(30.0f), mExpected60Config},
1483 {Fps(45.0f), mExpected90Config},
1484 {Fps(60.0f), mExpected60Config},
1485 {Fps(72.0f), mExpected90Config},
1486 {Fps(90.0f), mExpected90Config},
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001487 };
1488 /* clang-format on */
1489
1490 // Make sure the test tests all the known frame rate
1491 const auto knownFrameRateList = getKnownFrameRate(*refreshRateConfigs);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001492 const auto equal =
1493 std::equal(knownFrameRateList.begin(), knownFrameRateList.end(),
1494 knownFrameRatesExpectations.begin(),
1495 [](Fps a, const ExpectedRate& b) { return a.equalsWithMargin(b.rate); });
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001496 EXPECT_TRUE(equal);
1497
1498 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1499 auto& layer = layers[0];
1500 layer.vote = LayerVoteType::Heuristic;
1501 for (const auto& expectedRate : knownFrameRatesExpectations) {
1502 layer.desiredRefreshRate = expectedRate.rate;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001503 const auto& refreshRate =
1504 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001505 EXPECT_EQ(expectedRate.expected, refreshRate);
1506 }
1507}
1508
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001509TEST_F(RefreshRateConfigsTest, getBestRefreshRate_ExplicitExact) {
1510 auto refreshRateConfigs =
1511 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
1512 /*currentConfigId=*/HWC_CONFIG_ID_60);
1513
1514 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
1515 LayerRequirement{.weight = 0.5f}};
1516 auto& explicitExactLayer = layers[0];
1517 auto& explicitExactOrMultipleLayer = layers[1];
1518
1519 explicitExactOrMultipleLayer.vote = LayerVoteType::ExplicitExactOrMultiple;
1520 explicitExactOrMultipleLayer.name = "ExplicitExactOrMultiple";
1521 explicitExactOrMultipleLayer.desiredRefreshRate = Fps(60);
1522
1523 explicitExactLayer.vote = LayerVoteType::ExplicitExact;
1524 explicitExactLayer.name = "ExplicitExact";
1525 explicitExactLayer.desiredRefreshRate = Fps(30);
1526
1527 EXPECT_EQ(mExpected30Config,
1528 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1529 EXPECT_EQ(mExpected30Config,
1530 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
1531
1532 explicitExactOrMultipleLayer.desiredRefreshRate = Fps(120);
1533 explicitExactLayer.desiredRefreshRate = Fps(60);
1534 EXPECT_EQ(mExpected60Config,
1535 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1536
1537 explicitExactLayer.desiredRefreshRate = Fps(72);
1538 EXPECT_EQ(mExpected72Config,
1539 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1540
1541 explicitExactLayer.desiredRefreshRate = Fps(90);
1542 EXPECT_EQ(mExpected90Config,
1543 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1544
1545 explicitExactLayer.desiredRefreshRate = Fps(120);
1546 EXPECT_EQ(mExpected120Config,
1547 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1548}
1549
1550TEST_F(RefreshRateConfigsTest, getBestRefreshRate_ExplicitExactEnableFrameRateOverride) {
1551 auto refreshRateConfigs =
1552 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
1553 /*currentConfigId=*/HWC_CONFIG_ID_60,
1554 /*enableFrameRateOverride=*/true);
1555
1556 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
1557 LayerRequirement{.weight = 0.5f}};
1558 auto& explicitExactLayer = layers[0];
1559 auto& explicitExactOrMultipleLayer = layers[1];
1560
1561 explicitExactOrMultipleLayer.vote = LayerVoteType::ExplicitExactOrMultiple;
1562 explicitExactOrMultipleLayer.name = "ExplicitExactOrMultiple";
1563 explicitExactOrMultipleLayer.desiredRefreshRate = Fps(60);
1564
1565 explicitExactLayer.vote = LayerVoteType::ExplicitExact;
1566 explicitExactLayer.name = "ExplicitExact";
1567 explicitExactLayer.desiredRefreshRate = Fps(30);
1568
1569 EXPECT_EQ(mExpected60Config,
1570 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1571 EXPECT_EQ(mExpected120Config,
1572 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
1573
1574 explicitExactOrMultipleLayer.desiredRefreshRate = Fps(120);
1575 explicitExactLayer.desiredRefreshRate = Fps(60);
1576 EXPECT_EQ(mExpected120Config,
1577 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1578
1579 explicitExactLayer.desiredRefreshRate = Fps(72);
1580 EXPECT_EQ(mExpected72Config,
1581 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1582
1583 explicitExactLayer.desiredRefreshRate = Fps(90);
1584 EXPECT_EQ(mExpected90Config,
1585 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1586
1587 explicitExactLayer.desiredRefreshRate = Fps(120);
1588 EXPECT_EQ(mExpected120Config,
1589 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1590}
1591
Ana Krulecb9afd792020-06-11 13:16:15 -07001592TEST_F(RefreshRateConfigsTest, testComparisonOperator) {
1593 EXPECT_TRUE(mExpected60Config < mExpected90Config);
1594 EXPECT_FALSE(mExpected60Config < mExpected60Config);
1595 EXPECT_FALSE(mExpected90Config < mExpected90Config);
1596}
1597
1598TEST_F(RefreshRateConfigsTest, testKernelIdleTimerAction) {
1599 using KernelIdleTimerAction = scheduler::RefreshRateConfigs::KernelIdleTimerAction;
1600
1601 auto refreshRateConfigs =
1602 std::make_unique<RefreshRateConfigs>(m60_90Device,
1603 /*currentConfigId=*/HWC_CONFIG_ID_90);
1604 // SetPolicy(60, 90), current 90Hz => TurnOn.
1605 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1606
1607 // SetPolicy(60, 90), current 60Hz => TurnOn.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001608 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(90)}}),
1609 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001610 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1611
1612 // SetPolicy(60, 60), current 60Hz => NoChange, avoid extra calls.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001613 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
1614 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001615 EXPECT_EQ(KernelIdleTimerAction::NoChange, refreshRateConfigs->getIdleTimerAction());
1616
1617 // SetPolicy(90, 90), current 90Hz => TurnOff.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001618 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
1619 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001620 EXPECT_EQ(KernelIdleTimerAction::TurnOff, refreshRateConfigs->getIdleTimerAction());
1621}
1622
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001623TEST_F(RefreshRateConfigsTest, getRefreshRateDivider) {
Ady Abraham0bb6a472020-10-12 10:22:13 -07001624 auto refreshRateConfigs =
1625 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
1626 /*currentConfigId=*/HWC_CONFIG_ID_30);
Ady Abraham62a0be22020-12-08 16:54:10 -08001627
1628 const auto frameRate = Fps(30.f);
1629 EXPECT_EQ(1, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001630
1631 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_60);
Ady Abraham62a0be22020-12-08 16:54:10 -08001632 EXPECT_EQ(2, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001633
1634 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_72);
Ady Abraham62a0be22020-12-08 16:54:10 -08001635 EXPECT_EQ(0, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001636
1637 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001638 EXPECT_EQ(3, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001639
1640 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
Ady Abraham62a0be22020-12-08 16:54:10 -08001641 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham62f216c2020-10-13 19:07:23 -07001642
1643 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001644 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.5f)));
1645 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.6f)));
1646}
1647
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001648TEST_F(RefreshRateConfigsTest, getFrameRateOverrides_noLayers) {
Ady Abraham62a0be22020-12-08 16:54:10 -08001649 auto refreshRateConfigs =
1650 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1651 HWC_CONFIG_ID_120);
1652
1653 auto layers = std::vector<LayerRequirement>{};
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001654 ASSERT_TRUE(refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false)
1655 .empty());
Ady Abraham62a0be22020-12-08 16:54:10 -08001656}
1657
1658TEST_F(RefreshRateConfigsTest, getFrameRateOverrides_60on120) {
1659 auto refreshRateConfigs =
1660 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001661 HWC_CONFIG_ID_120,
1662 /*enableFrameRateOverride=*/true);
Ady Abraham62a0be22020-12-08 16:54:10 -08001663
1664 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1665 layers[0].name = "Test layer";
1666 layers[0].ownerUid = 1234;
1667 layers[0].desiredRefreshRate = Fps(60.0f);
1668 layers[0].vote = LayerVoteType::ExplicitDefault;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001669 auto frameRateOverrides =
1670 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
Ady Abraham62a0be22020-12-08 16:54:10 -08001671 ASSERT_EQ(1, frameRateOverrides.size());
1672 ASSERT_EQ(1, frameRateOverrides.count(1234));
1673 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1674
1675 layers[0].vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001676 frameRateOverrides =
1677 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
Ady Abraham62a0be22020-12-08 16:54:10 -08001678 ASSERT_EQ(1, frameRateOverrides.size());
1679 ASSERT_EQ(1, frameRateOverrides.count(1234));
1680 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1681
1682 layers[0].vote = LayerVoteType::NoVote;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001683 frameRateOverrides =
1684 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
Ady Abraham62a0be22020-12-08 16:54:10 -08001685 ASSERT_TRUE(frameRateOverrides.empty());
1686
1687 layers[0].vote = LayerVoteType::Min;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001688 frameRateOverrides =
1689 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
Ady Abraham62a0be22020-12-08 16:54:10 -08001690 ASSERT_TRUE(frameRateOverrides.empty());
1691
1692 layers[0].vote = LayerVoteType::Max;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001693 frameRateOverrides =
1694 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
Ady Abraham62a0be22020-12-08 16:54:10 -08001695 ASSERT_TRUE(frameRateOverrides.empty());
1696
1697 layers[0].vote = LayerVoteType::Heuristic;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001698 frameRateOverrides =
1699 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
Ady Abraham62a0be22020-12-08 16:54:10 -08001700 ASSERT_TRUE(frameRateOverrides.empty());
1701}
1702
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001703TEST_F(RefreshRateConfigsTest, getFrameRateOverrides_twoUids) {
Ady Abraham62a0be22020-12-08 16:54:10 -08001704 auto refreshRateConfigs =
1705 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001706 HWC_CONFIG_ID_120,
1707 /*enableFrameRateOverride=*/true);
Ady Abraham62a0be22020-12-08 16:54:10 -08001708
1709 auto layers = std::vector<LayerRequirement>{
1710 LayerRequirement{.ownerUid = 1234, .weight = 1.0f},
1711 LayerRequirement{.ownerUid = 5678, .weight = 1.0f},
1712 };
1713
1714 layers[0].name = "Test layer 1234";
1715 layers[0].desiredRefreshRate = Fps(60.0f);
1716 layers[0].vote = LayerVoteType::ExplicitDefault;
1717
1718 layers[1].name = "Test layer 5678";
1719 layers[1].desiredRefreshRate = Fps(30.0f);
1720 layers[1].vote = LayerVoteType::ExplicitDefault;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001721 auto frameRateOverrides =
1722 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
Ady Abraham62a0be22020-12-08 16:54:10 -08001723
1724 ASSERT_EQ(2, frameRateOverrides.size());
1725 ASSERT_EQ(1, frameRateOverrides.count(1234));
1726 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1727 ASSERT_EQ(1, frameRateOverrides.count(5678));
1728 ASSERT_EQ(30.0f, frameRateOverrides.at(5678).getValue());
1729
1730 layers[1].vote = LayerVoteType::Heuristic;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001731 frameRateOverrides =
1732 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
Ady Abraham62a0be22020-12-08 16:54:10 -08001733 ASSERT_EQ(1, frameRateOverrides.size());
1734 ASSERT_EQ(1, frameRateOverrides.count(1234));
1735 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1736
1737 layers[1].ownerUid = 1234;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001738 frameRateOverrides =
1739 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
1740 ASSERT_TRUE(frameRateOverrides.empty());
1741}
1742
1743TEST_F(RefreshRateConfigsTest, getFrameRateOverrides_touch) {
1744 auto refreshRateConfigs =
1745 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1746 HWC_CONFIG_ID_120,
1747 /*enableFrameRateOverride=*/true);
1748
1749 auto layers = std::vector<LayerRequirement>{
1750 LayerRequirement{.ownerUid = 1234, .weight = 1.0f},
1751 };
1752
1753 layers[0].name = "Test layer";
1754 layers[0].desiredRefreshRate = Fps(60.0f);
1755 layers[0].vote = LayerVoteType::ExplicitDefault;
1756
1757 auto frameRateOverrides =
1758 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
1759 ASSERT_EQ(1, frameRateOverrides.size());
1760 ASSERT_EQ(1, frameRateOverrides.count(1234));
1761 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1762
1763 frameRateOverrides =
1764 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/true);
1765 ASSERT_EQ(1, frameRateOverrides.size());
1766 ASSERT_EQ(1, frameRateOverrides.count(1234));
1767 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1768
1769 layers[0].vote = LayerVoteType::ExplicitExact;
1770 frameRateOverrides =
1771 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
1772 ASSERT_EQ(1, frameRateOverrides.size());
1773 ASSERT_EQ(1, frameRateOverrides.count(1234));
1774 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1775
1776 frameRateOverrides =
1777 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/true);
1778 ASSERT_EQ(1, frameRateOverrides.size());
1779 ASSERT_EQ(1, frameRateOverrides.count(1234));
1780 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1781
1782 layers[0].vote = LayerVoteType::ExplicitExactOrMultiple;
1783 frameRateOverrides =
1784 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/false);
1785 ASSERT_EQ(1, frameRateOverrides.size());
1786 ASSERT_EQ(1, frameRateOverrides.count(1234));
1787 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1788
1789 frameRateOverrides =
1790 refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f), /*touch=*/true);
Ady Abraham62a0be22020-12-08 16:54:10 -08001791 ASSERT_TRUE(frameRateOverrides.empty());
Ady Abraham0bb6a472020-10-12 10:22:13 -07001792}
1793
Alec Mouri0a1cc962019-03-14 12:33:02 -07001794} // namespace
1795} // namespace scheduler
1796} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001797
1798// TODO(b/129481165): remove the #pragma below and fix conversion issues
1799#pragma clang diagnostic pop // ignored "-Wextra"