Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 1 | /* |
| 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 Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wextra" |
| 20 | |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 21 | #include <gtest/gtest.h> |
| 22 | #include <gui/ISurfaceComposer.h> |
| 23 | #include <gui/SurfaceComposerClient.h> |
| 24 | #include <private/gui/ComposerService.h> |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 25 | #include <ui/DisplayMode.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 26 | #include <ui/DynamicDisplayInfo.h> |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 27 | #include <utils/Errors.h> |
| 28 | #include <utils/Vector.h> |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 29 | |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 30 | #include "utils/TransactionUtils.h" |
| 31 | |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 34 | ::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 | */ |
| 40 | class RefreshRateRangeTest : public ::testing::Test { |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 41 | private: |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 42 | ui::DisplayModeId initialDefaultMode; |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 43 | bool initialAllowGroupSwitching; |
| 44 | float initialPrimaryMin; |
| 45 | float initialPrimaryMax; |
| 46 | float initialAppRequestMin; |
| 47 | float initialAppRequestMax; |
| 48 | |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 49 | protected: |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 50 | void SetUp() override { |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 51 | const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 52 | ASSERT_FALSE(ids.empty()); |
| 53 | mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front()); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 54 | status_t res = |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 55 | SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, |
| 56 | &initialDefaultMode, |
| 57 | &initialAllowGroupSwitching, |
| 58 | &initialPrimaryMin, |
| 59 | &initialPrimaryMax, |
| 60 | &initialAppRequestMin, |
| 61 | &initialAppRequestMax); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 62 | ASSERT_EQ(res, NO_ERROR); |
| 63 | } |
| 64 | |
| 65 | void TearDown() override { |
| 66 | status_t res = |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 67 | SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, initialDefaultMode, |
| 68 | initialAllowGroupSwitching, |
| 69 | initialPrimaryMin, |
| 70 | initialPrimaryMax, |
| 71 | initialAppRequestMin, |
| 72 | initialAppRequestMax); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 73 | ASSERT_EQ(res, NO_ERROR); |
| 74 | } |
| 75 | |
| 76 | void testSetAllowGroupSwitching(bool allowGroupSwitching); |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 77 | |
| 78 | sp<IBinder> mDisplayToken; |
| 79 | }; |
| 80 | |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 81 | TEST_F(RefreshRateRangeTest, setAllConfigs) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 82 | ui::DynamicDisplayInfo info; |
| 83 | status_t res = SurfaceComposerClient::getDynamicDisplayInfo(mDisplayToken, &info); |
| 84 | const auto& modes = info.supportedDisplayModes; |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 85 | ASSERT_EQ(res, NO_ERROR); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 86 | ASSERT_GT(modes.size(), 0); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 87 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 88 | for (size_t i = 0; i < modes.size(); i++) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 89 | res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, modes[i].id, false, |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 90 | modes[i].refreshRate, |
| 91 | modes[i].refreshRate, |
| 92 | modes[i].refreshRate, |
| 93 | modes[i].refreshRate); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 94 | ASSERT_EQ(res, NO_ERROR); |
| 95 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 96 | ui::DisplayModeId defaultConfig; |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 97 | bool allowGroupSwitching; |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 98 | float primaryRefreshRateMin; |
| 99 | float primaryRefreshRateMax; |
| 100 | float appRequestRefreshRateMin; |
| 101 | float appRequestRefreshRateMax; |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 102 | res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig, |
| 103 | &allowGroupSwitching, |
| 104 | &primaryRefreshRateMin, |
| 105 | &primaryRefreshRateMax, |
| 106 | &appRequestRefreshRateMin, |
| 107 | &appRequestRefreshRateMax); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 108 | ASSERT_EQ(res, NO_ERROR); |
| 109 | ASSERT_EQ(defaultConfig, i); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 110 | ASSERT_EQ(allowGroupSwitching, false); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 111 | 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 Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 115 | } |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 116 | } |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 117 | |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 118 | void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 119 | status_t res = |
| 120 | SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, 0, allowGroupSwitching, |
| 121 | 0.f, 90.f, 0.f, 90.f); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 122 | ASSERT_EQ(res, NO_ERROR); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 123 | ui::DisplayModeId defaultConfig; |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 124 | bool newAllowGroupSwitching; |
| 125 | float primaryRefreshRateMin; |
| 126 | float primaryRefreshRateMax; |
| 127 | float appRequestRefreshRateMin; |
| 128 | float appRequestRefreshRateMax; |
| 129 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 130 | res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig, |
| 131 | &newAllowGroupSwitching, |
| 132 | &primaryRefreshRateMin, |
| 133 | &primaryRefreshRateMax, |
| 134 | &appRequestRefreshRateMin, |
| 135 | &appRequestRefreshRateMax); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 136 | 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 | |
| 145 | TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) { |
| 146 | testSetAllowGroupSwitching(true); |
| 147 | testSetAllowGroupSwitching(false); |
| 148 | testSetAllowGroupSwitching(true); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 149 | } |
| 150 | |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 151 | } // namespace android |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 152 | |
| 153 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 154 | #pragma clang diagnostic pop // ignored "-Wextra" |