blob: 29be5aba47ef4995304e5970e7000745b80daf4d [file] [log] [blame]
Alec Mouri0a1cc962019-03-14 12:33:02 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#undef LOG_TAG
18#define LOG_TAG "SchedulerUnittests"
19
20#include <gmock/gmock.h>
21#include <log/log.h>
22#include <thread>
23
Ady Abraham6fb599b2020-03-05 13:48:22 -080024#include "../../Scheduler/RefreshRateConfigs.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070025#include "DisplayHardware/HWC2.h"
26#include "Scheduler/RefreshRateConfigs.h"
Ady Abrahamabc27602020-04-08 17:20:29 -070027#include "mock/DisplayHardware/MockDisplay.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070028
29using namespace std::chrono_literals;
30using testing::_;
31
32namespace android {
Marin Shalamanove8a663d2020-11-24 17:48:00 +010033
Alec Mouri0a1cc962019-03-14 12:33:02 -070034namespace scheduler {
35
Peiyong Line9d809e2020-04-14 13:10:48 -070036namespace hal = android::hardware::graphics::composer::hal;
37
Alec Mouri0a1cc962019-03-14 12:33:02 -070038using RefreshRate = RefreshRateConfigs::RefreshRate;
Ady Abraham8a82ba62020-01-17 12:43:17 -080039using LayerVoteType = RefreshRateConfigs::LayerVoteType;
40using LayerRequirement = RefreshRateConfigs::LayerRequirement;
Alec Mouri0a1cc962019-03-14 12:33:02 -070041
42class RefreshRateConfigsTest : public testing::Test {
43protected:
Alec Mouri0a1cc962019-03-14 12:33:02 -070044 RefreshRateConfigsTest();
45 ~RefreshRateConfigsTest();
Ady Abrahamabc27602020-04-08 17:20:29 -070046
Marin Shalamanove8a663d2020-11-24 17:48:00 +010047 Fps findClosestKnownFrameRate(const RefreshRateConfigs& refreshRateConfigs, Fps frameRate) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -070048 return refreshRateConfigs.findClosestKnownFrameRate(frameRate);
49 }
50
Marin Shalamanove8a663d2020-11-24 17:48:00 +010051 std::vector<Fps> getKnownFrameRate(const RefreshRateConfigs& refreshRateConfigs) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -070052 return refreshRateConfigs.mKnownFrameRates;
53 }
54
Ady Abrahamabc27602020-04-08 17:20:29 -070055 // Test config IDs
56 static inline const HwcConfigIndexType HWC_CONFIG_ID_60 = HwcConfigIndexType(0);
57 static inline const HwcConfigIndexType HWC_CONFIG_ID_90 = HwcConfigIndexType(1);
58 static inline const HwcConfigIndexType HWC_CONFIG_ID_72 = HwcConfigIndexType(2);
59 static inline const HwcConfigIndexType HWC_CONFIG_ID_120 = HwcConfigIndexType(3);
60 static inline const HwcConfigIndexType HWC_CONFIG_ID_30 = HwcConfigIndexType(4);
Marin Shalamanov46084422020-10-13 12:33:42 +020061 static inline const HwcConfigIndexType HWC_CONFIG_ID_25 = HwcConfigIndexType(5);
62 static inline const HwcConfigIndexType HWC_CONFIG_ID_50 = HwcConfigIndexType(6);
Ady Abrahamabc27602020-04-08 17:20:29 -070063
64 // Test configs
65 std::shared_ptr<const HWC2::Display::Config> mConfig60 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010066 createConfig(HWC_CONFIG_ID_60, 0, Fps(60.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070067 std::shared_ptr<const HWC2::Display::Config> mConfig90 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010068 createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070069 std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010070 createConfig(HWC_CONFIG_ID_90, 1, Fps(90.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070071 std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentResolution =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010072 createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs(), 111, 222);
Ady Abrahamabc27602020-04-08 17:20:29 -070073 std::shared_ptr<const HWC2::Display::Config> mConfig72 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010074 createConfig(HWC_CONFIG_ID_72, 0, Fps(72.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070075 std::shared_ptr<const HWC2::Display::Config> mConfig72DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010076 createConfig(HWC_CONFIG_ID_72, 1, Fps(72.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070077 std::shared_ptr<const HWC2::Display::Config> mConfig120 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010078 createConfig(HWC_CONFIG_ID_120, 0, Fps(120.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070079 std::shared_ptr<const HWC2::Display::Config> mConfig120DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010080 createConfig(HWC_CONFIG_ID_120, 1, Fps(120.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070081 std::shared_ptr<const HWC2::Display::Config> mConfig30 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010082 createConfig(HWC_CONFIG_ID_30, 0, Fps(30.0f).getPeriodNsecs());
Marin Shalamanov46084422020-10-13 12:33:42 +020083 std::shared_ptr<const HWC2::Display::Config> mConfig30DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010084 createConfig(HWC_CONFIG_ID_30, 1, Fps(30.0f).getPeriodNsecs());
Marin Shalamanov46084422020-10-13 12:33:42 +020085 std::shared_ptr<const HWC2::Display::Config> mConfig25DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010086 createConfig(HWC_CONFIG_ID_25, 1, Fps(25.0f).getPeriodNsecs());
Marin Shalamanov46084422020-10-13 12:33:42 +020087 std::shared_ptr<const HWC2::Display::Config> mConfig50 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010088 createConfig(HWC_CONFIG_ID_50, 0, Fps(50.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070089
90 // Test device configurations
Marin Shalamanov46084422020-10-13 12:33:42 +020091 // The positions of the configs in the arrays below MUST match their IDs. For example,
92 // the first config should always be 60Hz, the second 90Hz etc.
Ady Abrahamabc27602020-04-08 17:20:29 -070093 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60OnlyConfigDevice = {mConfig60};
94 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90Device = {mConfig60, mConfig90};
95 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentGroups =
96 {mConfig60, mConfig90DifferentGroup};
97 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentResolutions =
98 {mConfig60, mConfig90DifferentResolution};
99 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_72_90Device = {mConfig60,
100 mConfig90,
101 mConfig72};
102 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90_72_120Device = {mConfig60,
103 mConfig90,
104 mConfig72,
105 mConfig120};
106 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90_120Device = {mConfig60,
107 mConfig90,
108 mConfig72,
109 mConfig120,
110 mConfig30};
111 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60Device =
112 {mConfig60, mConfig90DifferentGroup, mConfig72DifferentGroup, mConfig120DifferentGroup,
113 mConfig30};
114 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90Device =
115 {mConfig60, mConfig90, mConfig72, mConfig120DifferentGroup, mConfig30};
116 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_90Device =
117 {mConfig60, mConfig90, mConfig72DifferentGroup, mConfig120DifferentGroup, mConfig30};
Marin Shalamanov46084422020-10-13 12:33:42 +0200118 std::vector<std::shared_ptr<const HWC2::Display::Config>> m25_30_50_60Device =
119 {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)};
146
147 Hwc2::mock::Display mDisplay;
148
149private:
150 std::shared_ptr<const HWC2::Display::Config> createConfig(HwcConfigIndexType configId,
151 int32_t configGroup,
152 int64_t vsyncPeriod,
153 int32_t hight = -1,
154 int32_t width = -1);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700155};
156
Ady Abrahamabc27602020-04-08 17:20:29 -0700157using Builder = HWC2::Display::Config::Builder;
158
Alec Mouri0a1cc962019-03-14 12:33:02 -0700159RefreshRateConfigsTest::RefreshRateConfigsTest() {
160 const ::testing::TestInfo* const test_info =
161 ::testing::UnitTest::GetInstance()->current_test_info();
162 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
163}
164
165RefreshRateConfigsTest::~RefreshRateConfigsTest() {
166 const ::testing::TestInfo* const test_info =
167 ::testing::UnitTest::GetInstance()->current_test_info();
168 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
169}
170
Ady Abrahamabc27602020-04-08 17:20:29 -0700171std::shared_ptr<const HWC2::Display::Config> RefreshRateConfigsTest::createConfig(
172 HwcConfigIndexType configId, int32_t configGroup, int64_t vsyncPeriod, int32_t hight,
173 int32_t width) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700174 return HWC2::Display::Config::Builder(mDisplay, hal::HWConfigId(configId.value()))
Ady Abrahamabc27602020-04-08 17:20:29 -0700175 .setVsyncPeriod(int32_t(vsyncPeriod))
176 .setConfigGroup(configGroup)
177 .setHeight(hight)
178 .setWidth(width)
179 .build();
180}
181
Alec Mouri0a1cc962019-03-14 12:33:02 -0700182namespace {
183/* ------------------------------------------------------------------------
184 * Test cases
185 */
Ady Abraham2139f732019-11-13 18:56:40 -0800186TEST_F(RefreshRateConfigsTest, oneDeviceConfig_SwitchingSupported) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700187 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700188 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
189 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700190}
191
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100192TEST_F(RefreshRateConfigsTest, invalidPolicy) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100193 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700194 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
195 /*currentConfigId=*/HWC_CONFIG_ID_60);
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100196 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy(
197 {HwcConfigIndexType(10), {Fps(60), Fps(60)}}),
198 0);
199 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(20), Fps(40)}}),
200 0);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100201}
202
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700203TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700204 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700205 std::make_unique<RefreshRateConfigs>(m60_90Device,
206 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700207
Ady Abraham2e1dd892020-03-05 13:48:36 -0800208 const auto& minRate = refreshRateConfigs->getMinRefreshRate();
209 const auto& performanceRate = refreshRateConfigs->getMaxRefreshRate();
Alec Mouri0a1cc962019-03-14 12:33:02 -0700210
Ady Abrahamabc27602020-04-08 17:20:29 -0700211 ASSERT_EQ(mExpected60Config, minRate);
212 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800213
Ady Abraham2e1dd892020-03-05 13:48:36 -0800214 const auto& minRateByPolicy = refreshRateConfigs->getMinRefreshRateByPolicy();
215 const auto& performanceRateByPolicy = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800216 ASSERT_EQ(minRateByPolicy, minRate);
217 ASSERT_EQ(performanceRateByPolicy, performanceRate);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700218}
Ady Abraham2139f732019-11-13 18:56:40 -0800219
220TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentGroups) {
Ady Abraham2139f732019-11-13 18:56:40 -0800221 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700222 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
223 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800224
Ady Abraham2e1dd892020-03-05 13:48:36 -0800225 const auto& minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
226 const auto& performanceRate = refreshRateConfigs->getMaxRefreshRate();
227 const auto& minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
228 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800229
Ady Abrahamabc27602020-04-08 17:20:29 -0700230 ASSERT_EQ(mExpected60Config, minRate);
231 ASSERT_EQ(mExpected60Config, minRate60);
232 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800233
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100234 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
235 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800236 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
237
Ady Abraham2e1dd892020-03-05 13:48:36 -0800238 const auto& minRate90 = refreshRateConfigs->getMinRefreshRateByPolicy();
239 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800240
Ady Abrahamabc27602020-04-08 17:20:29 -0700241 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate);
242 ASSERT_EQ(mExpected90DifferentGroupConfig, minRate90);
243 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate90);
244}
245
246TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentResolutions) {
247 auto refreshRateConfigs =
248 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentResolutions,
249 /*currentConfigId=*/HWC_CONFIG_ID_60);
250
251 const auto& minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
252 const auto& performanceRate = refreshRateConfigs->getMaxRefreshRate();
253 const auto& minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
254 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
255
256 ASSERT_EQ(mExpected60Config, minRate);
257 ASSERT_EQ(mExpected60Config, minRate60);
258 ASSERT_EQ(mExpected60Config, performanceRate60);
259
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100260 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
261 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700262 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
263
264 const auto& minRate90 = refreshRateConfigs->getMinRefreshRateByPolicy();
265 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
266
267 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate);
268 ASSERT_EQ(mExpected90DifferentResolutionConfig, minRate90);
269 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate90);
Ady Abraham2139f732019-11-13 18:56:40 -0800270}
271
272TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_policyChange) {
Ady Abraham2139f732019-11-13 18:56:40 -0800273 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700274 std::make_unique<RefreshRateConfigs>(m60_90Device,
275 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ana Krulec3f6a2062020-01-23 15:48:01 -0800276
Ady Abraham2e1dd892020-03-05 13:48:36 -0800277 auto& minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
278 auto& performanceRate = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800279
Ady Abrahamabc27602020-04-08 17:20:29 -0700280 ASSERT_EQ(mExpected60Config, minRate);
281 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800282
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100283 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
284 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800285
Ady Abraham2e1dd892020-03-05 13:48:36 -0800286 auto& minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
287 auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abrahamabc27602020-04-08 17:20:29 -0700288 ASSERT_EQ(mExpected60Config, minRate60);
289 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800290}
291
292TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getCurrentRefreshRate) {
Ady Abraham2139f732019-11-13 18:56:40 -0800293 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700294 std::make_unique<RefreshRateConfigs>(m60_90Device,
295 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800296 {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800297 auto& current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700298 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800299 }
300
301 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
302 {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800303 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
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100307 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
308 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800309 {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800310 auto& current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700311 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800312 }
313}
314
Steven Thomasbb374322020-04-28 22:47:16 -0700315TEST_F(RefreshRateConfigsTest, getBestRefreshRate_noLayers) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700316 auto refreshRateConfigs =
317 std::make_unique<RefreshRateConfigs>(m60_72_90Device, /*currentConfigId=*/
318 HWC_CONFIG_ID_72);
Ana Krulec3d367c82020-02-25 15:02:01 -0800319
Steven Thomasdebafed2020-05-18 17:30:35 -0700320 // If there are no layers we select the default frame rate, which is the max of the primary
321 // range.
Ana Krulec3d367c82020-02-25 15:02:01 -0800322 auto layers = std::vector<LayerRequirement>{};
Steven Thomasdebafed2020-05-18 17:30:35 -0700323 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700324 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800325
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100326 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
327 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700328 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700329 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800330}
331
Steven Thomasbb374322020-04-28 22:47:16 -0700332TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800333 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700334 std::make_unique<RefreshRateConfigs>(m60_90Device,
335 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800336
337 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
338 auto& lr = layers[0];
339
340 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800341 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700342 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700343 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800344
345 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800346 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700347 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700348 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800349
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100350 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800351 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800352 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700353 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700354 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800355
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100356 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800357 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700358 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700359 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800360
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100361 lr.desiredRefreshRate = Fps(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800362 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700363 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700364 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800365
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100366 lr.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800367 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700368 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700369 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800370
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100371 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800372 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700373 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700374 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800375
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800376 lr.name = "";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100377 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
378 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800379
380 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700381 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700382 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800383
384 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700385 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700386 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800387
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100388 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800389 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700390 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700391 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800392
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100393 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700394 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700395 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800396
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100397 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700398 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700399 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800400
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100401 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700402 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700403 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800404
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100405 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700406 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700407 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800408
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100409 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
410 {HWC_CONFIG_ID_90, {Fps(90.0f), Fps(90.0f)}}),
411 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800412
413 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700414 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700415 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800416
417 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700418 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700419 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800420
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100421 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800422 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700423 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700424 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800425
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100426 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700427 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700428 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800429
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100430 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700431 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700432 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800433
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100434 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700435 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700436 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800437
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100438 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700439 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700440 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800441
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100442 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
443 {HWC_CONFIG_ID_60, {Fps(0.0f), Fps(120.0f)}}),
444 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800445 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700446 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700447 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800448
449 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700450 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700451 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800452
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100453 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800454 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700455 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700456 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800457
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100458 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700459 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700460 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800461
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100462 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700463 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700464 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800465
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100466 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700467 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700468 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800469
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100470 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700471 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700472 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800473}
474
Steven Thomasbb374322020-04-28 22:47:16 -0700475TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800476 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700477 std::make_unique<RefreshRateConfigs>(m60_72_90Device,
478 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800479
480 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
481 auto& lr = layers[0];
482
483 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700484 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700485 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800486
487 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700488 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700489 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800490
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100491 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800492 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700493 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700494 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800495
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100496 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700497 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700498 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800499
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100500 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700501 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700502 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800503
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100504 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700505 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700506 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800507
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100508 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700509 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700510 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800511}
512
Steven Thomasbb374322020-04-28 22:47:16 -0700513TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90_120) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800514 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700515 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
516 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800517
518 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
519 LayerRequirement{.weight = 1.0f}};
520 auto& lr1 = layers[0];
521 auto& lr2 = layers[1];
522
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(60.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800526 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700527 EXPECT_EQ(mExpected120Config,
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
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100537 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800538 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100539 lr2.desiredRefreshRate = Fps(48.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800540 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700541 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700542 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800543}
544
Steven Thomasbb374322020-04-28 22:47:16 -0700545TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_90_120_DifferentTypes) {
Ady Abraham71c437d2020-01-31 15:56:57 -0800546 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700547 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
548 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham71c437d2020-01-31 15:56:57 -0800549
550 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
551 LayerRequirement{.weight = 1.0f}};
552 auto& lr1 = layers[0];
553 auto& lr2 = layers[1];
554
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100555 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800556 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800557 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100558 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800559 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800560 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700561 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700562 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800563
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100564 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800565 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800566 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100567 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800568 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800569 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700570 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700571 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800572
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100573 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800574 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800575 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100576 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800577 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800578 lr2.name = "60Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700579 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700580 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800581
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100582 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800583 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800584 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100585 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800586 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800587 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700588 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700589 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800590
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100591 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800592 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
593 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100594 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800595 lr2.vote = LayerVoteType::ExplicitDefault;
596 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700597 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700598 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800599
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100600 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800601 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800602 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100603 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800604 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800605 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700606 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700607 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800608
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100609 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800610 lr1.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800611 lr1.name = "24Hz Heuristic";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100612 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800613 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800614 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700615 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700616 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800617
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100618 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800619 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800620 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100621 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800622 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800623 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700624 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700625 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800626
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100627 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800628 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800629 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100630 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800631 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800632 lr2.name = "90Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700633 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700634 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800635}
636
Steven Thomasbb374322020-04-28 22:47:16 -0700637TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800638 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700639 std::make_unique<RefreshRateConfigs>(m30_60Device,
640 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800641
642 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
643 auto& lr = layers[0];
644
645 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700646 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700647 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800648
649 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700650 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700651 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800652
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100653 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800654 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700655 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700656 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800657
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100658 lr.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700659 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700660 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800661
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100662 lr.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700663 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700664 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800665
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100666 lr.desiredRefreshRate = Fps(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700667 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700668 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800669
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100670 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700671 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700672 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800673}
674
Steven Thomasbb374322020-04-28 22:47:16 -0700675TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800676 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700677 std::make_unique<RefreshRateConfigs>(m30_60_72_90Device,
678 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800679
680 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
681 auto& lr = layers[0];
682
683 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800684 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700685 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700686 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800687
688 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800689 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700690 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700691 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800692
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100693 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800694 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800695 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700696 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700697 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800698
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100699 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800700 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700701 EXPECT_EQ(mExpected60Config,
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(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800707 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700708 EXPECT_EQ(mExpected90Config,
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(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800714 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700715 EXPECT_EQ(mExpected30Config,
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 Abraham8a82ba62020-01-17 12:43:17 -0800719
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100720 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800721 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700722 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700723 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700724 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700725 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800726
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100727 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800728 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
729 lr.name = "24Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700730 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700731 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700732 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700733 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800734}
735
Steven Thomasbb374322020-04-28 22:47:16 -0700736TEST_F(RefreshRateConfigsTest, getBestRefreshRate_PriorityTest) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800737 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700738 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
739 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800740
741 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
742 LayerRequirement{.weight = 1.0f}};
743 auto& lr1 = layers[0];
744 auto& lr2 = layers[1];
745
746 lr1.vote = LayerVoteType::Min;
747 lr2.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700748 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700749 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800750
751 lr1.vote = LayerVoteType::Min;
752 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100753 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700754 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700755 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800756
757 lr1.vote = LayerVoteType::Min;
Ady Abraham71c437d2020-01-31 15:56:57 -0800758 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100759 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700760 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700761 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800762
763 lr1.vote = LayerVoteType::Max;
764 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100765 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700766 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700767 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800768
769 lr1.vote = LayerVoteType::Max;
Ady Abraham71c437d2020-01-31 15:56:57 -0800770 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100771 lr2.desiredRefreshRate = Fps(60.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(15.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800777 lr2.vote = LayerVoteType::Heuristic;
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 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100783 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800784 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100785 lr2.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700786 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700787 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800788}
789
Steven Thomasbb374322020-04-28 22:47:16 -0700790TEST_F(RefreshRateConfigsTest, getBestRefreshRate_24FpsVideo) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800791 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700792 std::make_unique<RefreshRateConfigs>(m60_90Device,
793 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800794
795 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
796 auto& lr = layers[0];
797
Ady Abraham71c437d2020-01-31 15:56:57 -0800798 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800799 for (float fps = 23.0f; fps < 25.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100800 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800801 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700802 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700803 EXPECT_EQ(mExpected60Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abraham8a82ba62020-01-17 12:43:17 -0800804 }
805}
806
Steven Thomasbb374322020-04-28 22:47:16 -0700807TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getBestRefreshRate_Explicit) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800808 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700809 std::make_unique<RefreshRateConfigs>(m60_90Device,
810 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800811
812 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
813 LayerRequirement{.weight = 1.0f}};
814 auto& lr1 = layers[0];
815 auto& lr2 = layers[1];
816
817 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100818 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800819 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100820 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700821 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700822 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800823
824 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100825 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -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(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700829 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800830
831 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100832 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800833 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100834 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700835 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700836 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham2139f732019-11-13 18:56:40 -0800837}
838
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800839TEST_F(RefreshRateConfigsTest, testInPolicy) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100840 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(60.000004f), Fps(60.000004f)));
841 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(59.0f), Fps(60.1f)));
842 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(75.0f), Fps(90.0f)));
843 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(60.0011f), Fps(90.0f)));
844 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(50.0f), Fps(59.998f)));
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800845}
846
Steven Thomasbb374322020-04-28 22:47:16 -0700847TEST_F(RefreshRateConfigsTest, getBestRefreshRate_75HzContent) {
Ady Abrahamf6b77072020-01-30 14:22:54 -0800848 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700849 std::make_unique<RefreshRateConfigs>(m60_90Device,
850 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abrahamf6b77072020-01-30 14:22:54 -0800851
852 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
853 auto& lr = layers[0];
854
Ady Abraham71c437d2020-01-31 15:56:57 -0800855 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abrahamf6b77072020-01-30 14:22:54 -0800856 for (float fps = 75.0f; fps < 100.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100857 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800858 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700859 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700860 EXPECT_EQ(mExpected90Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abrahamf6b77072020-01-30 14:22:54 -0800861 }
862}
863
Steven Thomasbb374322020-04-28 22:47:16 -0700864TEST_F(RefreshRateConfigsTest, getBestRefreshRate_Multiples) {
Ady Abraham34702102020-02-10 14:12:05 -0800865 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700866 std::make_unique<RefreshRateConfigs>(m60_90Device,
867 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham34702102020-02-10 14:12:05 -0800868
869 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
870 LayerRequirement{.weight = 1.0f}};
871 auto& lr1 = layers[0];
872 auto& lr2 = layers[1];
873
874 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100875 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800876 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800877 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100878 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800879 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700880 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700881 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800882
883 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100884 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800885 lr1.name = "60Hz ExplicitExactOrMultiple";
886 lr2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100887 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800888 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700889 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700890 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800891
892 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100893 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800894 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800895 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800896 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700897 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700898 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800899
900 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100901 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800902 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800903 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100904 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800905 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700906 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700907 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800908
909 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100910 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800911 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800912 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800913 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700914 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700915 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800916}
917
918TEST_F(RefreshRateConfigsTest, scrollWhileWatching60fps_60_90) {
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800919 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700920 std::make_unique<RefreshRateConfigs>(m60_90Device,
921 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800922
923 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
924 LayerRequirement{.weight = 1.0f}};
925 auto& lr1 = layers[0];
926 auto& lr2 = layers[1];
927
928 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100929 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800930 lr1.name = "60Hz ExplicitExactOrMultiple";
931 lr2.vote = LayerVoteType::NoVote;
932 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700933 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700934 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800935
936 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100937 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800938 lr1.name = "60Hz ExplicitExactOrMultiple";
939 lr2.vote = LayerVoteType::NoVote;
940 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700941 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700942 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800943
944 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100945 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800946 lr1.name = "60Hz ExplicitExactOrMultiple";
947 lr2.vote = LayerVoteType::Max;
948 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700949 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700950 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800951
952 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100953 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800954 lr1.name = "60Hz ExplicitExactOrMultiple";
955 lr2.vote = LayerVoteType::Max;
956 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700957 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700958 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800959
960 // The other layer starts to provide buffers
961 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100962 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800963 lr1.name = "60Hz ExplicitExactOrMultiple";
964 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100965 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800966 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700967 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700968 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham6fb599b2020-03-05 13:48:22 -0800969}
970
971TEST_F(RefreshRateConfigsTest, touchConsidered) {
Ady Abrahamdfd62162020-06-10 16:11:56 -0700972 RefreshRateConfigs::GlobalSignals consideredSignals;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800973 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700974 std::make_unique<RefreshRateConfigs>(m60_90Device,
975 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800976
Ady Abrahamdfd62162020-06-10 16:11:56 -0700977 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false}, &consideredSignals);
978 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800979
Ady Abrahamdfd62162020-06-10 16:11:56 -0700980 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = false}, &consideredSignals);
981 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800982
983 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
984 LayerRequirement{.weight = 1.0f}};
985 auto& lr1 = layers[0];
986 auto& lr2 = layers[1];
987
988 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100989 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800990 lr1.name = "60Hz ExplicitExactOrMultiple";
991 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100992 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -0700993 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -0700994 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
995 &consideredSignals);
996 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800997
998 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100999 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001000 lr1.name = "60Hz ExplicitExactOrMultiple";
1001 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001002 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001003 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001004 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1005 &consideredSignals);
1006 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001007
1008 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001009 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001010 lr1.name = "60Hz ExplicitExactOrMultiple";
1011 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001012 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001013 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001014 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1015 &consideredSignals);
1016 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001017
1018 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001019 lr1.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001020 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001021 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001022 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001023 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001024 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1025 &consideredSignals);
1026 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham34702102020-02-10 14:12:05 -08001027}
1028
Steven Thomasbb374322020-04-28 22:47:16 -07001029TEST_F(RefreshRateConfigsTest, getBestRefreshRate_ExplicitDefault) {
Ady Abrahamabc27602020-04-08 17:20:29 -07001030 auto refreshRateConfigs =
1031 std::make_unique<RefreshRateConfigs>(m60_90_72_120Device, /*currentConfigId=*/
1032 HWC_CONFIG_ID_60);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001033
1034 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1035 auto& lr = layers[0];
1036
1037 // Prepare a table with the vote and the expected refresh rate
1038 const std::vector<std::pair<float, float>> testCases = {
1039 {130, 120}, {120, 120}, {119, 120}, {110, 120},
1040
1041 {100, 90}, {90, 90}, {89, 90},
1042
1043 {80, 72}, {73, 72}, {72, 72}, {71, 72}, {70, 72},
1044
1045 {65, 60}, {60, 60}, {59, 60}, {58, 60},
1046
1047 {55, 90}, {50, 90}, {45, 90},
1048
1049 {42, 120}, {40, 120}, {39, 120},
1050
1051 {37, 72}, {36, 72}, {35, 72},
1052
1053 {30, 60},
1054 };
1055
1056 for (const auto& test : testCases) {
1057 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001058 lr.desiredRefreshRate = Fps(test.first);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001059
1060 std::stringstream ss;
1061 ss << "ExplicitDefault " << test.first << " fps";
1062 lr.name = ss.str();
1063
1064 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -07001065 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001066 EXPECT_TRUE(refreshRate.getFps().equalsWithMargin(Fps(test.second)))
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001067 << "Expecting " << test.first << "fps => " << test.second << "Hz";
1068 }
Alec Mouri0a1cc962019-03-14 12:33:02 -07001069}
1070
Alec Mouri11232a22020-05-14 18:06:25 -07001071TEST_F(RefreshRateConfigsTest,
1072 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresTouchFlag) {
1073 auto refreshRateConfigs =
1074 std::make_unique<RefreshRateConfigs>(m60_90Device,
1075 /*currentConfigId=*/HWC_CONFIG_ID_90);
1076
1077 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001078 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001079 0);
1080
1081 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1082 auto& lr = layers[0];
1083
Ady Abrahamdfd62162020-06-10 16:11:56 -07001084 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001085 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001086 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001087 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001088 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001089 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001090 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = true},
1091 &consideredSignals));
1092 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001093}
1094
1095TEST_F(RefreshRateConfigsTest,
1096 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresIdleFlag) {
1097 auto refreshRateConfigs =
1098 std::make_unique<RefreshRateConfigs>(m60_90Device,
1099 /*currentConfigId=*/HWC_CONFIG_ID_60);
1100
1101 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001102 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001103 0);
1104
1105 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1106 auto& lr = layers[0];
1107
Alec Mouri11232a22020-05-14 18:06:25 -07001108 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001109 lr.desiredRefreshRate = Fps(90.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001110 lr.name = "90Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001111 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001112 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001113 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = true}));
Alec Mouri11232a22020-05-14 18:06:25 -07001114}
1115
1116TEST_F(RefreshRateConfigsTest,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001117 getBestRefreshRate_withDisplayManagerRequestingSingleRate_onlySwitchesRatesForExplicitFocusedLayers) {
Alec Mouri11232a22020-05-14 18:06:25 -07001118 auto refreshRateConfigs =
1119 std::make_unique<RefreshRateConfigs>(m60_90Device,
1120 /*currentConfigId=*/HWC_CONFIG_ID_90);
1121
1122 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001123 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001124 0);
1125
Ady Abrahamdfd62162020-06-10 16:11:56 -07001126 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001127 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001128 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false},
1129 &consideredSignals));
1130 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001131
1132 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1133 auto& lr = layers[0];
1134
1135 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001136 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001137 lr.name = "60Hz ExplicitExactOrMultiple";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001138 lr.focused = false;
1139 EXPECT_EQ(mExpected90Config,
1140 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1141
1142 lr.focused = true;
Ady Abraham20c029c2020-07-06 12:58:05 -07001143 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001144 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001145
1146 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001147 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001148 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001149 lr.focused = false;
1150 EXPECT_EQ(mExpected90Config,
1151 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1152
1153 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001154 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001155 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001156
1157 lr.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001158 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001159 lr.name = "60Hz Heuristic";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001160 lr.focused = false;
1161 EXPECT_EQ(mExpected90Config,
1162 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1163
1164 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001165 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001166 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001167
1168 lr.vote = LayerVoteType::Max;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001169 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001170 lr.name = "60Hz Max";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001171 lr.focused = false;
1172 EXPECT_EQ(mExpected90Config,
1173 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1174
1175 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001176 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001177 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001178
1179 lr.vote = LayerVoteType::Min;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001180 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001181 lr.name = "60Hz Min";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001182 lr.focused = false;
1183 EXPECT_EQ(mExpected90Config,
1184 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1185
1186 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001187 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001188 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001189}
1190
Steven Thomasd4071902020-03-24 16:02:53 -07001191TEST_F(RefreshRateConfigsTest, groupSwitching) {
Steven Thomasd4071902020-03-24 16:02:53 -07001192 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -07001193 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
1194 /*currentConfigId=*/HWC_CONFIG_ID_60);
Steven Thomasd4071902020-03-24 16:02:53 -07001195
1196 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1197 auto& layer = layers[0];
1198 layer.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001199 layer.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001200 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Steven Thomasd4071902020-03-24 16:02:53 -07001201 layer.name = "90Hz ExplicitDefault";
Marin Shalamanov46084422020-10-13 12:33:42 +02001202 layer.focused = true;
Steven Thomasd4071902020-03-24 16:02:53 -07001203
Steven Thomasd4071902020-03-24 16:02:53 -07001204 ASSERT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001205 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001206 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001207
1208 RefreshRateConfigs::Policy policy;
1209 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1210 policy.allowGroupSwitching = true;
1211 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1212 ASSERT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001213 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001214 .getConfigId());
Marin Shalamanov46084422020-10-13 12:33:42 +02001215
1216 // Verify that we won't change the group if seamless switch is required.
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001217 layer.seamlessness = Seamlessness::OnlySeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001218 ASSERT_EQ(HWC_CONFIG_ID_60,
1219 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1220 .getConfigId());
1221
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001222 // 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 +02001223 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001224 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001225 layer.name = "60Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001226 layer.seamlessness = Seamlessness::OnlySeamless;
1227 ASSERT_EQ(HWC_CONFIG_ID_90,
1228 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1229 .getConfigId());
1230
1231 // Verify that if the current config is in another group and there are no layers with
1232 // seamlessness=SeamedAndSeamless we'll go back to the default group.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001233 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001234 layer.name = "60Hz ExplicitDefault";
1235 layer.seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001236 ASSERT_EQ(HWC_CONFIG_ID_60,
1237 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1238 .getConfigId());
1239
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001240 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1241 // seamlessness=OnlySeamless can't change the config group.
Marin Shalamanov46084422020-10-13 12:33:42 +02001242 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001243 layer.seamlessness = Seamlessness::OnlySeamless;
1244
1245 layers.push_back(LayerRequirement{.weight = 0.5f});
1246 auto& layer2 = layers[layers.size() - 1];
Marin Shalamanov46084422020-10-13 12:33:42 +02001247 layer2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001248 layer2.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001249 layer2.name = "90Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001250 layer2.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001251 layer2.focused = false;
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001252
1253 ASSERT_EQ(HWC_CONFIG_ID_90,
1254 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1255 .getConfigId());
1256
1257 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1258 // seamlessness=Default can't change the config group.
1259 layers[0].seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001260 ASSERT_EQ(HWC_CONFIG_ID_90,
1261 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1262 .getConfigId());
1263}
1264
1265TEST_F(RefreshRateConfigsTest, nonSeamlessVotePrefersSeamlessSwitches) {
1266 auto refreshRateConfigs =
1267 std::make_unique<RefreshRateConfigs>(m30_60Device,
1268 /*currentConfigId=*/HWC_CONFIG_ID_60);
1269
1270 // Allow group switching.
1271 RefreshRateConfigs::Policy policy;
1272 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1273 policy.allowGroupSwitching = true;
1274 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1275
1276 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1277 auto& layer = layers[0];
1278 layer.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001279 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001280 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001281 layer.name = "60Hz ExplicitExactOrMultiple";
1282 layer.focused = true;
1283
1284 ASSERT_EQ(HWC_CONFIG_ID_60,
1285 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1286 .getConfigId());
1287
1288 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
1289 ASSERT_EQ(HWC_CONFIG_ID_120,
1290 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1291 .getConfigId());
1292}
1293
1294TEST_F(RefreshRateConfigsTest, nonSeamlessExactAndSeamlessMultipleLayers) {
1295 auto refreshRateConfigs =
1296 std::make_unique<RefreshRateConfigs>(m25_30_50_60Device,
1297 /*currentConfigId=*/HWC_CONFIG_ID_60);
1298
1299 // Allow group switching.
1300 RefreshRateConfigs::Policy policy;
1301 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1302 policy.allowGroupSwitching = true;
1303 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1304
1305 auto layers = std::vector<
1306 LayerRequirement>{LayerRequirement{.name = "60Hz ExplicitDefault",
1307 .vote = LayerVoteType::ExplicitDefault,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001308 .desiredRefreshRate = Fps(60.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001309 .seamlessness = Seamlessness::SeamedAndSeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001310 .weight = 0.5f,
1311 .focused = false},
1312 LayerRequirement{.name = "25Hz ExplicitExactOrMultiple",
1313 .vote = LayerVoteType::ExplicitExactOrMultiple,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001314 .desiredRefreshRate = Fps(25.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001315 .seamlessness = Seamlessness::OnlySeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001316 .weight = 1.0f,
1317 .focused = true}};
1318 auto& seamedLayer = layers[0];
1319
1320 ASSERT_EQ(HWC_CONFIG_ID_50,
1321 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1322 .getConfigId());
1323
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001324 seamedLayer.name = "30Hz ExplicitDefault", seamedLayer.desiredRefreshRate = Fps(30.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001325 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_30);
1326
1327 ASSERT_EQ(HWC_CONFIG_ID_25,
1328 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1329 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001330}
1331
Steven Thomasf734df42020-04-13 21:09:28 -07001332TEST_F(RefreshRateConfigsTest, primaryVsAppRequestPolicy) {
1333 auto refreshRateConfigs =
Alec Mouri11232a22020-05-14 18:06:25 -07001334 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
Steven Thomasf734df42020-04-13 21:09:28 -07001335 /*currentConfigId=*/HWC_CONFIG_ID_60);
1336
1337 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1338 layers[0].name = "Test layer";
1339
Steven Thomasbb374322020-04-28 22:47:16 -07001340 // Return the config ID from calling getBestRefreshRate() for a single layer with the
Steven Thomasf734df42020-04-13 21:09:28 -07001341 // given voteType and fps.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001342 auto getFrameRate = [&](LayerVoteType voteType, Fps fps, bool touchActive = false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001343 bool focused = true) -> HwcConfigIndexType {
Steven Thomasf734df42020-04-13 21:09:28 -07001344 layers[0].vote = voteType;
1345 layers[0].desiredRefreshRate = fps;
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001346 layers[0].focused = focused;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001347 return refreshRateConfigs->getBestRefreshRate(layers, {.touch = touchActive, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001348 .getConfigId();
1349 };
1350
1351 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001352 {HWC_CONFIG_ID_60, {Fps(30.f), Fps(60.f)}, {Fps(30.f), Fps(90.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001353 0);
Steven Thomasf734df42020-04-13 21:09:28 -07001354 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001355 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001356 .getConfigId());
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001357 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1358 EXPECT_EQ(HWC_CONFIG_ID_30, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1359 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1360 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1361 EXPECT_EQ(HWC_CONFIG_ID_90, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1362 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001363
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001364 // Layers not focused are not allowed to override primary config
1365 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001366 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001367 /*focused=*/false));
1368 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001369 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001370 /*focused=*/false));
1371
Steven Thomasf734df42020-04-13 21:09:28 -07001372 // Touch boost should be restricted to the primary range.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001373 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001374 // When we're higher than the primary range max due to a layer frame rate setting, touch boost
1375 // shouldn't drag us back down to the primary range max.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001376 EXPECT_EQ(HWC_CONFIG_ID_90,
1377 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/true));
Ady Abraham20c029c2020-07-06 12:58:05 -07001378 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001379 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001380
1381 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001382 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(60.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001383 0);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001384 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1385 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1386 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1387 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1388 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1389 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001390}
1391
Steven Thomasbb374322020-04-28 22:47:16 -07001392TEST_F(RefreshRateConfigsTest, idle) {
1393 auto refreshRateConfigs =
1394 std::make_unique<RefreshRateConfigs>(m60_90Device,
1395 /*currentConfigId=*/HWC_CONFIG_ID_60);
1396
1397 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1398 layers[0].name = "Test layer";
1399
Ady Abrahamdfd62162020-06-10 16:11:56 -07001400 const auto getIdleFrameRate = [&](LayerVoteType voteType,
1401 bool touchActive) -> HwcConfigIndexType {
Steven Thomasbb374322020-04-28 22:47:16 -07001402 layers[0].vote = voteType;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001403 layers[0].desiredRefreshRate = Fps(90.f);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001404 RefreshRateConfigs::GlobalSignals consideredSignals;
1405 const auto configId =
1406 refreshRateConfigs
1407 ->getBestRefreshRate(layers, {.touch = touchActive, .idle = true},
1408 &consideredSignals)
1409 .getConfigId();
1410 // Refresh rate will be chosen by either touch state or idle state
1411 EXPECT_EQ(!touchActive, consideredSignals.idle);
1412 return configId;
Steven Thomasbb374322020-04-28 22:47:16 -07001413 };
1414
1415 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001416 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Steven Thomasbb374322020-04-28 22:47:16 -07001417 0);
1418
1419 // Idle should be lower priority than touch boost.
Ady Abrahamdfd62162020-06-10 16:11:56 -07001420 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/true));
1421 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/true));
1422 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/true));
1423 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/true));
1424 EXPECT_EQ(HWC_CONFIG_ID_90,
1425 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/true));
1426 EXPECT_EQ(HWC_CONFIG_ID_90,
1427 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/true));
Steven Thomasbb374322020-04-28 22:47:16 -07001428
1429 // With no layers, idle should still be lower priority than touch boost.
Steven Thomasbb374322020-04-28 22:47:16 -07001430 EXPECT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001431 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001432 .getConfigId());
1433
1434 // Idle should be higher precedence than other layer frame rate considerations.
1435 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001436 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/false));
1437 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/false));
1438 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/false));
1439 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/false));
1440 EXPECT_EQ(HWC_CONFIG_ID_60,
1441 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/false));
1442 EXPECT_EQ(HWC_CONFIG_ID_60,
1443 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/false));
Steven Thomasbb374322020-04-28 22:47:16 -07001444
1445 // Idle should be applied rather than the current config when there are no layers.
1446 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001447 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001448 .getConfigId());
1449}
1450
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001451TEST_F(RefreshRateConfigsTest, findClosestKnownFrameRate) {
1452 auto refreshRateConfigs =
1453 std::make_unique<RefreshRateConfigs>(m60_90Device,
1454 /*currentConfigId=*/HWC_CONFIG_ID_60);
1455
1456 for (float fps = 1.0f; fps <= 120.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001457 const auto knownFrameRate = findClosestKnownFrameRate(*refreshRateConfigs, Fps(fps));
1458 Fps expectedFrameRate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001459 if (fps < 26.91f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001460 expectedFrameRate = Fps(24.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001461 } else if (fps < 37.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001462 expectedFrameRate = Fps(30.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001463 } else if (fps < 52.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001464 expectedFrameRate = Fps(45.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001465 } else if (fps < 66.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001466 expectedFrameRate = Fps(60.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001467 } else if (fps < 81.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001468 expectedFrameRate = Fps(72.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001469 } else {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001470 expectedFrameRate = Fps(90.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001471 }
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001472 EXPECT_TRUE(expectedFrameRate.equalsWithMargin(knownFrameRate))
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001473 << "findClosestKnownFrameRate(" << fps << ") = " << knownFrameRate;
1474 }
1475}
1476
1477TEST_F(RefreshRateConfigsTest, getBestRefreshRate_KnownFrameRate) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001478 auto refreshRateConfigs =
1479 std::make_unique<RefreshRateConfigs>(m60_90Device,
1480 /*currentConfigId=*/HWC_CONFIG_ID_60);
1481
1482 struct ExpectedRate {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001483 Fps rate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001484 const RefreshRate& expected;
1485 };
1486
1487 /* clang-format off */
1488 std::vector<ExpectedRate> knownFrameRatesExpectations = {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001489 {Fps(24.0f), mExpected60Config},
1490 {Fps(30.0f), mExpected60Config},
1491 {Fps(45.0f), mExpected90Config},
1492 {Fps(60.0f), mExpected60Config},
1493 {Fps(72.0f), mExpected90Config},
1494 {Fps(90.0f), mExpected90Config},
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001495 };
1496 /* clang-format on */
1497
1498 // Make sure the test tests all the known frame rate
1499 const auto knownFrameRateList = getKnownFrameRate(*refreshRateConfigs);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001500 const auto equal =
1501 std::equal(knownFrameRateList.begin(), knownFrameRateList.end(),
1502 knownFrameRatesExpectations.begin(),
1503 [](Fps a, const ExpectedRate& b) { return a.equalsWithMargin(b.rate); });
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001504 EXPECT_TRUE(equal);
1505
1506 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1507 auto& layer = layers[0];
1508 layer.vote = LayerVoteType::Heuristic;
1509 for (const auto& expectedRate : knownFrameRatesExpectations) {
1510 layer.desiredRefreshRate = expectedRate.rate;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001511 const auto& refreshRate =
1512 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001513 EXPECT_EQ(expectedRate.expected, refreshRate);
1514 }
1515}
1516
Ana Krulecb9afd792020-06-11 13:16:15 -07001517TEST_F(RefreshRateConfigsTest, testComparisonOperator) {
1518 EXPECT_TRUE(mExpected60Config < mExpected90Config);
1519 EXPECT_FALSE(mExpected60Config < mExpected60Config);
1520 EXPECT_FALSE(mExpected90Config < mExpected90Config);
1521}
1522
1523TEST_F(RefreshRateConfigsTest, testKernelIdleTimerAction) {
1524 using KernelIdleTimerAction = scheduler::RefreshRateConfigs::KernelIdleTimerAction;
1525
1526 auto refreshRateConfigs =
1527 std::make_unique<RefreshRateConfigs>(m60_90Device,
1528 /*currentConfigId=*/HWC_CONFIG_ID_90);
1529 // SetPolicy(60, 90), current 90Hz => TurnOn.
1530 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1531
1532 // SetPolicy(60, 90), current 60Hz => TurnOn.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001533 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(90)}}),
1534 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001535 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1536
1537 // SetPolicy(60, 60), current 60Hz => NoChange, avoid extra calls.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001538 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
1539 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001540 EXPECT_EQ(KernelIdleTimerAction::NoChange, refreshRateConfigs->getIdleTimerAction());
1541
1542 // SetPolicy(90, 90), current 90Hz => TurnOff.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001543 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
1544 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001545 EXPECT_EQ(KernelIdleTimerAction::TurnOff, refreshRateConfigs->getIdleTimerAction());
1546}
1547
Ady Abraham0bb6a472020-10-12 10:22:13 -07001548TEST_F(RefreshRateConfigsTest, RefreshRateDividerForUid) {
1549 auto refreshRateConfigs =
1550 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
1551 /*currentConfigId=*/HWC_CONFIG_ID_30);
Ady Abraham62a0be22020-12-08 16:54:10 -08001552
1553 const auto frameRate = Fps(30.f);
1554 EXPECT_EQ(1, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001555
1556 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_60);
Ady Abraham62a0be22020-12-08 16:54:10 -08001557 EXPECT_EQ(2, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001558
1559 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_72);
Ady Abraham62a0be22020-12-08 16:54:10 -08001560 EXPECT_EQ(0, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001561
1562 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001563 EXPECT_EQ(3, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001564
1565 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
Ady Abraham62a0be22020-12-08 16:54:10 -08001566 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham62f216c2020-10-13 19:07:23 -07001567
1568 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001569 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.5f)));
1570 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.6f)));
1571}
1572
1573TEST_F(RefreshRateConfigsTest, populatePreferredFrameRate_noLayers) {
1574 auto refreshRateConfigs =
1575 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1576 HWC_CONFIG_ID_120);
1577
1578 auto layers = std::vector<LayerRequirement>{};
1579 ASSERT_TRUE(refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f)).empty());
1580}
1581
1582TEST_F(RefreshRateConfigsTest, getFrameRateOverrides_60on120) {
1583 auto refreshRateConfigs =
1584 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1585 HWC_CONFIG_ID_120);
1586
1587 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1588 layers[0].name = "Test layer";
1589 layers[0].ownerUid = 1234;
1590 layers[0].desiredRefreshRate = Fps(60.0f);
1591 layers[0].vote = LayerVoteType::ExplicitDefault;
1592 auto frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1593 ASSERT_EQ(1, frameRateOverrides.size());
1594 ASSERT_EQ(1, frameRateOverrides.count(1234));
1595 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1596
1597 layers[0].vote = LayerVoteType::ExplicitExactOrMultiple;
1598 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1599 ASSERT_EQ(1, frameRateOverrides.size());
1600 ASSERT_EQ(1, frameRateOverrides.count(1234));
1601 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1602
1603 layers[0].vote = LayerVoteType::NoVote;
1604 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1605 ASSERT_TRUE(frameRateOverrides.empty());
1606
1607 layers[0].vote = LayerVoteType::Min;
1608 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1609 ASSERT_TRUE(frameRateOverrides.empty());
1610
1611 layers[0].vote = LayerVoteType::Max;
1612 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1613 ASSERT_TRUE(frameRateOverrides.empty());
1614
1615 layers[0].vote = LayerVoteType::Heuristic;
1616 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1617 ASSERT_TRUE(frameRateOverrides.empty());
1618}
1619
1620TEST_F(RefreshRateConfigsTest, populatePreferredFrameRate_twoUids) {
1621 auto refreshRateConfigs =
1622 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1623 HWC_CONFIG_ID_120);
1624
1625 auto layers = std::vector<LayerRequirement>{
1626 LayerRequirement{.ownerUid = 1234, .weight = 1.0f},
1627 LayerRequirement{.ownerUid = 5678, .weight = 1.0f},
1628 };
1629
1630 layers[0].name = "Test layer 1234";
1631 layers[0].desiredRefreshRate = Fps(60.0f);
1632 layers[0].vote = LayerVoteType::ExplicitDefault;
1633
1634 layers[1].name = "Test layer 5678";
1635 layers[1].desiredRefreshRate = Fps(30.0f);
1636 layers[1].vote = LayerVoteType::ExplicitDefault;
1637 auto frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1638
1639 ASSERT_EQ(2, frameRateOverrides.size());
1640 ASSERT_EQ(1, frameRateOverrides.count(1234));
1641 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1642 ASSERT_EQ(1, frameRateOverrides.count(5678));
1643 ASSERT_EQ(30.0f, frameRateOverrides.at(5678).getValue());
1644
1645 layers[1].vote = LayerVoteType::Heuristic;
1646 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1647 ASSERT_EQ(1, frameRateOverrides.size());
1648 ASSERT_EQ(1, frameRateOverrides.count(1234));
1649 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1650
1651 layers[1].ownerUid = 1234;
1652 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1653 ASSERT_TRUE(frameRateOverrides.empty());
Ady Abraham0bb6a472020-10-12 10:22:13 -07001654}
1655
Alec Mouri0a1cc962019-03-14 12:33:02 -07001656} // namespace
1657} // namespace scheduler
1658} // namespace android