summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/tests/DisplayConfigs_test.cpp
blob: 2dc96b85110d4d0ada9e5ddecb3613a4fc5638c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wextra"

#include <gtest/gtest.h>
#include <gui/ISurfaceComposer.h>
#include <gui/SurfaceComposerClient.h>
#include <private/gui/ComposerService.h>
#include <ui/DisplayMode.h>
#include <ui/DynamicDisplayInfo.h>
#include <utils/Errors.h>
#include <utils/Vector.h>

#include "utils/TransactionUtils.h"

namespace android {

::testing::Environment* const binderEnv =
        ::testing::AddGlobalTestEnvironment(new BinderEnvironment());

/**
 * Test class for setting display configs and passing around refresh rate ranges.
 */
class RefreshRateRangeTest : public ::testing::Test {
private:
    ui::DisplayModeId initialDefaultMode;
    bool initialAllowGroupSwitching;
    float initialPrimaryMin;
    float initialPrimaryMax;
    float initialAppRequestMin;
    float initialAppRequestMax;

protected:
    void SetUp() override {
        mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
        status_t res =
                SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken,
                                                                  &initialDefaultMode,
                                                                  &initialAllowGroupSwitching,
                                                                  &initialPrimaryMin,
                                                                  &initialPrimaryMax,
                                                                  &initialAppRequestMin,
                                                                  &initialAppRequestMax);
        ASSERT_EQ(res, NO_ERROR);
    }

    void TearDown() override {
        status_t res =
                SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, initialDefaultMode,
                                                                  initialAllowGroupSwitching,
                                                                  initialPrimaryMin,
                                                                  initialPrimaryMax,
                                                                  initialAppRequestMin,
                                                                  initialAppRequestMax);
        ASSERT_EQ(res, NO_ERROR);
    }

    void testSetAllowGroupSwitching(bool allowGroupSwitching);

    sp<IBinder> mDisplayToken;
};

TEST_F(RefreshRateRangeTest, setAllConfigs) {
    ui::DynamicDisplayInfo info;
    status_t res = SurfaceComposerClient::getDynamicDisplayInfo(mDisplayToken, &info);
    const auto& modes = info.supportedDisplayModes;
    ASSERT_EQ(res, NO_ERROR);
    ASSERT_GT(modes.size(), 0);

    for (size_t i = 0; i < modes.size(); i++) {
        res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, modes[i].id, false,
                                                                modes[i].refreshRate,
                                                                modes[i].refreshRate,
                                                                modes[i].refreshRate,
                                                                modes[i].refreshRate);
        ASSERT_EQ(res, NO_ERROR);

        ui::DisplayModeId defaultConfig;
        bool allowGroupSwitching;
        float primaryRefreshRateMin;
        float primaryRefreshRateMax;
        float appRequestRefreshRateMin;
        float appRequestRefreshRateMax;
        res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
                                                                &allowGroupSwitching,
                                                                &primaryRefreshRateMin,
                                                                &primaryRefreshRateMax,
                                                                &appRequestRefreshRateMin,
                                                                &appRequestRefreshRateMax);
        ASSERT_EQ(res, NO_ERROR);
        ASSERT_EQ(defaultConfig, i);
        ASSERT_EQ(allowGroupSwitching, false);
        ASSERT_EQ(primaryRefreshRateMin, modes[i].refreshRate);
        ASSERT_EQ(primaryRefreshRateMax, modes[i].refreshRate);
        ASSERT_EQ(appRequestRefreshRateMin, modes[i].refreshRate);
        ASSERT_EQ(appRequestRefreshRateMax, modes[i].refreshRate);
    }
}

void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) {
    status_t res =
            SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, 0, allowGroupSwitching,
                                                              0.f, 90.f, 0.f, 90.f);
    ASSERT_EQ(res, NO_ERROR);
    ui::DisplayModeId defaultConfig;
    bool newAllowGroupSwitching;
    float primaryRefreshRateMin;
    float primaryRefreshRateMax;
    float appRequestRefreshRateMin;
    float appRequestRefreshRateMax;

    res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
                                                            &newAllowGroupSwitching,
                                                            &primaryRefreshRateMin,
                                                            &primaryRefreshRateMax,
                                                            &appRequestRefreshRateMin,
                                                            &appRequestRefreshRateMax);
    ASSERT_EQ(res, NO_ERROR);
    ASSERT_EQ(defaultConfig, 0);
    ASSERT_EQ(newAllowGroupSwitching, allowGroupSwitching);
    ASSERT_EQ(primaryRefreshRateMin, 0.f);
    ASSERT_EQ(primaryRefreshRateMax, 90.f);
    ASSERT_EQ(appRequestRefreshRateMin, 0.f);
    ASSERT_EQ(appRequestRefreshRateMax, 90.f);
}

TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
    testSetAllowGroupSwitching(true);
    testSetAllowGroupSwitching(false);
    testSetAllowGroupSwitching(true);
}

} // namespace android

// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic pop // ignored "-Wextra"