blob: 3a8b40fd679da49e60ecef68a8586870b609fde9 [file] [log] [blame]
Ana Krulec0782b882019-10-15 17:34:54 -07001/*
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
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020017#include <gtest/gtest.h>
18#include <gui/ISurfaceComposer.h>
19#include <gui/SurfaceComposerClient.h>
20#include <private/gui/ComposerService.h>
21#include <ui/DisplayConfig.h>
22#include <utils/Errors.h>
23#include <utils/Vector.h>
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080024
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020025#include "utils/TransactionUtils.h"
26
Ana Krulec0782b882019-10-15 17:34:54 -070027namespace android {
28
Ana Krulec0782b882019-10-15 17:34:54 -070029::testing::Environment* const binderEnv =
30 ::testing::AddGlobalTestEnvironment(new BinderEnvironment());
31
32/**
33 * Test class for setting display configs and passing around refresh rate ranges.
34 */
35class RefreshRateRangeTest : public ::testing::Test {
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020036private:
37 int32_t initialDefaultConfig;
38 bool initialAllowGroupSwitching;
39 float initialPrimaryMin;
40 float initialPrimaryMax;
41 float initialAppRequestMin;
42 float initialAppRequestMax;
43
Ana Krulec0782b882019-10-15 17:34:54 -070044protected:
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020045 void SetUp() override {
46 mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
47 status_t res =
48 SurfaceComposerClient::getDesiredDisplayConfigSpecs(mDisplayToken,
49 &initialDefaultConfig,
50 &initialAllowGroupSwitching,
51 &initialPrimaryMin,
52 &initialPrimaryMax,
53 &initialAppRequestMin,
54 &initialAppRequestMax);
55 ASSERT_EQ(res, NO_ERROR);
56 }
57
58 void TearDown() override {
59 status_t res =
60 SurfaceComposerClient::setDesiredDisplayConfigSpecs(mDisplayToken,
61 initialDefaultConfig,
62 initialAllowGroupSwitching,
63 initialPrimaryMin,
64 initialPrimaryMax,
65 initialAppRequestMin,
66 initialAppRequestMax);
67 ASSERT_EQ(res, NO_ERROR);
68 }
69
70 void testSetAllowGroupSwitching(bool allowGroupSwitching);
Ana Krulec0782b882019-10-15 17:34:54 -070071
72 sp<IBinder> mDisplayToken;
73};
74
Steven Thomas6d2f5c32020-01-06 12:15:59 -080075TEST_F(RefreshRateRangeTest, setAllConfigs) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080076 Vector<DisplayConfig> configs;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020077 status_t res = SurfaceComposerClient::getDisplayConfigs(mDisplayToken, &configs);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080078 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020079 ASSERT_GT(configs.size(), 0);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080080
81 for (size_t i = 0; i < configs.size(); i++) {
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020082 res = SurfaceComposerClient::setDesiredDisplayConfigSpecs(mDisplayToken,
83 static_cast<int32_t>(i), false,
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080084 configs[i].refreshRate,
Steven Thomasf734df42020-04-13 21:09:28 -070085 configs[i].refreshRate,
86 configs[i].refreshRate,
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080087 configs[i].refreshRate);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080088 ASSERT_EQ(res, NO_ERROR);
89
90 int defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020091 bool allowGroupSwitching;
Steven Thomasf734df42020-04-13 21:09:28 -070092 float primaryRefreshRateMin;
93 float primaryRefreshRateMax;
94 float appRequestRefreshRateMin;
95 float appRequestRefreshRateMax;
Steven Thomas6d2f5c32020-01-06 12:15:59 -080096 res = SurfaceComposerClient::getDesiredDisplayConfigSpecs(mDisplayToken, &defaultConfig,
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020097 &allowGroupSwitching,
Steven Thomasf734df42020-04-13 21:09:28 -070098 &primaryRefreshRateMin,
99 &primaryRefreshRateMax,
100 &appRequestRefreshRateMin,
101 &appRequestRefreshRateMax);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800102 ASSERT_EQ(res, NO_ERROR);
103 ASSERT_EQ(defaultConfig, i);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200104 ASSERT_EQ(allowGroupSwitching, false);
Steven Thomasf734df42020-04-13 21:09:28 -0700105 ASSERT_EQ(primaryRefreshRateMin, configs[i].refreshRate);
106 ASSERT_EQ(primaryRefreshRateMax, configs[i].refreshRate);
107 ASSERT_EQ(appRequestRefreshRateMin, configs[i].refreshRate);
108 ASSERT_EQ(appRequestRefreshRateMax, configs[i].refreshRate);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800109 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200110}
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800111
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200112void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) {
113 status_t res = SurfaceComposerClient::setDesiredDisplayConfigSpecs(mDisplayToken, 0,
114 allowGroupSwitching, 0.f,
115 90.f, 0.f, 90.f);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800116 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200117 int defaultConfig;
118 bool newAllowGroupSwitching;
119 float primaryRefreshRateMin;
120 float primaryRefreshRateMax;
121 float appRequestRefreshRateMin;
122 float appRequestRefreshRateMax;
123
124 res = SurfaceComposerClient::getDesiredDisplayConfigSpecs(mDisplayToken, &defaultConfig,
125 &newAllowGroupSwitching,
126 &primaryRefreshRateMin,
127 &primaryRefreshRateMax,
128 &appRequestRefreshRateMin,
129 &appRequestRefreshRateMax);
130 ASSERT_EQ(res, NO_ERROR);
131 ASSERT_EQ(defaultConfig, 0);
132 ASSERT_EQ(newAllowGroupSwitching, allowGroupSwitching);
133 ASSERT_EQ(primaryRefreshRateMin, 0.f);
134 ASSERT_EQ(primaryRefreshRateMax, 90.f);
135 ASSERT_EQ(appRequestRefreshRateMin, 0.f);
136 ASSERT_EQ(appRequestRefreshRateMax, 90.f);
137}
138
139TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
140 testSetAllowGroupSwitching(true);
141 testSetAllowGroupSwitching(false);
142 testSetAllowGroupSwitching(true);
Ana Krulec234bb162019-11-10 22:55:55 +0100143}
144
Ana Krulec0782b882019-10-15 17:34:54 -0700145} // namespace android