blob: 4be961bda1356782d17ec33645ff8f46d2b581e4 [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:
Ady Abraham285f8c12022-10-11 17:12:14 -070042 gui::DisplayModeSpecs mSpecs;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020043
Ana Krulec0782b882019-10-15 17:34:54 -070044protected:
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020045 void SetUp() override {
Huihong Luo31b5ac22022-08-15 20:38:10 -070046 const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
47 ASSERT_FALSE(ids.empty());
Sally Qi6bb12822022-10-05 11:42:30 -070048 mDisplayId = ids.front().value;
Huihong Luo31b5ac22022-08-15 20:38:10 -070049 mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front());
Ady Abraham285f8c12022-10-11 17:12:14 -070050 status_t res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &mSpecs);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020051 ASSERT_EQ(res, NO_ERROR);
52 }
53
54 void TearDown() override {
Ady Abraham285f8c12022-10-11 17:12:14 -070055 status_t res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, mSpecs);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020056 ASSERT_EQ(res, NO_ERROR);
57 }
58
59 void testSetAllowGroupSwitching(bool allowGroupSwitching);
Ana Krulec0782b882019-10-15 17:34:54 -070060
61 sp<IBinder> mDisplayToken;
Sally Qi6bb12822022-10-05 11:42:30 -070062 uint64_t mDisplayId;
Ana Krulec0782b882019-10-15 17:34:54 -070063};
64
Steven Thomas6d2f5c32020-01-06 12:15:59 -080065TEST_F(RefreshRateRangeTest, setAllConfigs) {
Marin Shalamanov228f46b2021-01-28 21:11:45 +010066 ui::DynamicDisplayInfo info;
Sally Qi6bb12822022-10-05 11:42:30 -070067 status_t res =
68 SurfaceComposerClient::getDynamicDisplayInfoFromId(static_cast<int64_t>(mDisplayId),
69 &info);
Marin Shalamanov228f46b2021-01-28 21:11:45 +010070 const auto& modes = info.supportedDisplayModes;
Steven Thomas6d2f5c32020-01-06 12:15:59 -080071 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanova7fe3042021-01-29 21:02:08 +010072 ASSERT_GT(modes.size(), 0);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080073
Ady Abraham285f8c12022-10-11 17:12:14 -070074 gui::DisplayModeSpecs setSpecs;
75 setSpecs.allowGroupSwitching = false;
Marin Shalamanova7fe3042021-01-29 21:02:08 +010076 for (size_t i = 0; i < modes.size(); i++) {
Ady Abraham285f8c12022-10-11 17:12:14 -070077 setSpecs.defaultMode = modes[i].id;
78 setSpecs.primaryRanges.physical.min = modes[i].refreshRate;
79 setSpecs.primaryRanges.physical.max = modes[i].refreshRate;
80 setSpecs.primaryRanges.render = setSpecs.primaryRanges.physical;
81 setSpecs.appRequestRanges = setSpecs.primaryRanges;
82 res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, setSpecs);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080083 ASSERT_EQ(res, NO_ERROR);
84
Ady Abraham285f8c12022-10-11 17:12:14 -070085 gui::DisplayModeSpecs getSpecs;
86 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080087 ASSERT_EQ(res, NO_ERROR);
Ady Abraham285f8c12022-10-11 17:12:14 -070088 ASSERT_EQ(setSpecs, getSpecs);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080089 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020090}
Steven Thomas6d2f5c32020-01-06 12:15:59 -080091
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020092void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) {
Ady Abraham285f8c12022-10-11 17:12:14 -070093 gui::DisplayModeSpecs setSpecs;
94 setSpecs.defaultMode = 0;
95 setSpecs.allowGroupSwitching = allowGroupSwitching;
96 setSpecs.primaryRanges.physical.min = 0;
97 setSpecs.primaryRanges.physical.max = 90;
98 setSpecs.primaryRanges.render = setSpecs.primaryRanges.physical;
99 setSpecs.appRequestRanges = setSpecs.primaryRanges;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200100
Ady Abraham285f8c12022-10-11 17:12:14 -0700101 status_t res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, setSpecs);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200102 ASSERT_EQ(res, NO_ERROR);
Ady Abraham285f8c12022-10-11 17:12:14 -0700103 gui::DisplayModeSpecs getSpecs;
104 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs);
105 ASSERT_EQ(res, NO_ERROR);
106 ASSERT_EQ(setSpecs, getSpecs);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200107}
108
109TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
110 testSetAllowGroupSwitching(true);
111 testSetAllowGroupSwitching(false);
112 testSetAllowGroupSwitching(true);
Ana Krulec234bb162019-11-10 22:55:55 +0100113}
114
Ana Krulec0782b882019-10-15 17:34:54 -0700115} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100116
117// TODO(b/129481165): remove the #pragma below and fix conversion issues
Huihong Luo31b5ac22022-08-15 20:38:10 -0700118#pragma clang diagnostic pop // ignored "-Wextra"