blob: 45f0ee6d38fece99e6f5f6d2ff2abaf8d0b74a07 [file] [log] [blame]
Alec Mouri0a1cc962019-03-14 12:33:02 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wextra"
20
Alec Mouri0a1cc962019-03-14 12:33:02 -070021#undef LOG_TAG
22#define LOG_TAG "SchedulerUnittests"
23
24#include <gmock/gmock.h>
25#include <log/log.h>
26#include <thread>
27
Ady Abraham6fb599b2020-03-05 13:48:22 -080028#include "../../Scheduler/RefreshRateConfigs.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070029#include "DisplayHardware/HWC2.h"
30#include "Scheduler/RefreshRateConfigs.h"
Ady Abrahamabc27602020-04-08 17:20:29 -070031#include "mock/DisplayHardware/MockDisplay.h"
Alec Mouri0a1cc962019-03-14 12:33:02 -070032
33using namespace std::chrono_literals;
34using testing::_;
35
36namespace android {
Marin Shalamanove8a663d2020-11-24 17:48:00 +010037
Alec Mouri0a1cc962019-03-14 12:33:02 -070038namespace scheduler {
39
Peiyong Line9d809e2020-04-14 13:10:48 -070040namespace hal = android::hardware::graphics::composer::hal;
41
Alec Mouri0a1cc962019-03-14 12:33:02 -070042using RefreshRate = RefreshRateConfigs::RefreshRate;
Ady Abraham8a82ba62020-01-17 12:43:17 -080043using LayerVoteType = RefreshRateConfigs::LayerVoteType;
44using LayerRequirement = RefreshRateConfigs::LayerRequirement;
Alec Mouri0a1cc962019-03-14 12:33:02 -070045
46class RefreshRateConfigsTest : public testing::Test {
47protected:
Alec Mouri0a1cc962019-03-14 12:33:02 -070048 RefreshRateConfigsTest();
49 ~RefreshRateConfigsTest();
Ady Abrahamabc27602020-04-08 17:20:29 -070050
Marin Shalamanove8a663d2020-11-24 17:48:00 +010051 Fps findClosestKnownFrameRate(const RefreshRateConfigs& refreshRateConfigs, Fps frameRate) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -070052 return refreshRateConfigs.findClosestKnownFrameRate(frameRate);
53 }
54
Marin Shalamanove8a663d2020-11-24 17:48:00 +010055 std::vector<Fps> getKnownFrameRate(const RefreshRateConfigs& refreshRateConfigs) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -070056 return refreshRateConfigs.mKnownFrameRates;
57 }
58
Ady Abrahamabc27602020-04-08 17:20:29 -070059 // Test config IDs
60 static inline const HwcConfigIndexType HWC_CONFIG_ID_60 = HwcConfigIndexType(0);
61 static inline const HwcConfigIndexType HWC_CONFIG_ID_90 = HwcConfigIndexType(1);
62 static inline const HwcConfigIndexType HWC_CONFIG_ID_72 = HwcConfigIndexType(2);
63 static inline const HwcConfigIndexType HWC_CONFIG_ID_120 = HwcConfigIndexType(3);
64 static inline const HwcConfigIndexType HWC_CONFIG_ID_30 = HwcConfigIndexType(4);
Marin Shalamanov46084422020-10-13 12:33:42 +020065 static inline const HwcConfigIndexType HWC_CONFIG_ID_25 = HwcConfigIndexType(5);
66 static inline const HwcConfigIndexType HWC_CONFIG_ID_50 = HwcConfigIndexType(6);
Ady Abrahamabc27602020-04-08 17:20:29 -070067
68 // Test configs
69 std::shared_ptr<const HWC2::Display::Config> mConfig60 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010070 createConfig(HWC_CONFIG_ID_60, 0, Fps(60.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070071 std::shared_ptr<const HWC2::Display::Config> mConfig90 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010072 createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070073 std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010074 createConfig(HWC_CONFIG_ID_90, 1, Fps(90.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070075 std::shared_ptr<const HWC2::Display::Config> mConfig90DifferentResolution =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010076 createConfig(HWC_CONFIG_ID_90, 0, Fps(90.0f).getPeriodNsecs(), 111, 222);
Ady Abrahamabc27602020-04-08 17:20:29 -070077 std::shared_ptr<const HWC2::Display::Config> mConfig72 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010078 createConfig(HWC_CONFIG_ID_72, 0, Fps(72.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070079 std::shared_ptr<const HWC2::Display::Config> mConfig72DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010080 createConfig(HWC_CONFIG_ID_72, 1, Fps(72.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070081 std::shared_ptr<const HWC2::Display::Config> mConfig120 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010082 createConfig(HWC_CONFIG_ID_120, 0, Fps(120.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070083 std::shared_ptr<const HWC2::Display::Config> mConfig120DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010084 createConfig(HWC_CONFIG_ID_120, 1, Fps(120.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070085 std::shared_ptr<const HWC2::Display::Config> mConfig30 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010086 createConfig(HWC_CONFIG_ID_30, 0, Fps(30.0f).getPeriodNsecs());
Marin Shalamanov46084422020-10-13 12:33:42 +020087 std::shared_ptr<const HWC2::Display::Config> mConfig30DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010088 createConfig(HWC_CONFIG_ID_30, 1, Fps(30.0f).getPeriodNsecs());
Marin Shalamanov46084422020-10-13 12:33:42 +020089 std::shared_ptr<const HWC2::Display::Config> mConfig25DifferentGroup =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010090 createConfig(HWC_CONFIG_ID_25, 1, Fps(25.0f).getPeriodNsecs());
Marin Shalamanov46084422020-10-13 12:33:42 +020091 std::shared_ptr<const HWC2::Display::Config> mConfig50 =
Marin Shalamanove8a663d2020-11-24 17:48:00 +010092 createConfig(HWC_CONFIG_ID_50, 0, Fps(50.0f).getPeriodNsecs());
Ady Abrahamabc27602020-04-08 17:20:29 -070093
94 // Test device configurations
Marin Shalamanov46084422020-10-13 12:33:42 +020095 // The positions of the configs in the arrays below MUST match their IDs. For example,
96 // the first config should always be 60Hz, the second 90Hz etc.
Ady Abrahamabc27602020-04-08 17:20:29 -070097 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60OnlyConfigDevice = {mConfig60};
98 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90Device = {mConfig60, mConfig90};
99 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentGroups =
100 {mConfig60, mConfig90DifferentGroup};
101 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90DeviceWithDifferentResolutions =
102 {mConfig60, mConfig90DifferentResolution};
103 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_72_90Device = {mConfig60,
104 mConfig90,
105 mConfig72};
106 std::vector<std::shared_ptr<const HWC2::Display::Config>> m60_90_72_120Device = {mConfig60,
107 mConfig90,
108 mConfig72,
109 mConfig120};
110 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90_120Device = {mConfig60,
111 mConfig90,
112 mConfig72,
113 mConfig120,
114 mConfig30};
115 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60Device =
116 {mConfig60, mConfig90DifferentGroup, mConfig72DifferentGroup, mConfig120DifferentGroup,
117 mConfig30};
118 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_72_90Device =
119 {mConfig60, mConfig90, mConfig72, mConfig120DifferentGroup, mConfig30};
120 std::vector<std::shared_ptr<const HWC2::Display::Config>> m30_60_90Device =
121 {mConfig60, mConfig90, mConfig72DifferentGroup, mConfig120DifferentGroup, mConfig30};
Marin Shalamanov46084422020-10-13 12:33:42 +0200122 std::vector<std::shared_ptr<const HWC2::Display::Config>> m25_30_50_60Device =
123 {mConfig60,
124 mConfig90,
125 mConfig72DifferentGroup,
126 mConfig120DifferentGroup,
127 mConfig30DifferentGroup,
128 mConfig25DifferentGroup,
129 mConfig50};
Ady Abrahamabc27602020-04-08 17:20:29 -0700130
131 // Expected RefreshRate objects
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100132 RefreshRate mExpected60Config = {HWC_CONFIG_ID_60, mConfig60, Fps(60),
Ady Abrahamabc27602020-04-08 17:20:29 -0700133 RefreshRate::ConstructorTag(0)};
134 RefreshRate mExpectedAlmost60Config = {HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100135 createConfig(HWC_CONFIG_ID_60, 0, 16666665), Fps(60),
Ady Abrahamabc27602020-04-08 17:20:29 -0700136 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100137 RefreshRate mExpected90Config = {HWC_CONFIG_ID_90, mConfig90, Fps(90),
Ady Abrahamabc27602020-04-08 17:20:29 -0700138 RefreshRate::ConstructorTag(0)};
139 RefreshRate mExpected90DifferentGroupConfig = {HWC_CONFIG_ID_90, mConfig90DifferentGroup,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100140 Fps(90), RefreshRate::ConstructorTag(0)};
Ady Abrahamabc27602020-04-08 17:20:29 -0700141 RefreshRate mExpected90DifferentResolutionConfig = {HWC_CONFIG_ID_90,
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100142 mConfig90DifferentResolution, Fps(90),
Ady Abrahamabc27602020-04-08 17:20:29 -0700143 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100144 RefreshRate mExpected72Config = {HWC_CONFIG_ID_72, mConfig72, Fps(72.0f),
Ady Abrahamabc27602020-04-08 17:20:29 -0700145 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100146 RefreshRate mExpected30Config = {HWC_CONFIG_ID_30, mConfig30, Fps(30),
Ady Abrahamabc27602020-04-08 17:20:29 -0700147 RefreshRate::ConstructorTag(0)};
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100148 RefreshRate mExpected120Config = {HWC_CONFIG_ID_120, mConfig120, Fps(120),
Ady Abrahamabc27602020-04-08 17:20:29 -0700149 RefreshRate::ConstructorTag(0)};
150
151 Hwc2::mock::Display mDisplay;
152
153private:
154 std::shared_ptr<const HWC2::Display::Config> createConfig(HwcConfigIndexType configId,
155 int32_t configGroup,
156 int64_t vsyncPeriod,
157 int32_t hight = -1,
158 int32_t width = -1);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700159};
160
Ady Abrahamabc27602020-04-08 17:20:29 -0700161using Builder = HWC2::Display::Config::Builder;
162
Alec Mouri0a1cc962019-03-14 12:33:02 -0700163RefreshRateConfigsTest::RefreshRateConfigsTest() {
164 const ::testing::TestInfo* const test_info =
165 ::testing::UnitTest::GetInstance()->current_test_info();
166 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
167}
168
169RefreshRateConfigsTest::~RefreshRateConfigsTest() {
170 const ::testing::TestInfo* const test_info =
171 ::testing::UnitTest::GetInstance()->current_test_info();
172 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
173}
174
Ady Abrahamabc27602020-04-08 17:20:29 -0700175std::shared_ptr<const HWC2::Display::Config> RefreshRateConfigsTest::createConfig(
176 HwcConfigIndexType configId, int32_t configGroup, int64_t vsyncPeriod, int32_t hight,
177 int32_t width) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700178 return HWC2::Display::Config::Builder(mDisplay, hal::HWConfigId(configId.value()))
Ady Abrahamabc27602020-04-08 17:20:29 -0700179 .setVsyncPeriod(int32_t(vsyncPeriod))
180 .setConfigGroup(configGroup)
181 .setHeight(hight)
182 .setWidth(width)
183 .build();
184}
185
Alec Mouri0a1cc962019-03-14 12:33:02 -0700186namespace {
187/* ------------------------------------------------------------------------
188 * Test cases
189 */
Ady Abraham2139f732019-11-13 18:56:40 -0800190TEST_F(RefreshRateConfigsTest, oneDeviceConfig_SwitchingSupported) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700191 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700192 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
193 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700194}
195
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100196TEST_F(RefreshRateConfigsTest, invalidPolicy) {
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100197 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700198 std::make_unique<RefreshRateConfigs>(m60OnlyConfigDevice,
199 /*currentConfigId=*/HWC_CONFIG_ID_60);
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100200 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy(
201 {HwcConfigIndexType(10), {Fps(60), Fps(60)}}),
202 0);
203 ASSERT_LT(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(20), Fps(40)}}),
204 0);
Ana Kruleced3a8cc2019-11-14 00:55:07 +0100205}
206
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700207TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700208 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700209 std::make_unique<RefreshRateConfigs>(m60_90Device,
210 /*currentConfigId=*/HWC_CONFIG_ID_60);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700211
Ady Abraham2e1dd892020-03-05 13:48:36 -0800212 const auto& minRate = refreshRateConfigs->getMinRefreshRate();
213 const auto& performanceRate = refreshRateConfigs->getMaxRefreshRate();
Alec Mouri0a1cc962019-03-14 12:33:02 -0700214
Ady Abrahamabc27602020-04-08 17:20:29 -0700215 ASSERT_EQ(mExpected60Config, minRate);
216 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800217
Ady Abraham2e1dd892020-03-05 13:48:36 -0800218 const auto& minRateByPolicy = refreshRateConfigs->getMinRefreshRateByPolicy();
219 const auto& performanceRateByPolicy = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800220 ASSERT_EQ(minRateByPolicy, minRate);
221 ASSERT_EQ(performanceRateByPolicy, performanceRate);
Alec Mouri0a1cc962019-03-14 12:33:02 -0700222}
Ady Abraham2139f732019-11-13 18:56:40 -0800223
224TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentGroups) {
Ady Abraham2139f732019-11-13 18:56:40 -0800225 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700226 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
227 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800228
Ady Abraham2e1dd892020-03-05 13:48:36 -0800229 const auto& minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
230 const auto& performanceRate = refreshRateConfigs->getMaxRefreshRate();
231 const auto& minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
232 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800233
Ady Abrahamabc27602020-04-08 17:20:29 -0700234 ASSERT_EQ(mExpected60Config, minRate);
235 ASSERT_EQ(mExpected60Config, minRate60);
236 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800237
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100238 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
239 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800240 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
241
Ady Abraham2e1dd892020-03-05 13:48:36 -0800242 const auto& minRate90 = refreshRateConfigs->getMinRefreshRateByPolicy();
243 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800244
Ady Abrahamabc27602020-04-08 17:20:29 -0700245 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate);
246 ASSERT_EQ(mExpected90DifferentGroupConfig, minRate90);
247 ASSERT_EQ(mExpected90DifferentGroupConfig, performanceRate90);
248}
249
250TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentResolutions) {
251 auto refreshRateConfigs =
252 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentResolutions,
253 /*currentConfigId=*/HWC_CONFIG_ID_60);
254
255 const auto& minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
256 const auto& performanceRate = refreshRateConfigs->getMaxRefreshRate();
257 const auto& minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
258 const auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
259
260 ASSERT_EQ(mExpected60Config, minRate);
261 ASSERT_EQ(mExpected60Config, minRate60);
262 ASSERT_EQ(mExpected60Config, performanceRate60);
263
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100264 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(60), Fps(90)}}),
265 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700266 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
267
268 const auto& minRate90 = refreshRateConfigs->getMinRefreshRateByPolicy();
269 const auto& performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy();
270
271 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate);
272 ASSERT_EQ(mExpected90DifferentResolutionConfig, minRate90);
273 ASSERT_EQ(mExpected90DifferentResolutionConfig, performanceRate90);
Ady Abraham2139f732019-11-13 18:56:40 -0800274}
275
276TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_policyChange) {
Ady Abraham2139f732019-11-13 18:56:40 -0800277 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700278 std::make_unique<RefreshRateConfigs>(m60_90Device,
279 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ana Krulec3f6a2062020-01-23 15:48:01 -0800280
Ady Abraham2e1dd892020-03-05 13:48:36 -0800281 auto& minRate = refreshRateConfigs->getMinRefreshRateByPolicy();
282 auto& performanceRate = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abraham2139f732019-11-13 18:56:40 -0800283
Ady Abrahamabc27602020-04-08 17:20:29 -0700284 ASSERT_EQ(mExpected60Config, minRate);
285 ASSERT_EQ(mExpected90Config, performanceRate);
Ady Abraham2139f732019-11-13 18:56:40 -0800286
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100287 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
288 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800289
Ady Abraham2e1dd892020-03-05 13:48:36 -0800290 auto& minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy();
291 auto& performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy();
Ady Abrahamabc27602020-04-08 17:20:29 -0700292 ASSERT_EQ(mExpected60Config, minRate60);
293 ASSERT_EQ(mExpected60Config, performanceRate60);
Ady Abraham2139f732019-11-13 18:56:40 -0800294}
295
296TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getCurrentRefreshRate) {
Ady Abraham2139f732019-11-13 18:56:40 -0800297 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700298 std::make_unique<RefreshRateConfigs>(m60_90Device,
299 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800300 {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800301 auto& current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700302 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_60);
Ady Abraham2139f732019-11-13 18:56:40 -0800303 }
304
305 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
306 {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800307 auto& current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700308 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800309 }
310
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100311 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
312 0);
Ady Abraham2139f732019-11-13 18:56:40 -0800313 {
Ady Abraham2e1dd892020-03-05 13:48:36 -0800314 auto& current = refreshRateConfigs->getCurrentRefreshRate();
Ady Abrahamabc27602020-04-08 17:20:29 -0700315 EXPECT_EQ(current.getConfigId(), HWC_CONFIG_ID_90);
Ady Abraham2139f732019-11-13 18:56:40 -0800316 }
317}
318
Steven Thomasbb374322020-04-28 22:47:16 -0700319TEST_F(RefreshRateConfigsTest, getBestRefreshRate_noLayers) {
Ady Abrahamabc27602020-04-08 17:20:29 -0700320 auto refreshRateConfigs =
321 std::make_unique<RefreshRateConfigs>(m60_72_90Device, /*currentConfigId=*/
322 HWC_CONFIG_ID_72);
Ana Krulec3d367c82020-02-25 15:02:01 -0800323
Steven Thomasdebafed2020-05-18 17:30:35 -0700324 // If there are no layers we select the default frame rate, which is the max of the primary
325 // range.
Ana Krulec3d367c82020-02-25 15:02:01 -0800326 auto layers = std::vector<LayerRequirement>{};
Steven Thomasdebafed2020-05-18 17:30:35 -0700327 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700328 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800329
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100330 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
331 0);
Ady Abrahamabc27602020-04-08 17:20:29 -0700332 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700333 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ana Krulec3d367c82020-02-25 15:02:01 -0800334}
335
Steven Thomasbb374322020-04-28 22:47:16 -0700336TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800337 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700338 std::make_unique<RefreshRateConfigs>(m60_90Device,
339 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800340
341 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
342 auto& lr = layers[0];
343
344 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800345 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700346 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700347 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800348
349 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800350 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700351 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700352 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800353
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100354 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800355 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800356 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700357 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700358 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800359
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100360 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800361 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700362 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700363 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800364
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100365 lr.desiredRefreshRate = Fps(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800366 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700367 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700368 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800369
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100370 lr.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800371 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700372 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700373 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800374
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100375 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800376 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700377 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700378 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800379
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800380 lr.name = "";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100381 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
382 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800383
384 lr.vote = LayerVoteType::Min;
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
388 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700389 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700390 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800391
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100392 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800393 lr.vote = LayerVoteType::Heuristic;
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(60.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(45.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(30.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 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700410 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700411 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800412
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100413 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
414 {HWC_CONFIG_ID_90, {Fps(90.0f), Fps(90.0f)}}),
415 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800416
417 lr.vote = LayerVoteType::Min;
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
421 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700422 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700423 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800424
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100425 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800426 lr.vote = LayerVoteType::Heuristic;
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(60.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(45.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(30.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 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700443 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700444 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800445
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100446 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
447 {HWC_CONFIG_ID_60, {Fps(0.0f), Fps(120.0f)}}),
448 0);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800449 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700450 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700451 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800452
453 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700454 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700455 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800456
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100457 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800458 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700459 EXPECT_EQ(mExpected90Config,
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(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700463 EXPECT_EQ(mExpected60Config,
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(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700467 EXPECT_EQ(mExpected90Config,
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(30.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
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100474 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700475 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700476 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800477}
478
Steven Thomasbb374322020-04-28 22:47:16 -0700479TEST_F(RefreshRateConfigsTest, getBestRefreshRate_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800480 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700481 std::make_unique<RefreshRateConfigs>(m60_72_90Device,
482 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800483
484 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
485 auto& lr = layers[0];
486
487 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700488 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700489 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800490
491 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700492 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700493 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800494
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100495 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800496 lr.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700497 EXPECT_EQ(mExpected90Config,
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(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700501 EXPECT_EQ(mExpected60Config,
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(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700505 EXPECT_EQ(mExpected90Config,
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(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700509 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700510 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800511
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100512 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700513 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700514 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800515}
516
Steven Thomasbb374322020-04-28 22:47:16 -0700517TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90_120) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800518 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700519 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
520 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800521
522 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
523 LayerRequirement{.weight = 1.0f}};
524 auto& lr1 = layers[0];
525 auto& lr2 = layers[1];
526
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100527 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800528 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100529 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800530 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700531 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700532 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800533
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100534 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800535 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100536 lr2.desiredRefreshRate = Fps(48.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800537 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700538 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700539 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800540
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100541 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800542 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100543 lr2.desiredRefreshRate = Fps(48.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800544 lr2.vote = LayerVoteType::Heuristic;
Ady Abrahamabc27602020-04-08 17:20:29 -0700545 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700546 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800547}
548
Steven Thomasbb374322020-04-28 22:47:16 -0700549TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_90_120_DifferentTypes) {
Ady Abraham71c437d2020-01-31 15:56:57 -0800550 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700551 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
552 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham71c437d2020-01-31 15:56:57 -0800553
554 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
555 LayerRequirement{.weight = 1.0f}};
556 auto& lr1 = layers[0];
557 auto& lr2 = layers[1];
558
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100559 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800560 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800561 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100562 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800563 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800564 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700565 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700566 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800567
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100568 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800569 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800570 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100571 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800572 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800573 lr2.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700574 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700575 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800576
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100577 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800578 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800579 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100580 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800581 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800582 lr2.name = "60Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700583 EXPECT_EQ(mExpected120Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700584 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800585
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100586 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800587 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800588 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100589 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800590 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800591 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700592 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700593 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800594
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100595 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800596 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
597 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100598 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800599 lr2.vote = LayerVoteType::ExplicitDefault;
600 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700601 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700602 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800603
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100604 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800605 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800606 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100607 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800608 lr2.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800609 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700610 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700611 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800612
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100613 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800614 lr1.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800615 lr1.name = "24Hz Heuristic";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100616 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800617 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800618 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700619 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700620 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800621
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100622 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800623 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800624 lr1.name = "24Hz ExplicitExactOrMultiple";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100625 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800626 lr2.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800627 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700628 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700629 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800630
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100631 lr1.desiredRefreshRate = Fps(24.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800632 lr1.vote = LayerVoteType::ExplicitDefault;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800633 lr1.name = "24Hz ExplicitDefault";
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100634 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800635 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800636 lr2.name = "90Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700637 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700638 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham71c437d2020-01-31 15:56:57 -0800639}
640
Steven Thomasbb374322020-04-28 22:47:16 -0700641TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800642 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700643 std::make_unique<RefreshRateConfigs>(m30_60Device,
644 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800645
646 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
647 auto& lr = layers[0];
648
649 lr.vote = LayerVoteType::Min;
Ady Abrahamabc27602020-04-08 17:20:29 -0700650 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700651 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800652
653 lr.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700654 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700655 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800656
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100657 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800658 lr.vote = LayerVoteType::Heuristic;
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(60.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(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700667 EXPECT_EQ(mExpected60Config,
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(30.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700671 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700672 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800673
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100674 lr.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700675 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700676 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800677}
678
Steven Thomasbb374322020-04-28 22:47:16 -0700679TEST_F(RefreshRateConfigsTest, getBestRefreshRate_30_60_72_90) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800680 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700681 std::make_unique<RefreshRateConfigs>(m30_60_72_90Device,
682 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800683
684 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
685 auto& lr = layers[0];
686
687 lr.vote = LayerVoteType::Min;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800688 lr.name = "Min";
Ady Abrahamabc27602020-04-08 17:20:29 -0700689 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700690 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800691
692 lr.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800693 lr.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700694 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700695 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800696
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100697 lr.desiredRefreshRate = Fps(90.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800698 lr.vote = LayerVoteType::Heuristic;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800699 lr.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700700 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700701 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800702
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100703 lr.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800704 lr.name = "60Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700705 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700706 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700707 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700708 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800709
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100710 lr.desiredRefreshRate = Fps(45.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800711 lr.name = "45Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700712 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700713 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700714 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700715 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800716
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100717 lr.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800718 lr.name = "30Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700719 EXPECT_EQ(mExpected30Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700720 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700721 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700722 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800723
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100724 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800725 lr.name = "24Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700726 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700727 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700728 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700729 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800730
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100731 lr.desiredRefreshRate = Fps(24.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800732 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
733 lr.name = "24Hz ExplicitExactOrMultiple";
Ady Abrahamabc27602020-04-08 17:20:29 -0700734 EXPECT_EQ(mExpected72Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700735 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abrahamabc27602020-04-08 17:20:29 -0700736 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700737 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800738}
739
Steven Thomasbb374322020-04-28 22:47:16 -0700740TEST_F(RefreshRateConfigsTest, getBestRefreshRate_PriorityTest) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800741 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700742 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
743 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800744
745 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
746 LayerRequirement{.weight = 1.0f}};
747 auto& lr1 = layers[0];
748 auto& lr2 = layers[1];
749
750 lr1.vote = LayerVoteType::Min;
751 lr2.vote = LayerVoteType::Max;
Ady Abrahamabc27602020-04-08 17:20:29 -0700752 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700753 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800754
755 lr1.vote = LayerVoteType::Min;
756 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100757 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700758 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700759 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800760
761 lr1.vote = LayerVoteType::Min;
Ady Abraham71c437d2020-01-31 15:56:57 -0800762 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100763 lr2.desiredRefreshRate = Fps(24.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700764 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700765 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800766
767 lr1.vote = LayerVoteType::Max;
768 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100769 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700770 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700771 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800772
773 lr1.vote = LayerVoteType::Max;
Ady Abraham71c437d2020-01-31 15:56:57 -0800774 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100775 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700776 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700777 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800778
779 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100780 lr1.desiredRefreshRate = Fps(15.0f);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800781 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100782 lr2.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700783 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700784 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800785
786 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100787 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800788 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100789 lr2.desiredRefreshRate = Fps(45.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700790 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700791 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800792}
793
Steven Thomasbb374322020-04-28 22:47:16 -0700794TEST_F(RefreshRateConfigsTest, getBestRefreshRate_24FpsVideo) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800795 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700796 std::make_unique<RefreshRateConfigs>(m60_90Device,
797 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800798
799 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
800 auto& lr = layers[0];
801
Ady Abraham71c437d2020-01-31 15:56:57 -0800802 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abraham8a82ba62020-01-17 12:43:17 -0800803 for (float fps = 23.0f; fps < 25.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100804 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800805 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700806 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700807 EXPECT_EQ(mExpected60Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abraham8a82ba62020-01-17 12:43:17 -0800808 }
809}
810
Steven Thomasbb374322020-04-28 22:47:16 -0700811TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getBestRefreshRate_Explicit) {
Ady Abraham8a82ba62020-01-17 12:43:17 -0800812 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700813 std::make_unique<RefreshRateConfigs>(m60_90Device,
814 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham8a82ba62020-01-17 12:43:17 -0800815
816 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
817 LayerRequirement{.weight = 1.0f}};
818 auto& lr1 = layers[0];
819 auto& lr2 = layers[1];
820
821 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100822 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800823 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100824 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700825 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700826 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800827
828 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100829 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800830 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100831 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700832 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700833 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham8a82ba62020-01-17 12:43:17 -0800834
835 lr1.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100836 lr1.desiredRefreshRate = Fps(90.0f);
Ady Abraham71c437d2020-01-31 15:56:57 -0800837 lr2.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100838 lr2.desiredRefreshRate = Fps(60.0f);
Ady Abrahamabc27602020-04-08 17:20:29 -0700839 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700840 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham2139f732019-11-13 18:56:40 -0800841}
842
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800843TEST_F(RefreshRateConfigsTest, testInPolicy) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100844 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(60.000004f), Fps(60.000004f)));
845 ASSERT_TRUE(mExpectedAlmost60Config.inPolicy(Fps(59.0f), Fps(60.1f)));
846 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(75.0f), Fps(90.0f)));
847 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(60.0011f), Fps(90.0f)));
848 ASSERT_FALSE(mExpectedAlmost60Config.inPolicy(Fps(50.0f), Fps(59.998f)));
Ana Krulec72f0d6e2020-01-06 15:24:47 -0800849}
850
Steven Thomasbb374322020-04-28 22:47:16 -0700851TEST_F(RefreshRateConfigsTest, getBestRefreshRate_75HzContent) {
Ady Abrahamf6b77072020-01-30 14:22:54 -0800852 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700853 std::make_unique<RefreshRateConfigs>(m60_90Device,
854 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abrahamf6b77072020-01-30 14:22:54 -0800855
856 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
857 auto& lr = layers[0];
858
Ady Abraham71c437d2020-01-31 15:56:57 -0800859 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Ady Abrahamf6b77072020-01-30 14:22:54 -0800860 for (float fps = 75.0f; fps < 100.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100861 lr.desiredRefreshRate = Fps(fps);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800862 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -0700863 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -0700864 EXPECT_EQ(mExpected90Config, refreshRate) << fps << "Hz chooses " << refreshRate.getName();
Ady Abrahamf6b77072020-01-30 14:22:54 -0800865 }
866}
867
Steven Thomasbb374322020-04-28 22:47:16 -0700868TEST_F(RefreshRateConfigsTest, getBestRefreshRate_Multiples) {
Ady Abraham34702102020-02-10 14:12:05 -0800869 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700870 std::make_unique<RefreshRateConfigs>(m60_90Device,
871 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham34702102020-02-10 14:12:05 -0800872
873 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
874 LayerRequirement{.weight = 1.0f}};
875 auto& lr1 = layers[0];
876 auto& lr2 = layers[1];
877
878 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100879 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800880 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800881 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100882 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800883 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700884 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700885 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800886
887 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100888 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800889 lr1.name = "60Hz ExplicitExactOrMultiple";
890 lr2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100891 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800892 lr2.name = "90Hz ExplicitDefault";
Ady Abrahamabc27602020-04-08 17:20:29 -0700893 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700894 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800895
896 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100897 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800898 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800899 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800900 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700901 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700902 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800903
904 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100905 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800906 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800907 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100908 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800909 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700910 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700911 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham34702102020-02-10 14:12:05 -0800912
913 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100914 lr1.desiredRefreshRate = Fps(30.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800915 lr1.name = "30Hz ExplicitExactOrMultiple";
Ady Abraham34702102020-02-10 14:12:05 -0800916 lr2.vote = LayerVoteType::Max;
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800917 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700918 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700919 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800920}
921
922TEST_F(RefreshRateConfigsTest, scrollWhileWatching60fps_60_90) {
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800923 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700924 std::make_unique<RefreshRateConfigs>(m60_90Device,
925 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800926
927 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
928 LayerRequirement{.weight = 1.0f}};
929 auto& lr1 = layers[0];
930 auto& lr2 = layers[1];
931
932 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100933 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800934 lr1.name = "60Hz ExplicitExactOrMultiple";
935 lr2.vote = LayerVoteType::NoVote;
936 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700937 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700938 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800939
940 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100941 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800942 lr1.name = "60Hz ExplicitExactOrMultiple";
943 lr2.vote = LayerVoteType::NoVote;
944 lr2.name = "NoVote";
Ady Abrahamabc27602020-04-08 17:20:29 -0700945 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700946 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800947
948 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100949 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800950 lr1.name = "60Hz ExplicitExactOrMultiple";
951 lr2.vote = LayerVoteType::Max;
952 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700953 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700954 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800955
956 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100957 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800958 lr1.name = "60Hz ExplicitExactOrMultiple";
959 lr2.vote = LayerVoteType::Max;
960 lr2.name = "Max";
Ady Abrahamabc27602020-04-08 17:20:29 -0700961 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700962 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800963
964 // The other layer starts to provide buffers
965 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100966 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800967 lr1.name = "60Hz ExplicitExactOrMultiple";
968 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100969 lr2.desiredRefreshRate = Fps(90.0f);
Ady Abraham4ccdcb42020-02-11 17:34:34 -0800970 lr2.name = "90Hz Heuristic";
Ady Abrahamabc27602020-04-08 17:20:29 -0700971 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -0700972 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Ady Abraham6fb599b2020-03-05 13:48:22 -0800973}
974
975TEST_F(RefreshRateConfigsTest, touchConsidered) {
Ady Abrahamdfd62162020-06-10 16:11:56 -0700976 RefreshRateConfigs::GlobalSignals consideredSignals;
Ady Abraham6fb599b2020-03-05 13:48:22 -0800977 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -0700978 std::make_unique<RefreshRateConfigs>(m60_90Device,
979 /*currentConfigId=*/HWC_CONFIG_ID_60);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800980
Ady Abrahamdfd62162020-06-10 16:11:56 -0700981 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false}, &consideredSignals);
982 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800983
Ady Abrahamdfd62162020-06-10 16:11:56 -0700984 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = false}, &consideredSignals);
985 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800986
987 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f},
988 LayerRequirement{.weight = 1.0f}};
989 auto& lr1 = layers[0];
990 auto& lr2 = layers[1];
991
992 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100993 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -0800994 lr1.name = "60Hz ExplicitExactOrMultiple";
995 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100996 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -0700997 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -0700998 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
999 &consideredSignals);
1000 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001001
1002 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001003 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001004 lr1.name = "60Hz ExplicitExactOrMultiple";
1005 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001006 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001007 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001008 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1009 &consideredSignals);
1010 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001011
1012 lr1.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001013 lr1.desiredRefreshRate = Fps(60.0f);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001014 lr1.name = "60Hz ExplicitExactOrMultiple";
1015 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001016 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001017 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001018 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1019 &consideredSignals);
1020 EXPECT_EQ(true, consideredSignals.touch);
Ady Abraham6fb599b2020-03-05 13:48:22 -08001021
1022 lr1.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001023 lr1.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001024 lr1.name = "60Hz ExplicitExactOrMultiple";
Ady Abraham6fb599b2020-03-05 13:48:22 -08001025 lr2.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001026 lr2.desiredRefreshRate = Fps(60.0f);
Steven Thomasf734df42020-04-13 21:09:28 -07001027 lr2.name = "60Hz Heuristic";
Ady Abrahamdfd62162020-06-10 16:11:56 -07001028 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = false},
1029 &consideredSignals);
1030 EXPECT_EQ(false, consideredSignals.touch);
Ady Abraham34702102020-02-10 14:12:05 -08001031}
1032
Steven Thomasbb374322020-04-28 22:47:16 -07001033TEST_F(RefreshRateConfigsTest, getBestRefreshRate_ExplicitDefault) {
Ady Abrahamabc27602020-04-08 17:20:29 -07001034 auto refreshRateConfigs =
1035 std::make_unique<RefreshRateConfigs>(m60_90_72_120Device, /*currentConfigId=*/
1036 HWC_CONFIG_ID_60);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001037
1038 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1039 auto& lr = layers[0];
1040
1041 // Prepare a table with the vote and the expected refresh rate
1042 const std::vector<std::pair<float, float>> testCases = {
1043 {130, 120}, {120, 120}, {119, 120}, {110, 120},
1044
1045 {100, 90}, {90, 90}, {89, 90},
1046
1047 {80, 72}, {73, 72}, {72, 72}, {71, 72}, {70, 72},
1048
1049 {65, 60}, {60, 60}, {59, 60}, {58, 60},
1050
1051 {55, 90}, {50, 90}, {45, 90},
1052
1053 {42, 120}, {40, 120}, {39, 120},
1054
1055 {37, 72}, {36, 72}, {35, 72},
1056
1057 {30, 60},
1058 };
1059
1060 for (const auto& test : testCases) {
1061 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001062 lr.desiredRefreshRate = Fps(test.first);
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001063
1064 std::stringstream ss;
1065 ss << "ExplicitDefault " << test.first << " fps";
1066 lr.name = ss.str();
1067
1068 const auto& refreshRate =
Ady Abrahamdfd62162020-06-10 16:11:56 -07001069 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001070 EXPECT_TRUE(refreshRate.getFps().equalsWithMargin(Fps(test.second)))
Ady Abraham5b8afb5a2020-03-06 14:57:26 -08001071 << "Expecting " << test.first << "fps => " << test.second << "Hz";
1072 }
Alec Mouri0a1cc962019-03-14 12:33:02 -07001073}
1074
Alec Mouri11232a22020-05-14 18:06:25 -07001075TEST_F(RefreshRateConfigsTest,
1076 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresTouchFlag) {
1077 auto refreshRateConfigs =
1078 std::make_unique<RefreshRateConfigs>(m60_90Device,
1079 /*currentConfigId=*/HWC_CONFIG_ID_90);
1080
1081 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001082 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001083 0);
1084
1085 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1086 auto& lr = layers[0];
1087
Ady Abrahamdfd62162020-06-10 16:11:56 -07001088 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001089 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001090 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001091 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001092 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001093 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001094 refreshRateConfigs->getBestRefreshRate(layers, {.touch = true, .idle = true},
1095 &consideredSignals));
1096 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001097}
1098
1099TEST_F(RefreshRateConfigsTest,
1100 getBestRefreshRate_withDisplayManagerRequestingSingleRate_ignoresIdleFlag) {
1101 auto refreshRateConfigs =
1102 std::make_unique<RefreshRateConfigs>(m60_90Device,
1103 /*currentConfigId=*/HWC_CONFIG_ID_60);
1104
1105 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001106 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001107 0);
1108
1109 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1110 auto& lr = layers[0];
1111
Alec Mouri11232a22020-05-14 18:06:25 -07001112 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001113 lr.desiredRefreshRate = Fps(90.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001114 lr.name = "90Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001115 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001116 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001117 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = true}));
Alec Mouri11232a22020-05-14 18:06:25 -07001118}
1119
1120TEST_F(RefreshRateConfigsTest,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001121 getBestRefreshRate_withDisplayManagerRequestingSingleRate_onlySwitchesRatesForExplicitFocusedLayers) {
Alec Mouri11232a22020-05-14 18:06:25 -07001122 auto refreshRateConfigs =
1123 std::make_unique<RefreshRateConfigs>(m60_90Device,
1124 /*currentConfigId=*/HWC_CONFIG_ID_90);
1125
1126 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001127 {HWC_CONFIG_ID_90, {Fps(90.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Alec Mouri11232a22020-05-14 18:06:25 -07001128 0);
1129
Ady Abrahamdfd62162020-06-10 16:11:56 -07001130 RefreshRateConfigs::GlobalSignals consideredSignals;
Alec Mouri11232a22020-05-14 18:06:25 -07001131 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001132 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false},
1133 &consideredSignals));
1134 EXPECT_EQ(false, consideredSignals.touch);
Alec Mouri11232a22020-05-14 18:06:25 -07001135
1136 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1137 auto& lr = layers[0];
1138
1139 lr.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001140 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001141 lr.name = "60Hz ExplicitExactOrMultiple";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001142 lr.focused = false;
1143 EXPECT_EQ(mExpected90Config,
1144 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1145
1146 lr.focused = true;
Ady Abraham20c029c2020-07-06 12:58:05 -07001147 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001148 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001149
1150 lr.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001151 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001152 lr.name = "60Hz ExplicitDefault";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001153 lr.focused = false;
1154 EXPECT_EQ(mExpected90Config,
1155 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1156
1157 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001158 EXPECT_EQ(mExpected60Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001159 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001160
1161 lr.vote = LayerVoteType::Heuristic;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001162 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001163 lr.name = "60Hz Heuristic";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001164 lr.focused = false;
1165 EXPECT_EQ(mExpected90Config,
1166 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1167
1168 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001169 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001170 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001171
1172 lr.vote = LayerVoteType::Max;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001173 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001174 lr.name = "60Hz Max";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001175 lr.focused = false;
1176 EXPECT_EQ(mExpected90Config,
1177 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1178
1179 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001180 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001181 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001182
1183 lr.vote = LayerVoteType::Min;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001184 lr.desiredRefreshRate = Fps(60.0f);
Alec Mouri11232a22020-05-14 18:06:25 -07001185 lr.name = "60Hz Min";
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001186 lr.focused = false;
1187 EXPECT_EQ(mExpected90Config,
1188 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
1189
1190 lr.focused = true;
Alec Mouri11232a22020-05-14 18:06:25 -07001191 EXPECT_EQ(mExpected90Config,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001192 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false}));
Alec Mouri11232a22020-05-14 18:06:25 -07001193}
1194
Steven Thomasd4071902020-03-24 16:02:53 -07001195TEST_F(RefreshRateConfigsTest, groupSwitching) {
Steven Thomasd4071902020-03-24 16:02:53 -07001196 auto refreshRateConfigs =
Ady Abrahamabc27602020-04-08 17:20:29 -07001197 std::make_unique<RefreshRateConfigs>(m60_90DeviceWithDifferentGroups,
1198 /*currentConfigId=*/HWC_CONFIG_ID_60);
Steven Thomasd4071902020-03-24 16:02:53 -07001199
1200 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1201 auto& layer = layers[0];
1202 layer.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001203 layer.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001204 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Steven Thomasd4071902020-03-24 16:02:53 -07001205 layer.name = "90Hz ExplicitDefault";
Marin Shalamanov46084422020-10-13 12:33:42 +02001206 layer.focused = true;
Steven Thomasd4071902020-03-24 16:02:53 -07001207
Steven Thomasd4071902020-03-24 16:02:53 -07001208 ASSERT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001209 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001210 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001211
1212 RefreshRateConfigs::Policy policy;
1213 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1214 policy.allowGroupSwitching = true;
1215 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1216 ASSERT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001217 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
Ady Abrahamabc27602020-04-08 17:20:29 -07001218 .getConfigId());
Marin Shalamanov46084422020-10-13 12:33:42 +02001219
1220 // Verify that we won't change the group if seamless switch is required.
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001221 layer.seamlessness = Seamlessness::OnlySeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001222 ASSERT_EQ(HWC_CONFIG_ID_60,
1223 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1224 .getConfigId());
1225
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001226 // 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 +02001227 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001228 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001229 layer.name = "60Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001230 layer.seamlessness = Seamlessness::OnlySeamless;
1231 ASSERT_EQ(HWC_CONFIG_ID_90,
1232 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1233 .getConfigId());
1234
1235 // Verify that if the current config is in another group and there are no layers with
1236 // seamlessness=SeamedAndSeamless we'll go back to the default group.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001237 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001238 layer.name = "60Hz ExplicitDefault";
1239 layer.seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001240 ASSERT_EQ(HWC_CONFIG_ID_60,
1241 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1242 .getConfigId());
1243
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001244 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1245 // seamlessness=OnlySeamless can't change the config group.
Marin Shalamanov46084422020-10-13 12:33:42 +02001246 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001247 layer.seamlessness = Seamlessness::OnlySeamless;
1248
1249 layers.push_back(LayerRequirement{.weight = 0.5f});
1250 auto& layer2 = layers[layers.size() - 1];
Marin Shalamanov46084422020-10-13 12:33:42 +02001251 layer2.vote = LayerVoteType::ExplicitDefault;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001252 layer2.desiredRefreshRate = Fps(90.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001253 layer2.name = "90Hz ExplicitDefault";
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001254 layer2.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001255 layer2.focused = false;
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001256
1257 ASSERT_EQ(HWC_CONFIG_ID_90,
1258 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1259 .getConfigId());
1260
1261 // If there's a layer with seamlessness=SeamedAndSeamless, another layer with
1262 // seamlessness=Default can't change the config group.
1263 layers[0].seamlessness = Seamlessness::Default;
Marin Shalamanov46084422020-10-13 12:33:42 +02001264 ASSERT_EQ(HWC_CONFIG_ID_90,
1265 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1266 .getConfigId());
1267}
1268
1269TEST_F(RefreshRateConfigsTest, nonSeamlessVotePrefersSeamlessSwitches) {
1270 auto refreshRateConfigs =
1271 std::make_unique<RefreshRateConfigs>(m30_60Device,
1272 /*currentConfigId=*/HWC_CONFIG_ID_60);
1273
1274 // Allow group switching.
1275 RefreshRateConfigs::Policy policy;
1276 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1277 policy.allowGroupSwitching = true;
1278 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1279
1280 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1281 auto& layer = layers[0];
1282 layer.vote = LayerVoteType::ExplicitExactOrMultiple;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001283 layer.desiredRefreshRate = Fps(60.0f);
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001284 layer.seamlessness = Seamlessness::SeamedAndSeamless;
Marin Shalamanov46084422020-10-13 12:33:42 +02001285 layer.name = "60Hz ExplicitExactOrMultiple";
1286 layer.focused = true;
1287
1288 ASSERT_EQ(HWC_CONFIG_ID_60,
1289 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1290 .getConfigId());
1291
1292 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
1293 ASSERT_EQ(HWC_CONFIG_ID_120,
1294 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1295 .getConfigId());
1296}
1297
1298TEST_F(RefreshRateConfigsTest, nonSeamlessExactAndSeamlessMultipleLayers) {
1299 auto refreshRateConfigs =
1300 std::make_unique<RefreshRateConfigs>(m25_30_50_60Device,
1301 /*currentConfigId=*/HWC_CONFIG_ID_60);
1302
1303 // Allow group switching.
1304 RefreshRateConfigs::Policy policy;
1305 policy.defaultConfig = refreshRateConfigs->getCurrentPolicy().defaultConfig;
1306 policy.allowGroupSwitching = true;
1307 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(policy), 0);
1308
1309 auto layers = std::vector<
1310 LayerRequirement>{LayerRequirement{.name = "60Hz ExplicitDefault",
1311 .vote = LayerVoteType::ExplicitDefault,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001312 .desiredRefreshRate = Fps(60.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001313 .seamlessness = Seamlessness::SeamedAndSeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001314 .weight = 0.5f,
1315 .focused = false},
1316 LayerRequirement{.name = "25Hz ExplicitExactOrMultiple",
1317 .vote = LayerVoteType::ExplicitExactOrMultiple,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001318 .desiredRefreshRate = Fps(25.0f),
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01001319 .seamlessness = Seamlessness::OnlySeamless,
Marin Shalamanov46084422020-10-13 12:33:42 +02001320 .weight = 1.0f,
1321 .focused = true}};
1322 auto& seamedLayer = layers[0];
1323
1324 ASSERT_EQ(HWC_CONFIG_ID_50,
1325 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1326 .getConfigId());
1327
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001328 seamedLayer.name = "30Hz ExplicitDefault", seamedLayer.desiredRefreshRate = Fps(30.0f);
Marin Shalamanov46084422020-10-13 12:33:42 +02001329 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_30);
1330
1331 ASSERT_EQ(HWC_CONFIG_ID_25,
1332 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false})
1333 .getConfigId());
Steven Thomasd4071902020-03-24 16:02:53 -07001334}
1335
Steven Thomasf734df42020-04-13 21:09:28 -07001336TEST_F(RefreshRateConfigsTest, primaryVsAppRequestPolicy) {
1337 auto refreshRateConfigs =
Alec Mouri11232a22020-05-14 18:06:25 -07001338 std::make_unique<RefreshRateConfigs>(m30_60_90Device,
Steven Thomasf734df42020-04-13 21:09:28 -07001339 /*currentConfigId=*/HWC_CONFIG_ID_60);
1340
1341 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1342 layers[0].name = "Test layer";
1343
Steven Thomasbb374322020-04-28 22:47:16 -07001344 // Return the config ID from calling getBestRefreshRate() for a single layer with the
Steven Thomasf734df42020-04-13 21:09:28 -07001345 // given voteType and fps.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001346 auto getFrameRate = [&](LayerVoteType voteType, Fps fps, bool touchActive = false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001347 bool focused = true) -> HwcConfigIndexType {
Steven Thomasf734df42020-04-13 21:09:28 -07001348 layers[0].vote = voteType;
1349 layers[0].desiredRefreshRate = fps;
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001350 layers[0].focused = focused;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001351 return refreshRateConfigs->getBestRefreshRate(layers, {.touch = touchActive, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001352 .getConfigId();
1353 };
1354
1355 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001356 {HWC_CONFIG_ID_60, {Fps(30.f), Fps(60.f)}, {Fps(30.f), Fps(90.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001357 0);
Steven Thomasf734df42020-04-13 21:09:28 -07001358 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001359 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = false})
Steven Thomasf734df42020-04-13 21:09:28 -07001360 .getConfigId());
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001361 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1362 EXPECT_EQ(HWC_CONFIG_ID_30, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1363 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1364 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1365 EXPECT_EQ(HWC_CONFIG_ID_90, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1366 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001367
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001368 // Layers not focused are not allowed to override primary config
1369 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001370 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001371 /*focused=*/false));
1372 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001373 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/false,
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001374 /*focused=*/false));
1375
Steven Thomasf734df42020-04-13 21:09:28 -07001376 // Touch boost should be restricted to the primary range.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001377 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001378 // When we're higher than the primary range max due to a layer frame rate setting, touch boost
1379 // shouldn't drag us back down to the primary range max.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001380 EXPECT_EQ(HWC_CONFIG_ID_90,
1381 getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f), /*touch=*/true));
Ady Abraham20c029c2020-07-06 12:58:05 -07001382 EXPECT_EQ(HWC_CONFIG_ID_60,
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001383 getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f), /*touch=*/true));
Steven Thomasf734df42020-04-13 21:09:28 -07001384
1385 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001386 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(60.f)}, {Fps(60.f), Fps(60.f)}}),
Steven Thomasf734df42020-04-13 21:09:28 -07001387 0);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001388 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::NoVote, Fps(90.f)));
1389 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Min, Fps(90.f)));
1390 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Max, Fps(90.f)));
1391 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::Heuristic, Fps(90.f)));
1392 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitDefault, Fps(90.f)));
1393 EXPECT_EQ(HWC_CONFIG_ID_60, getFrameRate(LayerVoteType::ExplicitExactOrMultiple, Fps(90.f)));
Steven Thomasf734df42020-04-13 21:09:28 -07001394}
1395
Steven Thomasbb374322020-04-28 22:47:16 -07001396TEST_F(RefreshRateConfigsTest, idle) {
1397 auto refreshRateConfigs =
1398 std::make_unique<RefreshRateConfigs>(m60_90Device,
1399 /*currentConfigId=*/HWC_CONFIG_ID_60);
1400
1401 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1402 layers[0].name = "Test layer";
1403
Ady Abrahamdfd62162020-06-10 16:11:56 -07001404 const auto getIdleFrameRate = [&](LayerVoteType voteType,
1405 bool touchActive) -> HwcConfigIndexType {
Steven Thomasbb374322020-04-28 22:47:16 -07001406 layers[0].vote = voteType;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001407 layers[0].desiredRefreshRate = Fps(90.f);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001408 RefreshRateConfigs::GlobalSignals consideredSignals;
1409 const auto configId =
1410 refreshRateConfigs
1411 ->getBestRefreshRate(layers, {.touch = touchActive, .idle = true},
1412 &consideredSignals)
1413 .getConfigId();
1414 // Refresh rate will be chosen by either touch state or idle state
1415 EXPECT_EQ(!touchActive, consideredSignals.idle);
1416 return configId;
Steven Thomasbb374322020-04-28 22:47:16 -07001417 };
1418
1419 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy(
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001420 {HWC_CONFIG_ID_60, {Fps(60.f), Fps(90.f)}, {Fps(60.f), Fps(90.f)}}),
Steven Thomasbb374322020-04-28 22:47:16 -07001421 0);
1422
1423 // Idle should be lower priority than touch boost.
Ady Abrahamdfd62162020-06-10 16:11:56 -07001424 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/true));
1425 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/true));
1426 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/true));
1427 EXPECT_EQ(HWC_CONFIG_ID_90, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/true));
1428 EXPECT_EQ(HWC_CONFIG_ID_90,
1429 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/true));
1430 EXPECT_EQ(HWC_CONFIG_ID_90,
1431 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/true));
Steven Thomasbb374322020-04-28 22:47:16 -07001432
1433 // With no layers, idle should still be lower priority than touch boost.
Steven Thomasbb374322020-04-28 22:47:16 -07001434 EXPECT_EQ(HWC_CONFIG_ID_90,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001435 refreshRateConfigs->getBestRefreshRate({}, {.touch = true, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001436 .getConfigId());
1437
1438 // Idle should be higher precedence than other layer frame rate considerations.
1439 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abrahamdfd62162020-06-10 16:11:56 -07001440 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::NoVote, /*touchActive=*/false));
1441 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Min, /*touchActive=*/false));
1442 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Max, /*touchActive=*/false));
1443 EXPECT_EQ(HWC_CONFIG_ID_60, getIdleFrameRate(LayerVoteType::Heuristic, /*touchActive=*/false));
1444 EXPECT_EQ(HWC_CONFIG_ID_60,
1445 getIdleFrameRate(LayerVoteType::ExplicitDefault, /*touchActive=*/false));
1446 EXPECT_EQ(HWC_CONFIG_ID_60,
1447 getIdleFrameRate(LayerVoteType::ExplicitExactOrMultiple, /*touchActive=*/false));
Steven Thomasbb374322020-04-28 22:47:16 -07001448
1449 // Idle should be applied rather than the current config when there are no layers.
1450 EXPECT_EQ(HWC_CONFIG_ID_60,
Ady Abrahamdfd62162020-06-10 16:11:56 -07001451 refreshRateConfigs->getBestRefreshRate({}, {.touch = false, .idle = true})
Steven Thomasbb374322020-04-28 22:47:16 -07001452 .getConfigId());
1453}
1454
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001455TEST_F(RefreshRateConfigsTest, findClosestKnownFrameRate) {
1456 auto refreshRateConfigs =
1457 std::make_unique<RefreshRateConfigs>(m60_90Device,
1458 /*currentConfigId=*/HWC_CONFIG_ID_60);
1459
1460 for (float fps = 1.0f; fps <= 120.0f; fps += 0.1f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001461 const auto knownFrameRate = findClosestKnownFrameRate(*refreshRateConfigs, Fps(fps));
1462 Fps expectedFrameRate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001463 if (fps < 26.91f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001464 expectedFrameRate = Fps(24.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001465 } else if (fps < 37.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001466 expectedFrameRate = Fps(30.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001467 } else if (fps < 52.51f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001468 expectedFrameRate = Fps(45.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001469 } else if (fps < 66.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001470 expectedFrameRate = Fps(60.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001471 } else if (fps < 81.01f) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001472 expectedFrameRate = Fps(72.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001473 } else {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001474 expectedFrameRate = Fps(90.0f);
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001475 }
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001476 EXPECT_TRUE(expectedFrameRate.equalsWithMargin(knownFrameRate))
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001477 << "findClosestKnownFrameRate(" << fps << ") = " << knownFrameRate;
1478 }
1479}
1480
1481TEST_F(RefreshRateConfigsTest, getBestRefreshRate_KnownFrameRate) {
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001482 auto refreshRateConfigs =
1483 std::make_unique<RefreshRateConfigs>(m60_90Device,
1484 /*currentConfigId=*/HWC_CONFIG_ID_60);
1485
1486 struct ExpectedRate {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001487 Fps rate;
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001488 const RefreshRate& expected;
1489 };
1490
1491 /* clang-format off */
1492 std::vector<ExpectedRate> knownFrameRatesExpectations = {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001493 {Fps(24.0f), mExpected60Config},
1494 {Fps(30.0f), mExpected60Config},
1495 {Fps(45.0f), mExpected90Config},
1496 {Fps(60.0f), mExpected60Config},
1497 {Fps(72.0f), mExpected90Config},
1498 {Fps(90.0f), mExpected90Config},
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001499 };
1500 /* clang-format on */
1501
1502 // Make sure the test tests all the known frame rate
1503 const auto knownFrameRateList = getKnownFrameRate(*refreshRateConfigs);
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001504 const auto equal =
1505 std::equal(knownFrameRateList.begin(), knownFrameRateList.end(),
1506 knownFrameRatesExpectations.begin(),
1507 [](Fps a, const ExpectedRate& b) { return a.equalsWithMargin(b.rate); });
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001508 EXPECT_TRUE(equal);
1509
1510 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1511 auto& layer = layers[0];
1512 layer.vote = LayerVoteType::Heuristic;
1513 for (const auto& expectedRate : knownFrameRatesExpectations) {
1514 layer.desiredRefreshRate = expectedRate.rate;
Ady Abrahamdfd62162020-06-10 16:11:56 -07001515 const auto& refreshRate =
1516 refreshRateConfigs->getBestRefreshRate(layers, {.touch = false, .idle = false});
Ady Abrahamb1b9d412020-06-01 19:53:52 -07001517 EXPECT_EQ(expectedRate.expected, refreshRate);
1518 }
1519}
1520
Ana Krulecb9afd792020-06-11 13:16:15 -07001521TEST_F(RefreshRateConfigsTest, testComparisonOperator) {
1522 EXPECT_TRUE(mExpected60Config < mExpected90Config);
1523 EXPECT_FALSE(mExpected60Config < mExpected60Config);
1524 EXPECT_FALSE(mExpected90Config < mExpected90Config);
1525}
1526
1527TEST_F(RefreshRateConfigsTest, testKernelIdleTimerAction) {
1528 using KernelIdleTimerAction = scheduler::RefreshRateConfigs::KernelIdleTimerAction;
1529
1530 auto refreshRateConfigs =
1531 std::make_unique<RefreshRateConfigs>(m60_90Device,
1532 /*currentConfigId=*/HWC_CONFIG_ID_90);
1533 // SetPolicy(60, 90), current 90Hz => TurnOn.
1534 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1535
1536 // SetPolicy(60, 90), current 60Hz => TurnOn.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001537 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(90)}}),
1538 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001539 EXPECT_EQ(KernelIdleTimerAction::TurnOn, refreshRateConfigs->getIdleTimerAction());
1540
1541 // SetPolicy(60, 60), current 60Hz => NoChange, avoid extra calls.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001542 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_60, {Fps(60), Fps(60)}}),
1543 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001544 EXPECT_EQ(KernelIdleTimerAction::NoChange, refreshRateConfigs->getIdleTimerAction());
1545
1546 // SetPolicy(90, 90), current 90Hz => TurnOff.
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001547 ASSERT_GE(refreshRateConfigs->setDisplayManagerPolicy({HWC_CONFIG_ID_90, {Fps(90), Fps(90)}}),
1548 0);
Ana Krulecb9afd792020-06-11 13:16:15 -07001549 EXPECT_EQ(KernelIdleTimerAction::TurnOff, refreshRateConfigs->getIdleTimerAction());
1550}
1551
Ady Abraham0bb6a472020-10-12 10:22:13 -07001552TEST_F(RefreshRateConfigsTest, RefreshRateDividerForUid) {
1553 auto refreshRateConfigs =
1554 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device,
1555 /*currentConfigId=*/HWC_CONFIG_ID_30);
Ady Abraham62a0be22020-12-08 16:54:10 -08001556
1557 const auto frameRate = Fps(30.f);
1558 EXPECT_EQ(1, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001559
1560 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_60);
Ady Abraham62a0be22020-12-08 16:54:10 -08001561 EXPECT_EQ(2, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001562
1563 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_72);
Ady Abraham62a0be22020-12-08 16:54:10 -08001564 EXPECT_EQ(0, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001565
1566 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001567 EXPECT_EQ(3, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham0bb6a472020-10-12 10:22:13 -07001568
1569 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_120);
Ady Abraham62a0be22020-12-08 16:54:10 -08001570 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(frameRate));
Ady Abraham62f216c2020-10-13 19:07:23 -07001571
1572 refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90);
Ady Abraham62a0be22020-12-08 16:54:10 -08001573 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.5f)));
1574 EXPECT_EQ(4, refreshRateConfigs->getRefreshRateDivider(Fps(22.6f)));
1575}
1576
1577TEST_F(RefreshRateConfigsTest, populatePreferredFrameRate_noLayers) {
1578 auto refreshRateConfigs =
1579 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1580 HWC_CONFIG_ID_120);
1581
1582 auto layers = std::vector<LayerRequirement>{};
1583 ASSERT_TRUE(refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f)).empty());
1584}
1585
1586TEST_F(RefreshRateConfigsTest, getFrameRateOverrides_60on120) {
1587 auto refreshRateConfigs =
1588 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1589 HWC_CONFIG_ID_120);
1590
1591 auto layers = std::vector<LayerRequirement>{LayerRequirement{.weight = 1.0f}};
1592 layers[0].name = "Test layer";
1593 layers[0].ownerUid = 1234;
1594 layers[0].desiredRefreshRate = Fps(60.0f);
1595 layers[0].vote = LayerVoteType::ExplicitDefault;
1596 auto frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1597 ASSERT_EQ(1, frameRateOverrides.size());
1598 ASSERT_EQ(1, frameRateOverrides.count(1234));
1599 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1600
1601 layers[0].vote = LayerVoteType::ExplicitExactOrMultiple;
1602 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1603 ASSERT_EQ(1, frameRateOverrides.size());
1604 ASSERT_EQ(1, frameRateOverrides.count(1234));
1605 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1606
1607 layers[0].vote = LayerVoteType::NoVote;
1608 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1609 ASSERT_TRUE(frameRateOverrides.empty());
1610
1611 layers[0].vote = LayerVoteType::Min;
1612 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1613 ASSERT_TRUE(frameRateOverrides.empty());
1614
1615 layers[0].vote = LayerVoteType::Max;
1616 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1617 ASSERT_TRUE(frameRateOverrides.empty());
1618
1619 layers[0].vote = LayerVoteType::Heuristic;
1620 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1621 ASSERT_TRUE(frameRateOverrides.empty());
1622}
1623
1624TEST_F(RefreshRateConfigsTest, populatePreferredFrameRate_twoUids) {
1625 auto refreshRateConfigs =
1626 std::make_unique<RefreshRateConfigs>(m30_60_72_90_120Device, /*currentConfigId=*/
1627 HWC_CONFIG_ID_120);
1628
1629 auto layers = std::vector<LayerRequirement>{
1630 LayerRequirement{.ownerUid = 1234, .weight = 1.0f},
1631 LayerRequirement{.ownerUid = 5678, .weight = 1.0f},
1632 };
1633
1634 layers[0].name = "Test layer 1234";
1635 layers[0].desiredRefreshRate = Fps(60.0f);
1636 layers[0].vote = LayerVoteType::ExplicitDefault;
1637
1638 layers[1].name = "Test layer 5678";
1639 layers[1].desiredRefreshRate = Fps(30.0f);
1640 layers[1].vote = LayerVoteType::ExplicitDefault;
1641 auto frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1642
1643 ASSERT_EQ(2, frameRateOverrides.size());
1644 ASSERT_EQ(1, frameRateOverrides.count(1234));
1645 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1646 ASSERT_EQ(1, frameRateOverrides.count(5678));
1647 ASSERT_EQ(30.0f, frameRateOverrides.at(5678).getValue());
1648
1649 layers[1].vote = LayerVoteType::Heuristic;
1650 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1651 ASSERT_EQ(1, frameRateOverrides.size());
1652 ASSERT_EQ(1, frameRateOverrides.count(1234));
1653 ASSERT_EQ(60.0f, frameRateOverrides.at(1234).getValue());
1654
1655 layers[1].ownerUid = 1234;
1656 frameRateOverrides = refreshRateConfigs->getFrameRateOverrides(layers, Fps(120.0f));
1657 ASSERT_TRUE(frameRateOverrides.empty());
Ady Abraham0bb6a472020-10-12 10:22:13 -07001658}
1659
Alec Mouri0a1cc962019-03-14 12:33:02 -07001660} // namespace
1661} // namespace scheduler
1662} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001663
1664// TODO(b/129481165): remove the #pragma below and fix conversion issues
1665#pragma clang diagnostic pop // ignored "-Wextra"