blob: 02c934e576e23c160017bf0254bc4f175b5af092 [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 {
Huihong Luo31b5ac22022-08-15 20:38:10 -070051 const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
52 ASSERT_FALSE(ids.empty());
53 mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front());
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020054 status_t res =
Marin Shalamanova7fe3042021-01-29 21:02:08 +010055 SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken,
56 &initialDefaultMode,
57 &initialAllowGroupSwitching,
58 &initialPrimaryMin,
59 &initialPrimaryMax,
60 &initialAppRequestMin,
61 &initialAppRequestMax);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020062 ASSERT_EQ(res, NO_ERROR);
63 }
64
65 void TearDown() override {
66 status_t res =
Marin Shalamanova7fe3042021-01-29 21:02:08 +010067 SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, initialDefaultMode,
68 initialAllowGroupSwitching,
69 initialPrimaryMin,
70 initialPrimaryMax,
71 initialAppRequestMin,
72 initialAppRequestMax);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020073 ASSERT_EQ(res, NO_ERROR);
74 }
75
76 void testSetAllowGroupSwitching(bool allowGroupSwitching);
Ana Krulec0782b882019-10-15 17:34:54 -070077
78 sp<IBinder> mDisplayToken;
79};
80
Steven Thomas6d2f5c32020-01-06 12:15:59 -080081TEST_F(RefreshRateRangeTest, setAllConfigs) {
Marin Shalamanov228f46b2021-01-28 21:11:45 +010082 ui::DynamicDisplayInfo info;
83 status_t res = SurfaceComposerClient::getDynamicDisplayInfo(mDisplayToken, &info);
84 const auto& modes = info.supportedDisplayModes;
Steven Thomas6d2f5c32020-01-06 12:15:59 -080085 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanova7fe3042021-01-29 21:02:08 +010086 ASSERT_GT(modes.size(), 0);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080087
Marin Shalamanova7fe3042021-01-29 21:02:08 +010088 for (size_t i = 0; i < modes.size(); i++) {
Marin Shalamanov228f46b2021-01-28 21:11:45 +010089 res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, modes[i].id, false,
Marin Shalamanova7fe3042021-01-29 21:02:08 +010090 modes[i].refreshRate,
91 modes[i].refreshRate,
92 modes[i].refreshRate,
93 modes[i].refreshRate);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080094 ASSERT_EQ(res, NO_ERROR);
95
Marin Shalamanov228f46b2021-01-28 21:11:45 +010096 ui::DisplayModeId defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020097 bool allowGroupSwitching;
Steven Thomasf734df42020-04-13 21:09:28 -070098 float primaryRefreshRateMin;
99 float primaryRefreshRateMax;
100 float appRequestRefreshRateMin;
101 float appRequestRefreshRateMax;
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100102 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
103 &allowGroupSwitching,
104 &primaryRefreshRateMin,
105 &primaryRefreshRateMax,
106 &appRequestRefreshRateMin,
107 &appRequestRefreshRateMax);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800108 ASSERT_EQ(res, NO_ERROR);
109 ASSERT_EQ(defaultConfig, i);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200110 ASSERT_EQ(allowGroupSwitching, false);
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100111 ASSERT_EQ(primaryRefreshRateMin, modes[i].refreshRate);
112 ASSERT_EQ(primaryRefreshRateMax, modes[i].refreshRate);
113 ASSERT_EQ(appRequestRefreshRateMin, modes[i].refreshRate);
114 ASSERT_EQ(appRequestRefreshRateMax, modes[i].refreshRate);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800115 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200116}
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800117
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200118void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) {
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100119 status_t res =
120 SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, 0, allowGroupSwitching,
121 0.f, 90.f, 0.f, 90.f);
Steven Thomas6d2f5c32020-01-06 12:15:59 -0800122 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100123 ui::DisplayModeId defaultConfig;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200124 bool newAllowGroupSwitching;
125 float primaryRefreshRateMin;
126 float primaryRefreshRateMax;
127 float appRequestRefreshRateMin;
128 float appRequestRefreshRateMax;
129
Marin Shalamanova7fe3042021-01-29 21:02:08 +0100130 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig,
131 &newAllowGroupSwitching,
132 &primaryRefreshRateMin,
133 &primaryRefreshRateMax,
134 &appRequestRefreshRateMin,
135 &appRequestRefreshRateMax);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200136 ASSERT_EQ(res, NO_ERROR);
137 ASSERT_EQ(defaultConfig, 0);
138 ASSERT_EQ(newAllowGroupSwitching, allowGroupSwitching);
139 ASSERT_EQ(primaryRefreshRateMin, 0.f);
140 ASSERT_EQ(primaryRefreshRateMax, 90.f);
141 ASSERT_EQ(appRequestRefreshRateMin, 0.f);
142 ASSERT_EQ(appRequestRefreshRateMax, 90.f);
143}
144
145TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
146 testSetAllowGroupSwitching(true);
147 testSetAllowGroupSwitching(false);
148 testSetAllowGroupSwitching(true);
Ana Krulec234bb162019-11-10 22:55:55 +0100149}
150
Ana Krulec0782b882019-10-15 17:34:54 -0700151} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100152
153// TODO(b/129481165): remove the #pragma below and fix conversion issues
Huihong Luo31b5ac22022-08-15 20:38:10 -0700154#pragma clang diagnostic pop // ignored "-Wextra"