• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #undef LOG_TAG
18 #define LOG_TAG "FrameRateOverrideMappingsTest"
19 
20 #include <gtest/gtest.h>
21 #include <unordered_map>
22 
23 #include "Scheduler/FrameRateOverrideMappings.h"
24 
25 namespace android::scheduler {
26 
27 using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride;
28 using UidToFrameRateOverride = std::map<uid_t, Fps>;
29 
30 class FrameRateOverrideMappingsTest : public testing::Test {
31 protected:
32     FrameRateOverrideMappings mFrameRateOverrideMappings;
33     UidToFrameRateOverride mFrameRateOverrideByContent;
34 };
35 
36 namespace {
TEST_F(FrameRateOverrideMappingsTest,testUpdateFrameRateOverridesByContent)37 TEST_F(FrameRateOverrideMappingsTest, testUpdateFrameRateOverridesByContent) {
38     mFrameRateOverrideByContent.clear();
39     mFrameRateOverrideByContent.emplace(0, 30.0_Hz);
40     mFrameRateOverrideByContent.emplace(1, 60.0_Hz);
41     ASSERT_TRUE(mFrameRateOverrideMappings.updateFrameRateOverridesByContent(
42             mFrameRateOverrideByContent));
43 
44     ASSERT_TRUE(isApproxEqual(30.0_Hz,
45                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
46                                       0, /*supportsFrameRateOverrideByContent*/ true)));
47     ASSERT_TRUE(isApproxEqual(60.0_Hz,
48                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
49                                       1, /*supportsFrameRateOverrideByContent*/ true)));
50     ASSERT_EQ(std::nullopt,
51               mFrameRateOverrideMappings
52                       .getFrameRateOverrideForUid(1, /*supportsFrameRateOverrideByContent*/ false));
53     ASSERT_EQ(std::nullopt,
54               mFrameRateOverrideMappings
55                       .getFrameRateOverrideForUid(3, /*supportsFrameRateOverrideByContent*/ true));
56     ASSERT_EQ(std::nullopt,
57               mFrameRateOverrideMappings
58                       .getFrameRateOverrideForUid(3, /*supportsFrameRateOverrideByContent*/ false));
59 }
60 
TEST_F(FrameRateOverrideMappingsTest,testSetGameModeRefreshRateForUid)61 TEST_F(FrameRateOverrideMappingsTest, testSetGameModeRefreshRateForUid) {
62     mFrameRateOverrideMappings.setGameModeRefreshRateForUid({1, 30.0f});
63     mFrameRateOverrideMappings.setGameModeRefreshRateForUid({2, 90.0f});
64 
65     ASSERT_TRUE(isApproxEqual(30.0_Hz,
66                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
67                                       1, /*supportsFrameRateOverrideByContent*/ true)));
68     ASSERT_TRUE(isApproxEqual(90.0_Hz,
69                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
70                                       2, /*supportsFrameRateOverrideByContent*/ false)));
71     ASSERT_EQ(std::nullopt,
72               mFrameRateOverrideMappings
73                       .getFrameRateOverrideForUid(0, /*supportsFrameRateOverrideByContent*/ true));
74     ASSERT_EQ(std::nullopt,
75               mFrameRateOverrideMappings
76                       .getFrameRateOverrideForUid(0, /*supportsFrameRateOverrideByContent*/ false));
77 }
78 
TEST_F(FrameRateOverrideMappingsTest,testSetPreferredRefreshRateForUid)79 TEST_F(FrameRateOverrideMappingsTest, testSetPreferredRefreshRateForUid) {
80     mFrameRateOverrideMappings.setPreferredRefreshRateForUid({0, 60.0f});
81     mFrameRateOverrideMappings.setPreferredRefreshRateForUid({2, 120.0f});
82 
83     ASSERT_TRUE(isApproxEqual(60.0_Hz,
84                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
85                                       0, /*supportsFrameRateOverrideByContent*/ true)));
86     ASSERT_TRUE(isApproxEqual(120.0_Hz,
87                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
88                                       2, /*supportsFrameRateOverrideByContent*/ false)));
89     ASSERT_EQ(std::nullopt,
90               mFrameRateOverrideMappings
91                       .getFrameRateOverrideForUid(1, /*supportsFrameRateOverrideByContent*/ true));
92     ASSERT_EQ(std::nullopt,
93               mFrameRateOverrideMappings
94                       .getFrameRateOverrideForUid(1, /*supportsFrameRateOverrideByContent*/ false));
95 }
96 
TEST_F(FrameRateOverrideMappingsTest,testGetFrameRateOverrideForUidMixed)97 TEST_F(FrameRateOverrideMappingsTest, testGetFrameRateOverrideForUidMixed) {
98     mFrameRateOverrideByContent.clear();
99     mFrameRateOverrideByContent.emplace(0, 30.0_Hz);
100     mFrameRateOverrideByContent.emplace(1, 60.0_Hz);
101     mFrameRateOverrideByContent.emplace(2, 45.0_Hz);
102     mFrameRateOverrideByContent.emplace(5, 120.0_Hz);
103     ASSERT_TRUE(mFrameRateOverrideMappings.updateFrameRateOverridesByContent(
104             mFrameRateOverrideByContent));
105 
106     std::vector<FrameRateOverride> allFrameRateOverrides;
107     ASSERT_EQ(allFrameRateOverrides,
108               mFrameRateOverrideMappings.getAllFrameRateOverrides(
109                       /*supportsFrameRateOverrideByContent*/ false));
110     allFrameRateOverrides = {{0, 30.0f}, {1, 60.0f}, {2, 45.0f}, {5, 120.0f}};
111     ASSERT_EQ(allFrameRateOverrides,
112               mFrameRateOverrideMappings.getAllFrameRateOverrides(
113                       /*supportsFrameRateOverrideByContent*/ true));
114 
115     mFrameRateOverrideMappings.setGameModeRefreshRateForUid({1, 30.0f});
116     mFrameRateOverrideMappings.setGameModeRefreshRateForUid({2, 90.0f});
117     mFrameRateOverrideMappings.setGameModeRefreshRateForUid({4, 120.0f});
118 
119     allFrameRateOverrides.clear();
120     allFrameRateOverrides = {{1, 30.0f}, {2, 90.0f}, {4, 120.0f}};
121     ASSERT_EQ(allFrameRateOverrides,
122               mFrameRateOverrideMappings.getAllFrameRateOverrides(
123                       /*supportsFrameRateOverrideByContent*/ false));
124     allFrameRateOverrides.clear();
125     allFrameRateOverrides = {{1, 30.0f}, {2, 90.0f}, {4, 120.0f}, {0, 30.0f}, {5, 120.0f}};
126     ASSERT_EQ(allFrameRateOverrides,
127               mFrameRateOverrideMappings.getAllFrameRateOverrides(
128                       /*supportsFrameRateOverrideByContent*/ true));
129 
130     mFrameRateOverrideMappings.setPreferredRefreshRateForUid({0, 60.0f});
131     mFrameRateOverrideMappings.setPreferredRefreshRateForUid({2, 120.0f});
132     mFrameRateOverrideMappings.setPreferredRefreshRateForUid({3, 30.0f});
133 
134     allFrameRateOverrides.clear();
135     allFrameRateOverrides = {{0, 60.0f}, {2, 120.0f}, {3, 30.0f}, {1, 30.0f}, {4, 120.0f}};
136     ASSERT_EQ(allFrameRateOverrides,
137               mFrameRateOverrideMappings.getAllFrameRateOverrides(
138                       /*supportsFrameRateOverrideByContent*/ false));
139     allFrameRateOverrides.clear();
140     allFrameRateOverrides = {{0, 60.0f}, {2, 120.0f}, {3, 30.0f},
141                              {1, 30.0f}, {4, 120.0f}, {5, 120.0f}};
142     ASSERT_EQ(allFrameRateOverrides,
143               mFrameRateOverrideMappings.getAllFrameRateOverrides(
144                       /*supportsFrameRateOverrideByContent*/ true));
145 
146     ASSERT_TRUE(isApproxEqual(60.0_Hz,
147                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
148                                       0, /*supportsFrameRateOverrideByContent*/ true)));
149     ASSERT_TRUE(isApproxEqual(30.0_Hz,
150                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
151                                       1, /*supportsFrameRateOverrideByContent*/ true)));
152     ASSERT_TRUE(isApproxEqual(120.0_Hz,
153                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
154                                       2, /*supportsFrameRateOverrideByContent*/ true)));
155     ASSERT_TRUE(isApproxEqual(30.0_Hz,
156                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
157                                       3, /*supportsFrameRateOverrideByContent*/ true)));
158     ASSERT_TRUE(isApproxEqual(120.0_Hz,
159                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
160                                       4, /*supportsFrameRateOverrideByContent*/ true)));
161     ASSERT_TRUE(isApproxEqual(120.0_Hz,
162                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
163                                       5, /*supportsFrameRateOverrideByContent*/ true)));
164 
165     ASSERT_TRUE(isApproxEqual(60.0_Hz,
166                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
167                                       0, /*supportsFrameRateOverrideByContent*/ false)));
168     ASSERT_TRUE(isApproxEqual(30.0_Hz,
169                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
170                                       1, /*supportsFrameRateOverrideByContent*/ false)));
171     ASSERT_TRUE(isApproxEqual(120.0_Hz,
172                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
173                                       2, /*supportsFrameRateOverrideByContent*/ false)));
174     ASSERT_TRUE(isApproxEqual(30.0_Hz,
175                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
176                                       3, /*supportsFrameRateOverrideByContent*/ false)));
177     ASSERT_TRUE(isApproxEqual(120.0_Hz,
178                               *mFrameRateOverrideMappings.getFrameRateOverrideForUid(
179                                       4, /*supportsFrameRateOverrideByContent*/ false)));
180     ASSERT_EQ(std::nullopt,
181               mFrameRateOverrideMappings
182                       .getFrameRateOverrideForUid(5, /*supportsFrameRateOverrideByContent*/ false));
183 }
184 } // namespace
185 } // namespace android::scheduler
186