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()); |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 48 | mDisplayId = ids.front().value; |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 49 | mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front()); |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 50 | status_t res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &mSpecs); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 51 | ASSERT_EQ(res, NO_ERROR); |
| 52 | } |
| 53 | |
| 54 | void TearDown() override { |
Ady Abraham | 285f8c1 | 2022-10-11 17:12:14 -0700 | [diff] [blame] | 55 | status_t res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, mSpecs); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 56 | ASSERT_EQ(res, NO_ERROR); |
| 57 | } |
| 58 | |
ramindani | 87cbe26 | 2023-11-27 16:50:02 -0800 | [diff] [blame] | 59 | void testSetDesiredDisplayModeSpecs(bool allowGroupSwitching = false) { |
| 60 | ui::DynamicDisplayInfo info; |
| 61 | status_t res = |
| 62 | SurfaceComposerClient::getDynamicDisplayInfoFromId(static_cast<int64_t>(mDisplayId), |
| 63 | &info); |
| 64 | const auto& modes = info.supportedDisplayModes; |
| 65 | ASSERT_EQ(res, NO_ERROR); |
| 66 | ASSERT_GT(modes.size(), 0); |
| 67 | for (const auto& mode : modes) { |
| 68 | gui::DisplayModeSpecs setSpecs; |
| 69 | setSpecs.defaultMode = mode.id; |
| 70 | setSpecs.allowGroupSwitching = allowGroupSwitching; |
| 71 | setSpecs.primaryRanges.physical.min = mode.peakRefreshRate; |
| 72 | setSpecs.primaryRanges.physical.max = mode.peakRefreshRate; |
| 73 | setSpecs.primaryRanges.render = setSpecs.primaryRanges.physical; |
| 74 | setSpecs.appRequestRanges = setSpecs.primaryRanges; |
| 75 | |
| 76 | res = SurfaceComposerClient::setDesiredDisplayModeSpecs(mDisplayToken, setSpecs); |
| 77 | ASSERT_EQ(res, NO_ERROR); |
| 78 | gui::DisplayModeSpecs getSpecs; |
| 79 | res = SurfaceComposerClient::getDesiredDisplayModeSpecs(mDisplayToken, &getSpecs); |
| 80 | ASSERT_EQ(res, NO_ERROR); |
| 81 | ASSERT_EQ(setSpecs, getSpecs); |
| 82 | } |
| 83 | } |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 84 | |
| 85 | sp<IBinder> mDisplayToken; |
Sally Qi | 6bb1282 | 2022-10-05 11:42:30 -0700 | [diff] [blame] | 86 | uint64_t mDisplayId; |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Steven Thomas | 6d2f5c3 | 2020-01-06 12:15:59 -0800 | [diff] [blame] | 89 | TEST_F(RefreshRateRangeTest, setAllConfigs) { |
ramindani | 87cbe26 | 2023-11-27 16:50:02 -0800 | [diff] [blame] | 90 | testSetDesiredDisplayModeSpecs(); |
Marin Shalamanov | 30b0b3c | 2020-10-13 19:15:06 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | TEST_F(RefreshRateRangeTest, setAllowGroupSwitching) { |
ramindani | 87cbe26 | 2023-11-27 16:50:02 -0800 | [diff] [blame] | 94 | testSetDesiredDisplayModeSpecs(/*allowGroupSwitching=*/true); |
| 95 | testSetDesiredDisplayModeSpecs(/*allowGroupSwitching=*/false); |
| 96 | testSetDesiredDisplayModeSpecs(/*allowGroupSwitching=*/true); |
Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 99 | } // namespace android |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 100 | |
| 101 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 102 | #pragma clang diagnostic pop // ignored "-Wextra" |