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: |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 42 | gui::DisplayModeSpecs mSpecs; |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 43 | |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 44 | protected: |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 45 | void SetUp() override { |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 46 | const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 47 | ASSERT_FALSE(ids.empty()); |
| 48 | mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front()); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 49 | status_t res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &mSpecs); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 50 | ASSERT_EQ(res, NO_ERROR); |
| 51 | } |
| 52 | |
| 53 | void TearDown() override { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 54 | status_t res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, mSpecs); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 55 | ASSERT_EQ(res, NO_ERROR); |
| 56 | } |
| 57 | |
| 58 | void testSetAllowGroupSwitching(bool allowGroupSwitching); |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 59 | |
| 60 | sp<IBinder> mDisplayToken; |
| 61 | }; |
| 62 | |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 63 | TEST_F(RefreshRateRangeTest, setAllConfigs) { |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 64 | ui::DynamicDisplayInfo info; |
| 65 | status_t res = SurfaceComposerClient::getDynamicDisplayInfo(mDisplayToken, &info); |
| 66 | const auto& modes = info.supportedDisplayModes; |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 67 | ASSERT_EQ(res, NO_ERROR); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 68 | ASSERT_GT(modes.size(), 0); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 69 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 70 | gui::DisplayModeSpecs setSpecs; |
| 71 | setSpecs.allowGroupSwitching = false; |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 72 | for (size_t i = 0; i < modes.size(); i++) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 73 | 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 Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 79 | ASSERT_EQ(res, NO_ERROR); |
| 80 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 81 | gui::DisplayModeSpecs getSpecs; |
| 82 | res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 83 | ASSERT_EQ(res, NO_ERROR); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 84 | ASSERT_EQ(setSpecs, getSpecs); |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 85 | } |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 86 | } |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 87 | |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 88 | void RefreshRateRangeTest::testSetAllowGroupSwitching(bool allowGroupSwitching) { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 89 | 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 Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 96 | |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 97 | status_t res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, setSpecs); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 98 | ASSERT_EQ(res, NO_ERROR); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 99 | gui::DisplayModeSpecs getSpecs; |
| 100 | res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs); |
| 101 | ASSERT_EQ(res, NO_ERROR); |
| 102 | ASSERT_EQ(setSpecs, getSpecs); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) { |
| 106 | testSetAllowGroupSwitching(true); |
| 107 | testSetAllowGroupSwitching(false); |
| 108 | testSetAllowGroupSwitching(true); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 111 | } // namespace android |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 112 | |
| 113 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 114 | #pragma clang diagnostic pop // ignored "-Wextra" |