blob: 2dc96b85110d4d0ada9e5ddecb3613a4fc5638c5 [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 Shalamanov228f46b2021-01-28 21:11:45 +010026#include <ui/DynamicDisplayInfo.h>
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020027#include <utils/Errors.h>
28#include <utils/Vector.h>
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080029
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020030#include "utils/TransactionUtils.h"
31
Ana Krulec0782b882019-10-15 17:34:54 -070032namespace android {
33
Ana Krulec0782b882019-10-15 17:34:54 -070034::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 */
40class RefreshRateRangeTest : public ::testing::Test {
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020041private:
Marin Shalamanov228f46b2021-01-28 21:11:45 +010042 ui::DisplayModeId initialDefaultMode;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020043 bool initialAllowGroupSwitching;
44 float initialPrimaryMin;
45 float initialPrimaryMax;
46 float initialAppRequestMin;
47 float initialAppRequestMax;
48
Ana Krulec0782b882019-10-15 17:34:54 -070049protected:
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020050 void SetUp() override {
51 mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
52 status_t res =
Marin Shalamanova7fe3042021-01-29 21:02:08 +010053 SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken,
54 &initialDefaultMode,
55 &initialAllowGroupSwitching,
56 &initialPrimaryMin,
57 &initialPrimaryMax,
58 &initialAppRequestMin,
59 &initialAppRequestMax);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020060 ASSERT_EQ(res, NO_ERROR);
61 }
62
63 void TearDown() override {
64 status_t res =
Marin Shalamanova7fe3042021-01-29 21:02:08 +010065 SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, initialDefaultMode,
66 initialAllowGroupSwitching,
67 initialPrimaryMin,
68 initialPrimaryMax,
69 initialAppRequestMin,
70 initialAppRequestMax);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020071 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) {
Marin Shalamanov228f46b2021-01-28 21:11:45 +010080 ui::DynamicDisplayInfo info;
81 status_t res = SurfaceComposerClient::getDynamicDisplayInfo(mDisplayToken, &info);
82 const auto& modes = info.supportedDisplayModes;
Steven Thomas6d2f5c32020-01-06 12:15:59 -080083 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanova7fe3042021-01-29 21:02:08 +010084 ASSERT_GT(modes.size(), 0);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080085
Marin Shalamanova7fe3042021-01-29 21:02:08 +010086 for (size_t i = 0; i < modes.size(); i++) {
Marin Shalamanov228f46b2021-01-28 21:11:45 +010087 res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, modes[i].id, false,
Marin Shalamanova7fe3042021-01-29 21:02:08 +010088 modes[i].refreshRate,
89 modes[i].refreshRate,
90 modes[i].refreshRate,
91 modes[i].refreshRate);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080092 ASSERT_EQ(res, NO_ERROR);
93
Marin Shalamanov228f46b2021-01-28 21:11:45 +010094 ui::DisplayModeId 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;
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100100 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
101 &allowGroupSwitching,
102 &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);
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100109 ASSERT_EQ(primaryRefreshRateMin, modes[i].refreshRate);
110 ASSERT_EQ(primaryRefreshRateMax, modes[i].refreshRate);
111 ASSERT_EQ(appRequestRefreshRateMin, modes[i].refreshRate);
112 ASSERT_EQ(appRequestRefreshRateMax, modes[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) {
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100117 status_t res =
118 SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, 0, allowGroupSwitching,
119 0.f, 90.f, 0.f, 90.f);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800120 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100121 ui::DisplayModeId defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200122 bool newAllowGroupSwitching;
123 float primaryRefreshRateMin;
124 float primaryRefreshRateMax;
125 float appRequestRefreshRateMin;
126 float appRequestRefreshRateMax;
127
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100128 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
129 &newAllowGroupSwitching,
130 &primaryRefreshRateMin,
131 &primaryRefreshRateMax,
132 &appRequestRefreshRateMin,
133 &appRequestRefreshRateMax);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200134 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"