• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // TODO(b/129481165): remove the #pragma below and fix conversion issues
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wextra"
20 
21 #include <gtest/gtest.h>
22 #include <gui/ISurfaceComposer.h>
23 #include <gui/SurfaceComposerClient.h>
24 #include <private/gui/ComposerService.h>
25 #include <ui/DisplayMode.h>
26 #include <ui/DynamicDisplayInfo.h>
27 #include <utils/Errors.h>
28 #include <utils/Vector.h>
29 
30 #include "utils/TransactionUtils.h"
31 
32 namespace android {
33 
34 ::testing::Environment* const binderEnv =
35         ::testing::AddGlobalTestEnvironment(new BinderEnvironment());
36 
37 /**
38  * Test class for setting display configs and passing around refresh rate ranges.
39  */
40 class RefreshRateRangeTest : public ::testing::Test {
41 private:
42     ui::DisplayModeId initialDefaultMode;
43     bool initialAllowGroupSwitching;
44     float initialPrimaryMin;
45     float initialPrimaryMax;
46     float initialAppRequestMin;
47     float initialAppRequestMax;
48 
49 protected:
SetUp()50     void SetUp() override {
51         mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
52         status_t res =
53                 SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken,
54                                                                   &initialDefaultMode,
55                                                                   &initialAllowGroupSwitching,
56                                                                   &initialPrimaryMin,
57                                                                   &initialPrimaryMax,
58                                                                   &initialAppRequestMin,
59                                                                   &initialAppRequestMax);
60         ASSERT_EQ(res, NO_ERROR);
61     }
62 
TearDown()63     void TearDown() override {
64         status_t res =
65                 SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, initialDefaultMode,
66                                                                   initialAllowGroupSwitching,
67                                                                   initialPrimaryMin,
68                                                                   initialPrimaryMax,
69                                                                   initialAppRequestMin,
70                                                                   initialAppRequestMax);
71         ASSERT_EQ(res, NO_ERROR);
72     }
73 
74     void testSetAllowGroupSwitching(bool allowGroupSwitching);
75 
76     sp<IBinder> mDisplayToken;
77 };
78 
TEST_F(RefreshRateRangeTest,setAllConfigs)79 TEST_F(RefreshRateRangeTest, setAllConfigs) {
80     ui::DynamicDisplayInfo info;
81     status_t res = SurfaceComposerClient::getDynamicDisplayInfo(mDisplayToken, &info);
82     const auto& modes = info.supportedDisplayModes;
83     ASSERT_EQ(res, NO_ERROR);
84     ASSERT_GT(modes.size(), 0);
85 
86     for (size_t i = 0; i < modes.size(); i++) {
87         res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, modes[i].id, false,
88                                                                 modes[i].refreshRate,
89                                                                 modes[i].refreshRate,
90                                                                 modes[i].refreshRate,
91                                                                 modes[i].refreshRate);
92         ASSERT_EQ(res, NO_ERROR);
93 
94         ui::DisplayModeId defaultConfig;
95         bool allowGroupSwitching;
96         float primaryRefreshRateMin;
97         float primaryRefreshRateMax;
98         float appRequestRefreshRateMin;
99         float appRequestRefreshRateMax;
100         res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
101                                                                 &allowGroupSwitching,
102                                                                 &primaryRefreshRateMin,
103                                                                 &primaryRefreshRateMax,
104                                                                 &appRequestRefreshRateMin,
105                                                                 &appRequestRefreshRateMax);
106         ASSERT_EQ(res, NO_ERROR);
107         ASSERT_EQ(defaultConfig, i);
108         ASSERT_EQ(allowGroupSwitching, false);
109         ASSERT_EQ(primaryRefreshRateMin, modes[i].refreshRate);
110         ASSERT_EQ(primaryRefreshRateMax, modes[i].refreshRate);
111         ASSERT_EQ(appRequestRefreshRateMin, modes[i].refreshRate);
112         ASSERT_EQ(appRequestRefreshRateMax, modes[i].refreshRate);
113     }
114 }
115 
testSetAllowGroupSwitching(bool allowGroupSwitching)116 void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) {
117     status_t res =
118             SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, 0, allowGroupSwitching,
119                                                               0.f, 90.f, 0.f, 90.f);
120     ASSERT_EQ(res, NO_ERROR);
121     ui::DisplayModeId defaultConfig;
122     bool newAllowGroupSwitching;
123     float primaryRefreshRateMin;
124     float primaryRefreshRateMax;
125     float appRequestRefreshRateMin;
126     float appRequestRefreshRateMax;
127 
128     res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
129                                                             &newAllowGroupSwitching,
130                                                             &primaryRefreshRateMin,
131                                                             &primaryRefreshRateMax,
132                                                             &appRequestRefreshRateMin,
133                                                             &appRequestRefreshRateMax);
134     ASSERT_EQ(res, NO_ERROR);
135     ASSERT_EQ(defaultConfig, 0);
136     ASSERT_EQ(newAllowGroupSwitching, allowGroupSwitching);
137     ASSERT_EQ(primaryRefreshRateMin, 0.f);
138     ASSERT_EQ(primaryRefreshRateMax, 90.f);
139     ASSERT_EQ(appRequestRefreshRateMin, 0.f);
140     ASSERT_EQ(appRequestRefreshRateMax, 90.f);
141 }
142 
TEST_F(RefreshRateRangeTest,setAllowGroupSwitching)143 TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
144     testSetAllowGroupSwitching(true);
145     testSetAllowGroupSwitching(false);
146     testSetAllowGroupSwitching(true);
147 }
148 
149 } // namespace android
150 
151 // TODO(b/129481165): remove the #pragma below and fix conversion issues
152 #pragma clang diagnostic pop // ignored "-Wextra"