blob: 10dae4636e343adbfc62fc14d2417ecd578e76da [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());
48 mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front());
Ady Abraham285f8c12022-10-11 17:12:14 -070049 status_t res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &mSpecs);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020050 ASSERT_EQ(res, NO_ERROR);
51 }
52
53 void TearDown() override {
Ady Abraham285f8c12022-10-11 17:12:14 -070054 status_t res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, mSpecs);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020055 ASSERT_EQ(res, NO_ERROR);
56 }
57
58 void testSetAllowGroupSwitching(bool allowGroupSwitching);
Ana Krulec0782b882019-10-15 17:34:54 -070059
60 sp<IBinder> mDisplayToken;
61};
62
Steven Thomas6d2f5c32020-01-06 12:15:59 -080063TEST_F(RefreshRateRangeTest, setAllConfigs) {
Marin Shalamanov228f46b2021-01-28 21:11:45 +010064 ui::DynamicDisplayInfo info;
65 status_t res = SurfaceComposerClient::getDynamicDisplayInfo(mDisplayToken, &info);
66 const auto& modes = info.supportedDisplayModes;
Steven Thomas6d2f5c32020-01-06 12:15:59 -080067 ASSERT_EQ(res, NO_ERROR);
Marin Shalamanova7fe3042021-01-29 21:02:08 +010068 ASSERT_GT(modes.size(), 0);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080069
Ady Abraham285f8c12022-10-11 17:12:14 -070070 gui::DisplayModeSpecs setSpecs;
71 setSpecs.allowGroupSwitching = false;
Marin Shalamanova7fe3042021-01-29 21:02:08 +010072 for (size_t i = 0; i < modes.size(); i++) {
Ady Abraham285f8c12022-10-11 17:12:14 -070073 setSpecs.defaultMode = modes[i].id;
74 setSpecs.primaryRanges.physical.min = modes[i].refreshRate;
75 setSpecs.primaryRanges.physical.max = modes[i].refreshRate;
76 setSpecs.primaryRanges.render = setSpecs.primaryRanges.physical;
77 setSpecs.appRequestRanges = setSpecs.primaryRanges;
78 res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, setSpecs);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080079 ASSERT_EQ(res, NO_ERROR);
80
Ady Abraham285f8c12022-10-11 17:12:14 -070081 gui::DisplayModeSpecs getSpecs;
82 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080083 ASSERT_EQ(res, NO_ERROR);
Ady Abraham285f8c12022-10-11 17:12:14 -070084 ASSERT_EQ(setSpecs, getSpecs);
Steven Thomas6d2f5c32020-01-06 12:15:59 -080085 }
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020086}
Steven Thomas6d2f5c32020-01-06 12:15:59 -080087
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020088void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) {
Ady Abraham285f8c12022-10-11 17:12:14 -070089 gui::DisplayModeSpecs setSpecs;
90 setSpecs.defaultMode = 0;
91 setSpecs.allowGroupSwitching = allowGroupSwitching;
92 setSpecs.primaryRanges.physical.min = 0;
93 setSpecs.primaryRanges.physical.max = 90;
94 setSpecs.primaryRanges.render = setSpecs.primaryRanges.physical;
95 setSpecs.appRequestRanges = setSpecs.primaryRanges;
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020096
Ady Abraham285f8c12022-10-11 17:12:14 -070097 status_t res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, setSpecs);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +020098 ASSERT_EQ(res, NO_ERROR);
Ady Abraham285f8c12022-10-11 17:12:14 -070099 gui::DisplayModeSpecs getSpecs;
100 res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs);
101 ASSERT_EQ(res, NO_ERROR);
102 ASSERT_EQ(setSpecs, getSpecs);
Marin Shalamanov30b0b3c2020-10-13 19:15:06 +0200103}
104
105TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) {
106 testSetAllowGroupSwitching(true);
107 testSetAllowGroupSwitching(false);
108 testSetAllowGroupSwitching(true);
Ana Krulec234bb162019-11-10 22:55:55 +0100109}
110
Ana Krulec0782b882019-10-15 17:34:54 -0700111} // namespace android
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100112
113// TODO(b/129481165): remove the #pragma below and fix conversion issues
Huihong Luo31b5ac22022-08-15 20:38:10 -0700114#pragma clang diagnostic pop // ignored "-Wextra"