• 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     gui::DisplayModeSpecs mSpecs;
43 
44 protected:
SetUp()45     void SetUp() override {
46         const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
47         ASSERT_FALSE(ids.empty());
48         mDisplayId = ids.front().value;
49         mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front());
50         status_t res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &mSpecs);
51         ASSERT_EQ(res, NO_ERROR);
52     }
53 
TearDown()54     void TearDown() override {
55         status_t res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, mSpecs);
56         ASSERT_EQ(res, NO_ERROR);
57     }
58 
59     void testSetAllowGroupSwitching(bool allowGroupSwitching);
60 
61     sp<IBinder> mDisplayToken;
62     uint64_t mDisplayId;
63 };
64 
TEST_F(RefreshRateRangeTest,setAllConfigs)65 TEST_F(RefreshRateRangeTest, setAllConfigs) {
66     ui::DynamicDisplayInfo info;
67     status_t res =
68             SurfaceComposerClient::getDynamicDisplayInfoFromId(static_cast<int64_t>(mDisplayId),
69                                                                &info);
70     const auto& modes = info.supportedDisplayModes;
71     ASSERT_EQ(res, NO_ERROR);
72     ASSERT_GT(modes.size(), 0);
73 
74     gui::DisplayModeSpecs setSpecs;
75     setSpecs.allowGroupSwitching = false;
76     for (size_t i = 0; i < modes.size(); i++) {
77         setSpecs.defaultMode = modes[i].id;
78         setSpecs.primaryRanges.physical.min = modes[i].refreshRate;
79         setSpecs.primaryRanges.physical.max = modes[i].refreshRate;
80         setSpecs.primaryRanges.render = setSpecs.primaryRanges.physical;
81         setSpecs.appRequestRanges = setSpecs.primaryRanges;
82         res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, setSpecs);
83         ASSERT_EQ(res, NO_ERROR);
84 
85         gui::DisplayModeSpecs getSpecs;
86         res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs);
87         ASSERT_EQ(res, NO_ERROR);
88         ASSERT_EQ(setSpecs, getSpecs);
89     }
90 }
91 
testSetAllowGroupSwitching(bool allowGroupSwitching)92 void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) {
93     gui::DisplayModeSpecs setSpecs;
94     setSpecs.defaultMode = 0;
95     setSpecs.allowGroupSwitching = allowGroupSwitching;
96     setSpecs.primaryRanges.physical.min = 0;
97     setSpecs.primaryRanges.physical.max = 90;
98     setSpecs.primaryRanges.render = setSpecs.primaryRanges.physical;
99     setSpecs.appRequestRanges = setSpecs.primaryRanges;
100 
101     status_t res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, setSpecs);
102     ASSERT_EQ(res, NO_ERROR);
103     gui::DisplayModeSpecs getSpecs;
104     res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs);
105     ASSERT_EQ(res, NO_ERROR);
106     ASSERT_EQ(setSpecs, getSpecs);
107 }
108 
TEST_F(RefreshRateRangeTest,setAllowGroupSwitching)109 TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
110     testSetAllowGroupSwitching(true);
111     testSetAllowGroupSwitching(false);
112     testSetAllowGroupSwitching(true);
113 }
114 
115 } // namespace android
116 
117 // TODO(b/129481165): remove the #pragma below and fix conversion issues
118 #pragma clang diagnostic pop // ignored "-Wextra"
119