blob: 9f025a6aaae706f1a1f4ac1240259c1c4f1dbcc0 [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>
Marin Shalamanova7fe3042021-01-29 21:02:08 +010025#include <ui/DisplayMode.h>
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020026#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:
Marin Shalamanova7fe3042021-01-29 21:02:08 +010041 size_t initialDefaultMode;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020042 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 =
Marin Shalamanova7fe3042021-01-29 21:02:08 +010052 SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken,
53 &initialDefaultMode,
54 &initialAllowGroupSwitching,
55 &initialPrimaryMin,
56 &initialPrimaryMax,
57 &initialAppRequestMin,
58 &initialAppRequestMax);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020059 ASSERT_EQ(res, NO_ERROR);
60 }
61
62 void TearDown() override {
63 status_t res =
Marin Shalamanova7fe3042021-01-29 21:02:08 +010064 SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, initialDefaultMode,
65 initialAllowGroupSwitching,
66 initialPrimaryMin,
67 initialPrimaryMax,
68 initialAppRequestMin,
69 initialAppRequestMax);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020070 ASSERT_EQ(res, NO_ERROR);
71 }
72
73 void testSetAllowGroupSwitching(bool allowGroupSwitching);
Ana Krulec0782b882019-10-15 17:34:54 -070074
75 sp<IBinder> mDisplayToken;
76};
77
Steven Thomas6d2f5c32020-01-06 12:15:59 -080078TEST_F(RefreshRateRangeTest, setAllConfigs) {
Marin Shalamanova7fe3042021-01-29 21:02:08 +010079 Vector<ui::DisplayMode> modes;
80 status_t res = SurfaceComposerClient::getDisplayModes(mDisplayToken, &modes);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080081 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanova7fe3042021-01-29 21:02:08 +010082 ASSERT_GT(modes.size(), 0);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080083
Marin Shalamanova7fe3042021-01-29 21:02:08 +010084 for (size_t i = 0; i < modes.size(); i++) {
85 res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, i, false,
86 modes[i].refreshRate,
87 modes[i].refreshRate,
88 modes[i].refreshRate,
89 modes[i].refreshRate);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080090 ASSERT_EQ(res, NO_ERROR);
91
Marin Shalamanova7fe3042021-01-29 21:02:08 +010092 size_t defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020093 bool allowGroupSwitching;
Steven Thomasf734df42020-04-13 21:09:28 -070094 float primaryRefreshRateMin;
95 float primaryRefreshRateMax;
96 float appRequestRefreshRateMin;
97 float appRequestRefreshRateMax;
Marin Shalamanova7fe3042021-01-29 21:02:08 +010098 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
99 &allowGroupSwitching,
100 &primaryRefreshRateMin,
101 &primaryRefreshRateMax,
102 &appRequestRefreshRateMin,
103 &appRequestRefreshRateMax);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800104 ASSERT_EQ(res, NO_ERROR);
105 ASSERT_EQ(defaultConfig, i);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200106 ASSERT_EQ(allowGroupSwitching, false);
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100107 ASSERT_EQ(primaryRefreshRateMin, modes[i].refreshRate);
108 ASSERT_EQ(primaryRefreshRateMax, modes[i].refreshRate);
109 ASSERT_EQ(appRequestRefreshRateMin, modes[i].refreshRate);
110 ASSERT_EQ(appRequestRefreshRateMax, modes[i].refreshRate);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800111 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200112}
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800113
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200114void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) {
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100115 status_t res =
116 SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, 0, allowGroupSwitching,
117 0.f, 90.f, 0.f, 90.f);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800118 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100119 size_t defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200120 bool newAllowGroupSwitching;
121 float primaryRefreshRateMin;
122 float primaryRefreshRateMax;
123 float appRequestRefreshRateMin;
124 float appRequestRefreshRateMax;
125
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100126 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
127 &newAllowGroupSwitching,
128 &primaryRefreshRateMin,
129 &primaryRefreshRateMax,
130 &appRequestRefreshRateMin,
131 &appRequestRefreshRateMax);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200132 ASSERT_EQ(res, NO_ERROR);
133 ASSERT_EQ(defaultConfig, 0);
134 ASSERT_EQ(newAllowGroupSwitching, allowGroupSwitching);
135 ASSERT_EQ(primaryRefreshRateMin, 0.f);
136 ASSERT_EQ(primaryRefreshRateMax, 90.f);
137 ASSERT_EQ(appRequestRefreshRateMin, 0.f);
138 ASSERT_EQ(appRequestRefreshRateMax, 90.f);
139}
140
141TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
142 testSetAllowGroupSwitching(true);
143 testSetAllowGroupSwitching(false);
144 testSetAllowGroupSwitching(true);
Ana Krulec234bb162019-11-10 22:55:55 +0100145}
146
Ana Krulec0782b882019-10-15 17:34:54 -0700147} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100148
149// TODO(b/129481165): remove the #pragma below and fix conversion issues
150#pragma clang diagnostic pop // ignored "-Wextra"