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 { |
| 51 | mDisplayToken = SurfaceComposerClient::getInternalDisplayToken(); |
| 52 | status_t res = |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 53 | SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, |
| 54 | &initialDefaultMode, |
| 55 | &initialAllowGroupSwitching, |
| 56 | &initialPrimaryMin, |
| 57 | &initialPrimaryMax, |
| 58 | &initialAppRequestMin, |
| 59 | &initialAppRequestMax); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 60 | ASSERT_EQ(res, NO_ERROR); |
| 61 | } |
| 62 | |
| 63 | void TearDown() override { |
| 64 | status_t res = |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 65 | SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, initialDefaultMode, |
| 66 | initialAllowGroupSwitching, |
| 67 | initialPrimaryMin, |
| 68 | initialPrimaryMax, |
| 69 | initialAppRequestMin, |
| 70 | initialAppRequestMax); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 71 | ASSERT_EQ(res, NO_ERROR); |
| 72 | } |
| 73 | |
| 74 | void testSetAllowGroupSwitching(bool allowGroupSwitching); |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 75 | |
| 76 | sp<IBinder> mDisplayToken; |
| 77 | }; |
| 78 | |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 79 | TEST_F(RefreshRateRangeTest, setAllConfigs) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 80 | ui::DynamicDisplayInfo info; |
| 81 | status_t res = SurfaceComposerClient::getDynamicDisplayInfo(mDisplayToken, &info); |
| 82 | const auto& modes = info.supportedDisplayModes; |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 83 | ASSERT_EQ(res, NO_ERROR); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 84 | ASSERT_GT(modes.size(), 0); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 85 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 86 | for (size_t i = 0; i < modes.size(); i++) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 87 | res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, modes[i].id, false, |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 88 | modes[i].refreshRate, |
| 89 | modes[i].refreshRate, |
| 90 | modes[i].refreshRate, |
| 91 | modes[i].refreshRate); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 92 | ASSERT_EQ(res, NO_ERROR); |
| 93 | |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 94 | ui::DisplayModeId defaultConfig; |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 95 | bool allowGroupSwitching; |
Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 96 | float primaryRefreshRateMin; |
| 97 | float primaryRefreshRateMax; |
| 98 | float appRequestRefreshRateMin; |
| 99 | float appRequestRefreshRateMax; |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 100 | res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig, |
| 101 | &allowGroupSwitching, |
| 102 | &primaryRefreshRateMin, |
| 103 | &primaryRefreshRateMax, |
| 104 | &appRequestRefreshRateMin, |
| 105 | &appRequestRefreshRateMax); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 106 | ASSERT_EQ(res, NO_ERROR); |
| 107 | ASSERT_EQ(defaultConfig, i); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 108 | ASSERT_EQ(allowGroupSwitching, false); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 109 | 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 Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 113 | } |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 114 | } |
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 | void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) { |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 117 | status_t res = |
| 118 | SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, 0, allowGroupSwitching, |
| 119 | 0.f, 90.f, 0.f, 90.f); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 120 | ASSERT_EQ(res, NO_ERROR); |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 121 | ui::DisplayModeId defaultConfig; |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 122 | bool newAllowGroupSwitching; |
| 123 | float primaryRefreshRateMin; |
| 124 | float primaryRefreshRateMax; |
| 125 | float appRequestRefreshRateMin; |
| 126 | float appRequestRefreshRateMax; |
| 127 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 128 | res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &defaultConfig, |
| 129 | &newAllowGroupSwitching, |
| 130 | &primaryRefreshRateMin, |
| 131 | &primaryRefreshRateMax, |
| 132 | &appRequestRefreshRateMin, |
| 133 | &appRequestRefreshRateMax); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 134 | 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 | |
| 143 | TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) { |
| 144 | testSetAllowGroupSwitching(true); |
| 145 | testSetAllowGroupSwitching(false); |
| 146 | testSetAllowGroupSwitching(true); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 149 | } // namespace android |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 150 | |
| 151 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 152 | #pragma clang diagnostic pop // ignored "-Wextra" |