blob: 55b317382e71397d0a865a952d346233db15df50 [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 Shalamanovbed7fd32020-12-21 20:02:20 +010017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wextra"
20
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020021#include <gtest/gtest.h>
22#include <gui/ISurfaceComposer.h>
23#include <gui/SurfaceComposerClient.h>
24#include <private/gui/ComposerService.h>
25#include <ui/DisplayConfig.h>
26#include <utils/Errors.h>
27#include <utils/Vector.h>
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080028
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020029#include "utils/TransactionUtils.h"
30
Ana Krulec0782b882019-10-15 17:34:54 -070031namespace android {
32
Ana Krulec0782b882019-10-15 17:34:54 -070033::testing::Environment* const binderEnv =
34 ::testing::AddGlobalTestEnvironment(new BinderEnvironment());
35
36/**
37 * Test class for setting display configs and passing around refresh rate ranges.
38 */
39class RefreshRateRangeTest : public ::testing::Test {
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020040private:
41 int32_t initialDefaultConfig;
42 bool initialAllowGroupSwitching;
43 float initialPrimaryMin;
44 float initialPrimaryMax;
45 float initialAppRequestMin;
46 float initialAppRequestMax;
47
Ana Krulec0782b882019-10-15 17:34:54 -070048protected:
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020049 void SetUp() override {
50 mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
51 status_t res =
52 SurfaceComposerClient::getDesiredDisplayConfigSpecs(mDisplayToken,
53 &initialDefaultConfig,
54 &initialAllowGroupSwitching,
55 &initialPrimaryMin,
56 &initialPrimaryMax,
57 &initialAppRequestMin,
58 &initialAppRequestMax);
59 ASSERT_EQ(res, NO_ERROR);
60 }
61
62 void TearDown() override {
63 status_t res =
64 SurfaceComposerClient::setDesiredDisplayConfigSpecs(mDisplayToken,
65 initialDefaultConfig,
66 initialAllowGroupSwitching,
67 initialPrimaryMin,
68 initialPrimaryMax,
69 initialAppRequestMin,
70 initialAppRequestMax);
71 ASSERT_EQ(res, NO_ERROR);
72 }
73
74 void testSetAllowGroupSwitching(bool allowGroupSwitching);
Ana Krulec0782b882019-10-15 17:34:54 -070075
76 sp<IBinder> mDisplayToken;
77};
78
Steven Thomas6d2f5c32020-01-06 12:15:59 -080079TEST_F(RefreshRateRangeTest, setAllConfigs) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080080 Vector<DisplayConfig> configs;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020081 status_t res = SurfaceComposerClient::getDisplayConfigs(mDisplayToken, &configs);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080082 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020083 ASSERT_GT(configs.size(), 0);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080084
85 for (size_t i = 0; i < configs.size(); i++) {
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020086 res = SurfaceComposerClient::setDesiredDisplayConfigSpecs(mDisplayToken,
87 static_cast<int32_t>(i), false,
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080088 configs[i].refreshRate,
Steven Thomasf734df42020-04-13 21:09:28 -070089 configs[i].refreshRate,
90 configs[i].refreshRate,
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080091 configs[i].refreshRate);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080092 ASSERT_EQ(res, NO_ERROR);
93
94 int defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020095 bool allowGroupSwitching;
Steven Thomasf734df42020-04-13 21:09:28 -070096 float primaryRefreshRateMin;
97 float primaryRefreshRateMax;
98 float appRequestRefreshRateMin;
99 float appRequestRefreshRateMax;
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800100 res = SurfaceComposerClient::getDesiredDisplayConfigSpecs(mDisplayToken, &defaultConfig,
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200101 &allowGroupSwitching,
Steven Thomasf734df42020-04-13 21:09:28 -0700102 &primaryRefreshRateMin,
103 &primaryRefreshRateMax,
104 &appRequestRefreshRateMin,
105 &appRequestRefreshRateMax);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800106 ASSERT_EQ(res, NO_ERROR);
107 ASSERT_EQ(defaultConfig, i);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200108 ASSERT_EQ(allowGroupSwitching, false);
Steven Thomasf734df42020-04-13 21:09:28 -0700109 ASSERT_EQ(primaryRefreshRateMin, configs[i].refreshRate);
110 ASSERT_EQ(primaryRefreshRateMax, configs[i].refreshRate);
111 ASSERT_EQ(appRequestRefreshRateMin, configs[i].refreshRate);
112 ASSERT_EQ(appRequestRefreshRateMax, configs[i].refreshRate);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800113 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200114}
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800115
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200116void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) {
117 status_t res = SurfaceComposerClient::setDesiredDisplayConfigSpecs(mDisplayToken, 0,
118 allowGroupSwitching, 0.f,
119 90.f, 0.f, 90.f);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800120 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200121 int defaultConfig;
122 bool newAllowGroupSwitching;
123 float primaryRefreshRateMin;
124 float primaryRefreshRateMax;
125 float appRequestRefreshRateMin;
126 float appRequestRefreshRateMax;
127
128 res = SurfaceComposerClient::getDesiredDisplayConfigSpecs(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
143TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
144 testSetAllowGroupSwitching(true);
145 testSetAllowGroupSwitching(false);
146 testSetAllowGroupSwitching(true);
Ana Krulec234bb162019-11-10 22:55:55 +0100147}
148
Ana Krulec0782b882019-10-15 17:34:54 -0700149} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100150
151// TODO(b/129481165): remove the #pragma below and fix conversion issues
152#pragma clang diagnostic pop // ignored "-Wextra"