xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/tests/DisplayConfigs_test.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
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 
testSetDesiredDisplayModeSpecs(bool allowGroupSwitching=false)59     void testSetDesiredDisplayModeSpecs(bool allowGroupSwitching = false) {
60         ui::DynamicDisplayInfo info;
61         status_t res =
62                 SurfaceComposerClient::getDynamicDisplayInfoFromId(static_cast<int64_t>(mDisplayId),
63                                                                    &info);
64         const auto& modes = info.supportedDisplayModes;
65         ASSERT_EQ(res, NO_ERROR);
66         ASSERT_GT(modes.size(), 0);
67         for (const auto& mode : modes) {
68             gui::DisplayModeSpecs setSpecs;
69             setSpecs.defaultMode = mode.id;
70             setSpecs.allowGroupSwitching = allowGroupSwitching;
71             setSpecs.primaryRanges.physical.min = mode.peakRefreshRate;
72             setSpecs.primaryRanges.physical.max = mode.peakRefreshRate;
73             setSpecs.primaryRanges.render = setSpecs.primaryRanges.physical;
74             setSpecs.appRequestRanges = setSpecs.primaryRanges;
75 
76             res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, setSpecs);
77             ASSERT_EQ(res, NO_ERROR);
78             gui::DisplayModeSpecs getSpecs;
79             res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs);
80             ASSERT_EQ(res, NO_ERROR);
81             ASSERT_EQ(setSpecs, getSpecs);
82         }
83     }
84 
85     sp<IBinder> mDisplayToken;
86     uint64_t mDisplayId;
87 };
88 
TEST_F(RefreshRateRangeTest,setAllConfigs)89 TEST_F(RefreshRateRangeTest, setAllConfigs) {
90     testSetDesiredDisplayModeSpecs();
91 }
92 
TEST_F(RefreshRateRangeTest,setAllowGroupSwitching)93 TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
94     testSetDesiredDisplayModeSpecs(/*allowGroupSwitching=*/true);
95     testSetDesiredDisplayModeSpecs(/*allowGroupSwitching=*/false);
96     testSetDesiredDisplayModeSpecs(/*allowGroupSwitching=*/true);
97 }
98 
99 } // namespace android
100 
101 // TODO(b/129481165): remove the #pragma below and fix conversion issues
102 #pragma clang diagnostic pop // ignored "-Wextra"
103