Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 21 | #undef LOG_TAG |
| 22 | #define LOG_TAG "LibSurfaceFlingerUnittests" |
| 23 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 24 | #include <type_traits> |
| 25 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 26 | #include <android/hardware/power/Boost.h> |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 27 | #include <binder/IPCThreadState.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 28 | #include <compositionengine/Display.h> |
| 29 | #include <compositionengine/DisplayColorProfile.h> |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 30 | #include <compositionengine/impl/Display.h> |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 31 | #include <compositionengine/impl/OutputCompositionState.h> |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 32 | #include <compositionengine/mock/Display.h> |
| 33 | #include <compositionengine/mock/DisplayColorProfile.h> |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 34 | #include <compositionengine/mock/DisplaySurface.h> |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 35 | #include <compositionengine/mock/RenderSurface.h> |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 36 | #include <gmock/gmock.h> |
| 37 | #include <gtest/gtest.h> |
Lloyd Pique | 1ebe090 | 2019-10-04 14:47:13 -0700 | [diff] [blame] | 38 | #include <gui/mock/GraphicBufferConsumer.h> |
| 39 | #include <gui/mock/GraphicBufferProducer.h> |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 40 | #include <log/log.h> |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 41 | #include <private/android_filesystem_config.h> |
Lloyd Pique | 3823e7b | 2018-10-18 16:58:10 -0700 | [diff] [blame] | 42 | #include <renderengine/mock/RenderEngine.h> |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 43 | #include <ui/DebugUtils.h> |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 44 | |
| 45 | #include "DisplayIdentificationTest.h" |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 46 | #include "TestableScheduler.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 47 | #include "TestableSurfaceFlinger.h" |
Lloyd Pique | cbe0001 | 2018-02-02 15:40:42 -0800 | [diff] [blame] | 48 | #include "mock/DisplayHardware/MockComposer.h" |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 49 | #include "mock/DisplayHardware/MockPowerAdvisor.h" |
Lloyd Pique | cbe0001 | 2018-02-02 15:40:42 -0800 | [diff] [blame] | 50 | #include "mock/MockEventThread.h" |
| 51 | #include "mock/MockMessageQueue.h" |
| 52 | #include "mock/MockNativeWindowSurface.h" |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 53 | #include "mock/MockSchedulerCallback.h" |
Lloyd Pique | cbe0001 | 2018-02-02 15:40:42 -0800 | [diff] [blame] | 54 | #include "mock/MockSurfaceInterceptor.h" |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 55 | #include "mock/MockVsyncController.h" |
Lloyd Pique | cbe0001 | 2018-02-02 15:40:42 -0800 | [diff] [blame] | 56 | #include "mock/system/window/MockNativeWindow.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 57 | |
| 58 | namespace android { |
| 59 | namespace { |
| 60 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 61 | namespace hal = android::hardware::graphics::composer::hal; |
| 62 | |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 63 | using android::hardware::power::Boost; |
| 64 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 65 | using testing::_; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 66 | using testing::AnyNumber; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 67 | using testing::DoAll; |
| 68 | using testing::Mock; |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 69 | using testing::ResultOf; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 70 | using testing::Return; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 71 | using testing::ReturnRefOfCopy; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 72 | using testing::SetArgPointee; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 73 | using testing::StrictMock; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 74 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 75 | using hal::ColorMode; |
| 76 | using hal::Connection; |
| 77 | using hal::DisplayCapability; |
| 78 | using hal::DisplayType; |
| 79 | using hal::Error; |
| 80 | using hal::Hdr; |
| 81 | using hal::HWDisplayId; |
| 82 | using hal::IComposer; |
| 83 | using hal::IComposerClient; |
| 84 | using hal::PerFrameMetadataKey; |
| 85 | using hal::PowerMode; |
| 86 | using hal::RenderIntent; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 87 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 88 | using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector; |
| 89 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 90 | using HotplugEvent = TestableSurfaceFlinger::HotplugEvent; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 91 | using HWC2Display = TestableSurfaceFlinger::HWC2Display; |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 92 | |
Ady Abraham | 2492a02 | 2020-07-24 11:09:55 -0700 | [diff] [blame] | 93 | constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'667; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 94 | constexpr int32_t DEFAULT_DPI = 320; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 95 | constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 96 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 97 | constexpr int POWER_MODE_LEET = 1337; // An out of range power mode value |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 98 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 99 | /* ------------------------------------------------------------------------ |
| 100 | * Boolean avoidance |
| 101 | * |
| 102 | * To make calls and template instantiations more readable, we define some |
| 103 | * local enums along with an implicit bool conversion. |
| 104 | */ |
| 105 | |
| 106 | #define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true }; |
| 107 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 108 | BOOL_SUBSTITUTE(Async); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 109 | BOOL_SUBSTITUTE(Critical); |
| 110 | BOOL_SUBSTITUTE(Primary); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 111 | BOOL_SUBSTITUTE(Secure); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 112 | BOOL_SUBSTITUTE(Virtual); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 113 | |
| 114 | /* ------------------------------------------------------------------------ |
| 115 | * |
| 116 | */ |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 117 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 118 | class DisplayTransactionTest : public testing::Test { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 119 | public: |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 120 | DisplayTransactionTest(); |
| 121 | ~DisplayTransactionTest() override; |
| 122 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 123 | // -------------------------------------------------------------------- |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 124 | // Mock/Fake injection |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 125 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 126 | void injectMockScheduler(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 127 | void injectMockComposer(int virtualDisplayCount); |
| 128 | void injectFakeBufferQueueFactory(); |
| 129 | void injectFakeNativeWindowSurfaceFactory(); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 130 | sp<DisplayDevice> injectDefaultInternalDisplay(std::function<void(FakeDisplayDeviceInjector&)>); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 131 | |
| 132 | // -------------------------------------------------------------------- |
| 133 | // Postcondition helpers |
| 134 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 135 | bool hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 136 | bool hasTransactionFlagSet(int flag); |
| 137 | bool hasDisplayDevice(sp<IBinder> displayToken); |
| 138 | sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken); |
| 139 | bool hasCurrentDisplayState(sp<IBinder> displayToken); |
| 140 | const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken); |
| 141 | bool hasDrawingDisplayState(sp<IBinder> displayToken); |
| 142 | const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken); |
| 143 | |
| 144 | // -------------------------------------------------------------------- |
| 145 | // Test instances |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 146 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 147 | TestableSurfaceFlinger mFlinger; |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 148 | sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow(); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 149 | sp<GraphicBuffer> mBuffer = new GraphicBuffer(); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 150 | Hwc2::mock::PowerAdvisor mPowerAdvisor; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 151 | |
| 152 | // These mocks are created by the test, but are destroyed by SurfaceFlinger |
| 153 | // by virtue of being stored into a std::unique_ptr. However we still need |
| 154 | // to keep a reference to them for use in setting up call expectations. |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 155 | renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 156 | Hwc2::mock::Composer* mComposer = nullptr; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 157 | mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); |
Pablo Gamito | 5cfc6e5 | 2020-09-10 11:18:03 +0000 | [diff] [blame] | 158 | sp<mock::SurfaceInterceptor> mSurfaceInterceptor = new mock::SurfaceInterceptor; |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 159 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 160 | mock::VsyncController* mVsyncController = new mock::VsyncController; |
| 161 | mock::VSyncTracker* mVSyncTracker = new mock::VSyncTracker; |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 162 | mock::SchedulerCallback mSchedulerCallback; |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 163 | mock::EventThread* mEventThread = new mock::EventThread; |
| 164 | mock::EventThread* mSFEventThread = new mock::EventThread; |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 165 | |
| 166 | // These mocks are created only when expected to be created via a factory. |
| 167 | sp<mock::GraphicBufferConsumer> mConsumer; |
| 168 | sp<mock::GraphicBufferProducer> mProducer; |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 169 | surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr; |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | DisplayTransactionTest::DisplayTransactionTest() { |
| 173 | const ::testing::TestInfo* const test_info = |
| 174 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 175 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 176 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 177 | // Default to no wide color display support configured |
| 178 | mFlinger.mutableHasWideColorDisplay() = false; |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 179 | mFlinger.mutableUseColorManagement() = false; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 180 | mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 181 | |
| 182 | // Default to using HWC virtual displays |
| 183 | mFlinger.mutableUseHwcVirtualDisplays() = true; |
| 184 | |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 185 | mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) { |
| 186 | ADD_FAILURE() << "Unexpected request to create a buffer queue."; |
| 187 | }); |
| 188 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 189 | mFlinger.setCreateNativeWindowSurface([](auto) { |
| 190 | ADD_FAILURE() << "Unexpected request to create a native window surface."; |
| 191 | return nullptr; |
| 192 | }); |
| 193 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 194 | injectMockScheduler(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 195 | mFlinger.mutableEventQueue().reset(mMessageQueue); |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 196 | mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); |
Pablo Gamito | 5cfc6e5 | 2020-09-10 11:18:03 +0000 | [diff] [blame] | 197 | mFlinger.mutableInterceptor() = mSurfaceInterceptor; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 198 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 199 | injectMockComposer(0); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | DisplayTransactionTest::~DisplayTransactionTest() { |
| 203 | const ::testing::TestInfo* const test_info = |
| 204 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 205 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 206 | } |
| 207 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 208 | void DisplayTransactionTest::injectMockScheduler() { |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 209 | EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_)); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 210 | EXPECT_CALL(*mEventThread, createEventConnection(_, _)) |
| 211 | .WillOnce(Return(new EventThreadConnection(mEventThread, ResyncCallback(), |
| 212 | ISurfaceComposer::eConfigChangedSuppress))); |
| 213 | |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 214 | EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_)); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 215 | EXPECT_CALL(*mSFEventThread, createEventConnection(_, _)) |
| 216 | .WillOnce(Return(new EventThreadConnection(mSFEventThread, ResyncCallback(), |
| 217 | ISurfaceComposer::eConfigChangedSuppress))); |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 218 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 219 | mFlinger.setupScheduler(std::unique_ptr<scheduler::VsyncController>(mVsyncController), |
| 220 | std::unique_ptr<scheduler::VSyncTracker>(mVSyncTracker), |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 221 | std::unique_ptr<EventThread>(mEventThread), |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 222 | std::unique_ptr<EventThread>(mSFEventThread), &mSchedulerCallback); |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 225 | void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) { |
| 226 | mComposer = new Hwc2::mock::Composer(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 227 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); |
| 228 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 229 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 230 | Mock::VerifyAndClear(mComposer); |
| 231 | } |
| 232 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 233 | void DisplayTransactionTest::injectFakeBufferQueueFactory() { |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 234 | // This setup is only expected once per test. |
| 235 | ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr); |
| 236 | |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 237 | mConsumer = new mock::GraphicBufferConsumer(); |
| 238 | mProducer = new mock::GraphicBufferProducer(); |
| 239 | |
| 240 | mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) { |
| 241 | *outProducer = mProducer; |
| 242 | *outConsumer = mConsumer; |
| 243 | }); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 244 | } |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 245 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 246 | void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() { |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 247 | // This setup is only expected once per test. |
| 248 | ASSERT_TRUE(mNativeWindowSurface == nullptr); |
| 249 | |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 250 | mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 251 | |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 252 | mFlinger.setCreateNativeWindowSurface([this](auto) { |
| 253 | return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface); |
| 254 | }); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 257 | sp<DisplayDevice> DisplayTransactionTest::injectDefaultInternalDisplay( |
| 258 | std::function<void(FakeDisplayDeviceInjector&)> injectExtra) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 259 | constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID(777); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 260 | constexpr int DEFAULT_DISPLAY_WIDTH = 1080; |
| 261 | constexpr int DEFAULT_DISPLAY_HEIGHT = 1920; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 262 | constexpr HWDisplayId DEFAULT_DISPLAY_HWC_DISPLAY_ID = 0; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 263 | |
| 264 | // The DisplayDevice is required to have a framebuffer (behind the |
| 265 | // ANativeWindow interface) which uses the actual hardware display |
| 266 | // size. |
| 267 | EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 268 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0))); |
| 269 | EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 270 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0))); |
| 271 | EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)); |
| 272 | EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)); |
| 273 | EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)); |
| 274 | EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(AnyNumber()); |
| 275 | |
| 276 | auto compositionDisplay = compositionengine::impl:: |
| 277 | createDisplay(mFlinger.getCompositionEngine(), |
| 278 | compositionengine::DisplayCreationArgsBuilder() |
| 279 | .setPhysical( |
| 280 | {DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal}) |
| 281 | .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) |
| 282 | .setPowerAdvisor(&mPowerAdvisor) |
| 283 | .build()); |
| 284 | |
| 285 | auto injector = |
| 286 | FakeDisplayDeviceInjector(mFlinger, compositionDisplay, DisplayConnectionType::Internal, |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 287 | DEFAULT_DISPLAY_HWC_DISPLAY_ID, true /* isPrimary */); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 288 | |
| 289 | injector.setNativeWindow(mNativeWindow); |
| 290 | if (injectExtra) { |
| 291 | injectExtra(injector); |
| 292 | } |
| 293 | |
| 294 | auto displayDevice = injector.inject(); |
| 295 | |
| 296 | Mock::VerifyAndClear(mNativeWindow.get()); |
| 297 | |
| 298 | return displayDevice; |
| 299 | } |
| 300 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 301 | bool DisplayTransactionTest::hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 302 | return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | bool DisplayTransactionTest::hasTransactionFlagSet(int flag) { |
| 306 | return mFlinger.mutableTransactionFlags() & flag; |
| 307 | } |
| 308 | |
| 309 | bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 310 | return mFlinger.mutableDisplays().count(displayToken) == 1; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 314 | return mFlinger.mutableDisplays()[displayToken]; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) { |
| 318 | return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0; |
| 319 | } |
| 320 | |
| 321 | const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) { |
| 322 | return mFlinger.mutableCurrentState().displays.valueFor(displayToken); |
| 323 | } |
| 324 | |
| 325 | bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) { |
| 326 | return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0; |
| 327 | } |
| 328 | |
| 329 | const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) { |
| 330 | return mFlinger.mutableDrawingState().displays.valueFor(displayToken); |
| 331 | } |
| 332 | |
| 333 | /* ------------------------------------------------------------------------ |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 334 | * |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 335 | */ |
| 336 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 337 | template <typename PhysicalDisplay> |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 338 | struct PhysicalDisplayIdType {}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 339 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 340 | template <uint64_t displayId> |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 341 | using HalVirtualDisplayIdType = std::integral_constant<uint64_t, displayId>; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 342 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 343 | struct GpuVirtualDisplayIdType {}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 344 | |
| 345 | template <typename> |
| 346 | struct IsPhysicalDisplayId : std::bool_constant<false> {}; |
| 347 | |
| 348 | template <typename PhysicalDisplay> |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 349 | struct IsPhysicalDisplayId<PhysicalDisplayIdType<PhysicalDisplay>> : std::bool_constant<true> {}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 350 | |
| 351 | template <typename> |
| 352 | struct DisplayIdGetter; |
| 353 | |
| 354 | template <typename PhysicalDisplay> |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 355 | struct DisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 356 | static PhysicalDisplayId get() { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 357 | if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 358 | return PhysicalDisplayId::fromPort(static_cast<bool>(PhysicalDisplay::PRIMARY) |
| 359 | ? LEGACY_DISPLAY_TYPE_PRIMARY |
| 360 | : LEGACY_DISPLAY_TYPE_EXTERNAL); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | const auto info = |
| 364 | parseDisplayIdentificationData(PhysicalDisplay::PORT, |
| 365 | PhysicalDisplay::GET_IDENTIFICATION_DATA()); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 366 | return info ? info->id : PhysicalDisplayId::fromPort(PhysicalDisplay::PORT); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 367 | } |
| 368 | }; |
| 369 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 370 | template <uint64_t displayId> |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 371 | struct DisplayIdGetter<HalVirtualDisplayIdType<displayId>> { |
| 372 | static HalVirtualDisplayId get() { return HalVirtualDisplayId(displayId); } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | template <> |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 376 | struct DisplayIdGetter<GpuVirtualDisplayIdType> { |
| 377 | static GpuVirtualDisplayId get() { return GpuVirtualDisplayId(0); } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 378 | }; |
| 379 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 380 | template <typename> |
| 381 | struct DisplayConnectionTypeGetter { |
| 382 | static constexpr std::optional<DisplayConnectionType> value; |
| 383 | }; |
| 384 | |
| 385 | template <typename PhysicalDisplay> |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 386 | struct DisplayConnectionTypeGetter<PhysicalDisplayIdType<PhysicalDisplay>> { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 387 | static constexpr std::optional<DisplayConnectionType> value = PhysicalDisplay::CONNECTION_TYPE; |
| 388 | }; |
| 389 | |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 390 | template <typename> |
| 391 | struct HwcDisplayIdGetter { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 392 | static constexpr std::optional<HWDisplayId> value; |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 393 | }; |
| 394 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 395 | constexpr HWDisplayId HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID = 1010; |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 396 | |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 397 | template <uint64_t displayId> |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 398 | struct HwcDisplayIdGetter<HalVirtualDisplayIdType<displayId>> { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 399 | static constexpr std::optional<HWDisplayId> value = HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID; |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | template <typename PhysicalDisplay> |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 403 | struct HwcDisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 404 | static constexpr std::optional<HWDisplayId> value = PhysicalDisplay::HWC_DISPLAY_ID; |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 405 | }; |
| 406 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 407 | // DisplayIdType can be: |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 408 | // 1) PhysicalDisplayIdType<...> for generated ID of physical display backed by HWC. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 409 | // 2) HalVirtualDisplayIdType<...> for hard-coded ID of virtual display backed by HWC. |
| 410 | // 3) GpuVirtualDisplayIdType for virtual display without HWC backing. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 411 | template <typename DisplayIdType, int width, int height, Critical critical, Async async, |
| 412 | Secure secure, Primary primary, int grallocUsage> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 413 | struct DisplayVariant { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 414 | using DISPLAY_ID = DisplayIdGetter<DisplayIdType>; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 415 | using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>; |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 416 | using HWC_DISPLAY_ID_OPT = HwcDisplayIdGetter<DisplayIdType>; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 417 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 418 | // The display width and height |
| 419 | static constexpr int WIDTH = width; |
| 420 | static constexpr int HEIGHT = height; |
| 421 | |
| 422 | static constexpr int GRALLOC_USAGE = grallocUsage; |
| 423 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 424 | // Whether the display is virtual or physical |
| 425 | static constexpr Virtual VIRTUAL = |
| 426 | IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 427 | |
| 428 | // When creating native window surfaces for the framebuffer, whether those should be critical |
| 429 | static constexpr Critical CRITICAL = critical; |
| 430 | |
| 431 | // When creating native window surfaces for the framebuffer, whether those should be async |
| 432 | static constexpr Async ASYNC = async; |
| 433 | |
| 434 | // Whether the display should be treated as secure |
| 435 | static constexpr Secure SECURE = secure; |
| 436 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 437 | // Whether the display is primary |
| 438 | static constexpr Primary PRIMARY = primary; |
| 439 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 440 | static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) { |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 441 | auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 442 | if (auto displayId = PhysicalDisplayId::tryCast(DISPLAY_ID::get())) { |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 443 | ceDisplayArgs.setPhysical({*displayId, DisplayConnectionType::Internal}); |
| 444 | } else { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 445 | // We turn off the use of HwcVirtualDisplays, to prevent Composition Engine |
| 446 | // from calling into HWComposer. This way all virtual displays will get |
| 447 | // a GpuVirtualDisplayId, even if we are in the HwcVirtualDisplayVariant. |
| 448 | // In this case we later override it by calling display.setDisplayIdForTesting(). |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 449 | ceDisplayArgs.setUseHwcVirtualDisplays(false); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 450 | |
| 451 | GpuVirtualDisplayId desiredDisplayId = GpuVirtualDisplayId::tryCast(DISPLAY_ID::get()) |
| 452 | .value_or(GpuVirtualDisplayId(0)); |
| 453 | |
| 454 | ON_CALL(test->mFlinger.gpuVirtualDisplayIdGenerator(), nextId()) |
| 455 | .WillByDefault(Return(desiredDisplayId)); |
| 456 | |
| 457 | auto& generator = test->mFlinger.gpuVirtualDisplayIdGenerator(); |
| 458 | ceDisplayArgs.setGpuVirtualDisplayIdGenerator(generator); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 459 | } |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 460 | ceDisplayArgs.setPixels({WIDTH, HEIGHT}).setPowerAdvisor(&test->mPowerAdvisor); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 461 | |
| 462 | auto compositionDisplay = |
| 463 | compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(), |
| 464 | ceDisplayArgs.build()); |
| 465 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 466 | if (HalVirtualDisplayId::tryCast(DISPLAY_ID::get())) { |
| 467 | // CompositionEngine has assigned a placeholder GpuVirtualDisplayId and we need to |
| 468 | // override it with the correct HalVirtualDisplayId. |
| 469 | compositionDisplay->setDisplayIdForTesting(DISPLAY_ID::get()); |
| 470 | } |
| 471 | |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 472 | auto injector = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay, |
| 473 | CONNECTION_TYPE::value, HWC_DISPLAY_ID_OPT::value, |
| 474 | static_cast<bool>(PRIMARY)); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 475 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 476 | injector.setSecure(static_cast<bool>(SECURE)); |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 477 | injector.setNativeWindow(test->mNativeWindow); |
| 478 | |
| 479 | // Creating a DisplayDevice requires getting default dimensions from the |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 480 | // native window along with some other initial setup. |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 481 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 482 | .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0))); |
| 483 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 484 | .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0))); |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 485 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)) |
| 486 | .WillRepeatedly(Return(0)); |
| 487 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)) |
| 488 | .WillRepeatedly(Return(0)); |
| 489 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)) |
| 490 | .WillRepeatedly(Return(0)); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 491 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)) |
| 492 | .WillRepeatedly(Return(0)); |
| 493 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 494 | return injector; |
| 495 | } |
| 496 | |
| 497 | // Called by tests to set up any native window creation call expectations. |
| 498 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 499 | EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow()) |
| 500 | .WillOnce(Return(test->mNativeWindow)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 501 | |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 502 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 503 | .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0))); |
| 504 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 505 | .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0))); |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 506 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)) |
| 507 | .WillRepeatedly(Return(0)); |
| 508 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)) |
| 509 | .WillRepeatedly(Return(0)); |
| 510 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)) |
| 511 | .WillRepeatedly(Return(0)); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 512 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)) |
| 513 | .WillRepeatedly(Return(0)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) { |
| 517 | EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR)); |
| 518 | EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR)); |
| 519 | EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE)) |
| 520 | .WillRepeatedly(Return(NO_ERROR)); |
| 521 | EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT)) |
| 522 | .WillRepeatedly(Return(NO_ERROR)); |
| 523 | EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_)) |
| 524 | .WillRepeatedly(Return(NO_ERROR)); |
| 525 | } |
| 526 | |
| 527 | static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) { |
| 528 | EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return()); |
| 529 | } |
| 530 | }; |
| 531 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 532 | template <HWDisplayId hwcDisplayId, DisplayType hwcDisplayType, typename DisplayVariant, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 533 | typename PhysicalDisplay = void> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 534 | struct HwcDisplayVariant { |
| 535 | // The display id supplied by the HWC |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 536 | static constexpr HWDisplayId HWC_DISPLAY_ID = hwcDisplayId; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 537 | |
| 538 | // The HWC display type |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 539 | static constexpr DisplayType HWC_DISPLAY_TYPE = hwcDisplayType; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 540 | |
| 541 | // The HWC active configuration id |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 542 | static constexpr int HWC_ACTIVE_CONFIG_ID = 2001; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 543 | static constexpr PowerMode INIT_POWER_MODE = PowerMode::ON; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 544 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 545 | static void injectPendingHotplugEvent(DisplayTransactionTest* test, Connection connection) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 546 | test->mFlinger.mutablePendingHotplugEvents().emplace_back( |
| 547 | HotplugEvent{HWC_DISPLAY_ID, connection}); |
| 548 | } |
| 549 | |
| 550 | // Called by tests to inject a HWC display setup |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 551 | static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 552 | const auto displayId = DisplayVariant::DISPLAY_ID::get(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 553 | ASSERT_FALSE(GpuVirtualDisplayId::tryCast(displayId)); |
| 554 | FakeHwcDisplayInjector(displayId, HWC_DISPLAY_TYPE, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 555 | static_cast<bool>(DisplayVariant::PRIMARY)) |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 556 | .setHwcDisplayId(HWC_DISPLAY_ID) |
| 557 | .setWidth(DisplayVariant::WIDTH) |
| 558 | .setHeight(DisplayVariant::HEIGHT) |
| 559 | .setActiveConfig(HWC_ACTIVE_CONFIG_ID) |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 560 | .setPowerMode(INIT_POWER_MODE) |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 561 | .inject(&test->mFlinger, test->mComposer); |
| 562 | } |
| 563 | |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 564 | // Called by tests to inject a HWC display setup |
| 565 | static void injectHwcDisplay(DisplayTransactionTest* test) { |
| 566 | EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _)) |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 567 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})), |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 568 | Return(Error::NONE))); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 569 | EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY_ID, INIT_POWER_MODE)) |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 570 | .WillOnce(Return(Error::NONE)); |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 571 | injectHwcDisplayWithNoDefaultCapabilities(test); |
| 572 | } |
| 573 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 574 | static std::shared_ptr<compositionengine::Display> injectCompositionDisplay( |
| 575 | DisplayTransactionTest* test) { |
| 576 | const ::testing::TestInfo* const test_info = |
| 577 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 578 | |
| 579 | auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder() |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 580 | .setPhysical({DisplayVariant::DISPLAY_ID::get(), |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 581 | PhysicalDisplay::CONNECTION_TYPE}) |
| 582 | .setPixels({DisplayVariant::WIDTH, DisplayVariant::HEIGHT}) |
| 583 | .setIsSecure(static_cast<bool>(DisplayVariant::SECURE)) |
| 584 | .setPowerAdvisor(&test->mPowerAdvisor) |
| 585 | .setName(std::string("Injected display for ") + |
| 586 | test_info->test_case_name() + "." + test_info->name()) |
| 587 | .build(); |
| 588 | |
| 589 | return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(), |
| 590 | ceDisplayArgs); |
| 591 | } |
| 592 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 593 | static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 594 | constexpr auto CONNECTION_TYPE = |
| 595 | PhysicalDisplay::CONNECTION_TYPE == DisplayConnectionType::Internal |
| 596 | ? IComposerClient::DisplayConnectionType::INTERNAL |
| 597 | : IComposerClient::DisplayConnectionType::EXTERNAL; |
| 598 | |
| 599 | EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _)) |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 600 | .WillOnce(DoAll(SetArgPointee<1>(CONNECTION_TYPE), Return(hal::V2_4::Error::NONE))); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 601 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 602 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)) |
| 603 | .WillOnce(Return(hal::Error::NONE)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 604 | EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _)) |
| 605 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}), |
| 606 | Return(Error::NONE))); |
| 607 | EXPECT_CALL(*test->mComposer, |
| 608 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 609 | IComposerClient::Attribute::WIDTH, _)) |
| 610 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE))); |
| 611 | EXPECT_CALL(*test->mComposer, |
| 612 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 613 | IComposerClient::Attribute::HEIGHT, _)) |
| 614 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE))); |
| 615 | EXPECT_CALL(*test->mComposer, |
| 616 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 617 | IComposerClient::Attribute::VSYNC_PERIOD, _)) |
| 618 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE))); |
| 619 | EXPECT_CALL(*test->mComposer, |
| 620 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 621 | IComposerClient::Attribute::DPI_X, _)) |
| 622 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); |
| 623 | EXPECT_CALL(*test->mComposer, |
| 624 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 625 | IComposerClient::Attribute::DPI_Y, _)) |
| 626 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); |
Ady Abraham | 7159f57 | 2019-10-11 11:10:18 -0700 | [diff] [blame] | 627 | EXPECT_CALL(*test->mComposer, |
| 628 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 629 | IComposerClient::Attribute::CONFIG_GROUP, _)) |
| 630 | .WillOnce(DoAll(SetArgPointee<3>(-1), Return(Error::NONE))); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 631 | |
| 632 | if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) { |
| 633 | EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _)) |
Marin Shalamanov | 7ce8764 | 2020-05-06 13:45:58 +0200 | [diff] [blame] | 634 | .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT), |
| 635 | SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()), |
| 636 | Return(Error::NONE))); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 637 | } else { |
| 638 | EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _)) |
Marin Shalamanov | 7ce8764 | 2020-05-06 13:45:58 +0200 | [diff] [blame] | 639 | .WillOnce(Return(Error::UNSUPPORTED)); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 640 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | // Called by tests to set up HWC call expectations |
| 644 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { |
| 645 | EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _)) |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 646 | .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE))); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 647 | } |
| 648 | }; |
| 649 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 650 | // Physical displays are expected to be synchronous, secure, and have a HWC display for output. |
| 651 | constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY = |
| 652 | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB; |
| 653 | |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 654 | template <typename PhysicalDisplay, int width, int height, Critical critical> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 655 | struct PhysicalDisplayVariant |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 656 | : DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, critical, |
| 657 | Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY, |
| 658 | GRALLOC_USAGE_PHYSICAL_DISPLAY>, |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 659 | HwcDisplayVariant<PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL, |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 660 | DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 661 | critical, Async::FALSE, Secure::TRUE, |
| 662 | PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>, |
| 663 | PhysicalDisplay> {}; |
| 664 | |
| 665 | template <bool hasIdentificationData> |
| 666 | struct PrimaryDisplay { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 667 | static constexpr auto CONNECTION_TYPE = DisplayConnectionType::Internal; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 668 | static constexpr Primary PRIMARY = Primary::TRUE; |
| 669 | static constexpr uint8_t PORT = 255; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 670 | static constexpr HWDisplayId HWC_DISPLAY_ID = 1001; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 671 | static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData; |
| 672 | static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid; |
| 673 | }; |
| 674 | |
| 675 | template <bool hasIdentificationData> |
| 676 | struct ExternalDisplay { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 677 | static constexpr auto CONNECTION_TYPE = DisplayConnectionType::External; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 678 | static constexpr Primary PRIMARY = Primary::FALSE; |
| 679 | static constexpr uint8_t PORT = 254; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 680 | static constexpr HWDisplayId HWC_DISPLAY_ID = 1002; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 681 | static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData; |
| 682 | static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid; |
| 683 | }; |
| 684 | |
| 685 | struct TertiaryDisplay { |
| 686 | static constexpr Primary PRIMARY = Primary::FALSE; |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 687 | static constexpr uint8_t PORT = 253; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 688 | static constexpr HWDisplayId HWC_DISPLAY_ID = 1003; |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 689 | static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 690 | }; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 691 | |
| 692 | // A primary display is a physical display that is critical |
| 693 | using PrimaryDisplayVariant = |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 694 | PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 695 | |
| 696 | // An external display is physical display that is not critical. |
| 697 | using ExternalDisplayVariant = |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 698 | PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280, Critical::FALSE>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 699 | |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 700 | using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200, Critical::FALSE>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 701 | |
| 702 | // A virtual display not supported by the HWC. |
| 703 | constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0; |
| 704 | |
| 705 | template <int width, int height, Secure secure> |
| 706 | struct NonHwcVirtualDisplayVariant |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 707 | : DisplayVariant<GpuVirtualDisplayIdType, width, height, Critical::FALSE, Async::TRUE, secure, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 708 | Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 709 | using Base = |
| 710 | DisplayVariant<GpuVirtualDisplayIdType, width, height, Critical::FALSE, Async::TRUE, |
| 711 | secure, Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 712 | |
| 713 | static void injectHwcDisplay(DisplayTransactionTest*) {} |
| 714 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 715 | static std::shared_ptr<compositionengine::Display> injectCompositionDisplay( |
| 716 | DisplayTransactionTest* test) { |
| 717 | const ::testing::TestInfo* const test_info = |
| 718 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 719 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 720 | ON_CALL(test->mFlinger.gpuVirtualDisplayIdGenerator(), nextId()) |
| 721 | .WillByDefault(Return(Base::DISPLAY_ID::get())); |
| 722 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 723 | auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder() |
| 724 | .setPixels({Base::WIDTH, Base::HEIGHT}) |
| 725 | .setIsSecure(static_cast<bool>(Base::SECURE)) |
| 726 | .setPowerAdvisor(&test->mPowerAdvisor) |
| 727 | .setName(std::string("Injected display for ") + |
| 728 | test_info->test_case_name() + "." + test_info->name()) |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 729 | .setGpuVirtualDisplayIdGenerator( |
| 730 | test->mFlinger.gpuVirtualDisplayIdGenerator()) |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 731 | .build(); |
| 732 | |
| 733 | return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(), |
| 734 | ceDisplayArgs); |
| 735 | } |
| 736 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 737 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { |
| 738 | EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0); |
| 739 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 740 | |
| 741 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 742 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); |
| 743 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); |
| 744 | } |
| 745 | }; |
| 746 | |
| 747 | // A virtual display supported by the HWC. |
| 748 | constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER; |
| 749 | |
| 750 | template <int width, int height, Secure secure> |
| 751 | struct HwcVirtualDisplayVariant |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 752 | : DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE, |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 753 | secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>, |
| 754 | HwcDisplayVariant<HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL, |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 755 | DisplayVariant<HalVirtualDisplayIdType<42>, width, height, |
| 756 | Critical::FALSE, Async::TRUE, secure, Primary::FALSE, |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 757 | GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 758 | using Base = DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE, |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 759 | Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 760 | using Self = HwcVirtualDisplayVariant<width, height, secure>; |
| 761 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 762 | static std::shared_ptr<compositionengine::Display> injectCompositionDisplay( |
| 763 | DisplayTransactionTest* test) { |
| 764 | const ::testing::TestInfo* const test_info = |
| 765 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 766 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 767 | // In order to prevent compostition engine calling into HWComposer, we |
| 768 | // 1. turn off the use of HWC virtual displays, |
| 769 | // 2. provide a GpuVirtualDisplayIdGenerator which always returns some fake ID |
| 770 | // 3. override the ID by calling setDisplayIdForTesting() |
| 771 | |
| 772 | ON_CALL(test->mFlinger.gpuVirtualDisplayIdGenerator(), nextId()) |
| 773 | .WillByDefault(Return(GpuVirtualDisplayId(0))); |
| 774 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 775 | auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder() |
| 776 | .setUseHwcVirtualDisplays(false) |
| 777 | .setPixels({Base::WIDTH, Base::HEIGHT}) |
| 778 | .setIsSecure(static_cast<bool>(Base::SECURE)) |
| 779 | .setPowerAdvisor(&test->mPowerAdvisor) |
| 780 | .setName(std::string("Injected display for ") + |
| 781 | test_info->test_case_name() + "." + test_info->name()) |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 782 | .setGpuVirtualDisplayIdGenerator( |
| 783 | test->mFlinger.gpuVirtualDisplayIdGenerator()) |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 784 | .build(); |
| 785 | |
| 786 | auto compositionDisplay = |
| 787 | compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(), |
| 788 | ceDisplayArgs); |
| 789 | compositionDisplay->setDisplayIdForTesting(Base::DISPLAY_ID::get()); |
| 790 | |
| 791 | // Insert display data so that the HWC thinks it created the virtual display. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 792 | if (const auto displayId = Base::DISPLAY_ID::get(); |
| 793 | HalVirtualDisplayId::tryCast(displayId)) { |
| 794 | test->mFlinger.mutableHwcDisplayData().try_emplace(displayId); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | return compositionDisplay; |
| 798 | } |
| 799 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 800 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 801 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); |
| 802 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); |
| 803 | } |
| 804 | |
| 805 | static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) { |
| 806 | EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _)) |
| 807 | .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE))); |
| 808 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); |
| 809 | } |
| 810 | }; |
| 811 | |
| 812 | // For this variant, SurfaceFlinger should not configure itself with wide |
| 813 | // display support, so the display should not be configured for wide-color |
| 814 | // support. |
| 815 | struct WideColorSupportNotConfiguredVariant { |
| 816 | static constexpr bool WIDE_COLOR_SUPPORTED = false; |
| 817 | |
| 818 | static void injectConfigChange(DisplayTransactionTest* test) { |
| 819 | test->mFlinger.mutableHasWideColorDisplay() = false; |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 820 | test->mFlinger.mutableUseColorManagement() = false; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 821 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 825 | EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0); |
| 826 | EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0); |
| 827 | EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0); |
| 828 | } |
| 829 | }; |
| 830 | |
| 831 | // For this variant, SurfaceFlinger should configure itself with wide display |
| 832 | // support, and the display should respond with an non-empty list of supported |
| 833 | // color modes. Wide-color support should be configured. |
| 834 | template <typename Display> |
| 835 | struct WideColorP3ColorimetricSupportedVariant { |
| 836 | static constexpr bool WIDE_COLOR_SUPPORTED = true; |
| 837 | |
| 838 | static void injectConfigChange(DisplayTransactionTest* test) { |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 839 | test->mFlinger.mutableUseColorManagement() = true; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 840 | test->mFlinger.mutableHasWideColorDisplay() = true; |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 841 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 845 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1); |
| 846 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 847 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) |
| 848 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})), |
| 849 | Return(Error::NONE))); |
| 850 | EXPECT_CALL(*test->mComposer, |
| 851 | getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _)) |
| 852 | .WillOnce(DoAll(SetArgPointee<2>( |
| 853 | std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})), |
| 854 | Return(Error::NONE))); |
| 855 | EXPECT_CALL(*test->mComposer, |
| 856 | setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB, |
| 857 | RenderIntent::COLORIMETRIC)) |
| 858 | .WillOnce(Return(Error::NONE)); |
| 859 | } |
| 860 | }; |
| 861 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 862 | // For this variant, SurfaceFlinger should configure itself with wide display |
| 863 | // support, but the display should respond with an empty list of supported color |
| 864 | // modes. Wide-color support for the display should not be configured. |
| 865 | template <typename Display> |
| 866 | struct WideColorNotSupportedVariant { |
| 867 | static constexpr bool WIDE_COLOR_SUPPORTED = false; |
| 868 | |
| 869 | static void injectConfigChange(DisplayTransactionTest* test) { |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 870 | test->mFlinger.mutableUseColorManagement() = true; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 871 | test->mFlinger.mutableHasWideColorDisplay() = true; |
| 872 | } |
| 873 | |
| 874 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 875 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) |
| 876 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE))); |
Chia-I Wu | 614e142 | 2018-05-23 02:17:03 -0700 | [diff] [blame] | 877 | EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 878 | } |
| 879 | }; |
| 880 | |
| 881 | // For this variant, the display is not a HWC display, so no HDR support should |
| 882 | // be configured. |
| 883 | struct NonHwcDisplayHdrSupportVariant { |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 884 | static constexpr bool HDR10_PLUS_SUPPORTED = false; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 885 | static constexpr bool HDR10_SUPPORTED = false; |
| 886 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 887 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 888 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 889 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0); |
| 890 | } |
| 891 | }; |
| 892 | |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 893 | template <typename Display> |
| 894 | struct Hdr10PlusSupportedVariant { |
| 895 | static constexpr bool HDR10_PLUS_SUPPORTED = true; |
| 896 | static constexpr bool HDR10_SUPPORTED = true; |
| 897 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 898 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 899 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 900 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)) |
| 901 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({ |
| 902 | Hdr::HDR10_PLUS, |
| 903 | Hdr::HDR10, |
| 904 | })), |
| 905 | Return(Error::NONE))); |
| 906 | } |
| 907 | }; |
| 908 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 909 | // For this variant, the composer should respond with a non-empty list of HDR |
| 910 | // modes containing HDR10, so HDR10 support should be configured. |
| 911 | template <typename Display> |
| 912 | struct Hdr10SupportedVariant { |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 913 | static constexpr bool HDR10_PLUS_SUPPORTED = false; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 914 | static constexpr bool HDR10_SUPPORTED = true; |
| 915 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 916 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 917 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 918 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 919 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})), |
| 920 | Return(Error::NONE))); |
| 921 | } |
| 922 | }; |
| 923 | |
| 924 | // For this variant, the composer should respond with a non-empty list of HDR |
| 925 | // modes containing HLG, so HLG support should be configured. |
| 926 | template <typename Display> |
| 927 | struct HdrHlgSupportedVariant { |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 928 | static constexpr bool HDR10_PLUS_SUPPORTED = false; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 929 | static constexpr bool HDR10_SUPPORTED = false; |
| 930 | static constexpr bool HDR_HLG_SUPPORTED = true; |
| 931 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 932 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 933 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 934 | .WillOnce( |
| 935 | DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE))); |
| 936 | } |
| 937 | }; |
| 938 | |
| 939 | // For this variant, the composer should respond with a non-empty list of HDR |
| 940 | // modes containing DOLBY_VISION, so DOLBY_VISION support should be configured. |
| 941 | template <typename Display> |
| 942 | struct HdrDolbyVisionSupportedVariant { |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 943 | static constexpr bool HDR10_PLUS_SUPPORTED = false; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 944 | static constexpr bool HDR10_SUPPORTED = false; |
| 945 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 946 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true; |
| 947 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 948 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 949 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})), |
| 950 | Return(Error::NONE))); |
| 951 | } |
| 952 | }; |
| 953 | |
| 954 | // For this variant, the composer should respond with am empty list of HDR |
| 955 | // modes, so no HDR support should be configured. |
| 956 | template <typename Display> |
| 957 | struct HdrNotSupportedVariant { |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 958 | static constexpr bool HDR10_PLUS_SUPPORTED = false; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 959 | static constexpr bool HDR10_SUPPORTED = false; |
| 960 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 961 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 962 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 963 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 964 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE))); |
| 965 | } |
| 966 | }; |
| 967 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 968 | struct NonHwcPerFrameMetadataSupportVariant { |
| 969 | static constexpr int PER_FRAME_METADATA_KEYS = 0; |
| 970 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 971 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 972 | } |
| 973 | }; |
| 974 | |
| 975 | template <typename Display> |
| 976 | struct NoPerFrameMetadataSupportVariant { |
| 977 | static constexpr int PER_FRAME_METADATA_KEYS = 0; |
| 978 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 979 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 980 | .WillOnce(Return(std::vector<PerFrameMetadataKey>())); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 981 | } |
| 982 | }; |
| 983 | |
| 984 | template <typename Display> |
| 985 | struct Smpte2086PerFrameMetadataSupportVariant { |
| 986 | static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086; |
| 987 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 988 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 989 | .WillOnce(Return(std::vector<PerFrameMetadataKey>({ |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 990 | PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, |
| 991 | PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, |
| 992 | PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, |
| 993 | PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, |
| 994 | PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, |
| 995 | PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, |
| 996 | PerFrameMetadataKey::WHITE_POINT_X, |
| 997 | PerFrameMetadataKey::WHITE_POINT_Y, |
| 998 | PerFrameMetadataKey::MAX_LUMINANCE, |
| 999 | PerFrameMetadataKey::MIN_LUMINANCE, |
| 1000 | }))); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1001 | } |
| 1002 | }; |
| 1003 | |
| 1004 | template <typename Display> |
| 1005 | struct Cta861_3_PerFrameMetadataSupportVariant { |
| 1006 | static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3; |
| 1007 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 1008 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 1009 | .WillOnce(Return(std::vector<PerFrameMetadataKey>({ |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 1010 | PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, |
| 1011 | PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, |
| 1012 | }))); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1013 | } |
| 1014 | }; |
| 1015 | |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 1016 | template <typename Display> |
| 1017 | struct Hdr10_Plus_PerFrameMetadataSupportVariant { |
| 1018 | static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS; |
| 1019 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 1020 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 1021 | .WillOnce(Return(std::vector<PerFrameMetadataKey>({ |
| 1022 | PerFrameMetadataKey::HDR10_PLUS_SEI, |
| 1023 | }))); |
| 1024 | } |
| 1025 | }; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1026 | /* ------------------------------------------------------------------------ |
| 1027 | * Typical display configurations to test |
| 1028 | */ |
| 1029 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1030 | template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy, |
| 1031 | typename PerFrameMetadataSupportPolicy> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1032 | struct Case { |
| 1033 | using Display = DisplayPolicy; |
| 1034 | using WideColorSupport = WideColorSupportPolicy; |
| 1035 | using HdrSupport = HdrSupportPolicy; |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1036 | using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1037 | }; |
| 1038 | |
| 1039 | using SimplePrimaryDisplayCase = |
| 1040 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1041 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 1042 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1043 | using SimpleExternalDisplayCase = |
| 1044 | Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1045 | HdrNotSupportedVariant<ExternalDisplayVariant>, |
| 1046 | NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1047 | using SimpleTertiaryDisplayCase = |
| 1048 | Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1049 | HdrNotSupportedVariant<TertiaryDisplayVariant>, |
| 1050 | NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1051 | using NonHwcVirtualDisplayCase = |
| 1052 | Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1053 | WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant, |
| 1054 | NonHwcPerFrameMetadataSupportVariant>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1055 | using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>; |
| 1056 | using HwcVirtualDisplayCase = |
| 1057 | Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant, |
Lloyd Pique | 438e9e7 | 2018-09-04 18:06:08 -0700 | [diff] [blame] | 1058 | HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>, |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 1059 | NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1060 | using WideColorP3ColorimetricDisplayCase = |
| 1061 | Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1062 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 1063 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 1064 | using Hdr10PlusDisplayCase = |
| 1065 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 1066 | Hdr10SupportedVariant<PrimaryDisplayVariant>, |
| 1067 | Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1068 | using Hdr10DisplayCase = |
| 1069 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1070 | Hdr10SupportedVariant<PrimaryDisplayVariant>, |
| 1071 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1072 | using HdrHlgDisplayCase = |
| 1073 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1074 | HdrHlgSupportedVariant<PrimaryDisplayVariant>, |
| 1075 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1076 | using HdrDolbyVisionDisplayCase = |
| 1077 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1078 | HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>, |
| 1079 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
| 1080 | using HdrSmpte2086DisplayCase = |
| 1081 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 1082 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 1083 | Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
| 1084 | using HdrCta861_3_DisplayCase = |
| 1085 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 1086 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 1087 | Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 1088 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1089 | /* ------------------------------------------------------------------------ |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 1090 | * |
| 1091 | * SurfaceFlinger::onHotplugReceived |
| 1092 | */ |
| 1093 | |
| 1094 | TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) { |
| 1095 | constexpr int currentSequenceId = 123; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1096 | constexpr HWDisplayId hwcDisplayId1 = 456; |
| 1097 | constexpr HWDisplayId hwcDisplayId2 = 654; |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 1098 | |
| 1099 | // -------------------------------------------------------------------- |
| 1100 | // Preconditions |
| 1101 | |
| 1102 | // Set the current sequence id for accepted events |
| 1103 | mFlinger.mutableComposerSequenceId() = currentSequenceId; |
| 1104 | |
| 1105 | // Set the main thread id so that the current thread does not appear to be |
| 1106 | // the main thread. |
| 1107 | mFlinger.mutableMainThreadId() = std::thread::id(); |
| 1108 | |
| 1109 | // -------------------------------------------------------------------- |
| 1110 | // Call Expectations |
| 1111 | |
| 1112 | // We expect invalidate() to be invoked once to trigger display transaction |
| 1113 | // processing. |
| 1114 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 1115 | |
| 1116 | // -------------------------------------------------------------------- |
| 1117 | // Invocation |
| 1118 | |
| 1119 | // Simulate two hotplug events (a connect and a disconnect) |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1120 | mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, Connection::CONNECTED); |
| 1121 | mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, Connection::DISCONNECTED); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 1122 | |
| 1123 | // -------------------------------------------------------------------- |
| 1124 | // Postconditions |
| 1125 | |
| 1126 | // The display transaction needed flag should be set. |
| 1127 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 1128 | |
| 1129 | // All events should be in the pending event queue. |
| 1130 | const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents(); |
| 1131 | ASSERT_EQ(2u, pendingEvents.size()); |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 1132 | EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1133 | EXPECT_EQ(Connection::CONNECTED, pendingEvents[0].connection); |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 1134 | EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1135 | EXPECT_EQ(Connection::DISCONNECTED, pendingEvents[1].connection); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) { |
| 1139 | constexpr int currentSequenceId = 123; |
| 1140 | constexpr int otherSequenceId = 321; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1141 | constexpr HWDisplayId displayId = 456; |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 1142 | |
| 1143 | // -------------------------------------------------------------------- |
| 1144 | // Preconditions |
| 1145 | |
| 1146 | // Set the current sequence id for accepted events |
| 1147 | mFlinger.mutableComposerSequenceId() = currentSequenceId; |
| 1148 | |
| 1149 | // Set the main thread id so that the current thread does not appear to be |
| 1150 | // the main thread. |
| 1151 | mFlinger.mutableMainThreadId() = std::thread::id(); |
| 1152 | |
| 1153 | // -------------------------------------------------------------------- |
| 1154 | // Call Expectations |
| 1155 | |
| 1156 | // We do not expect any calls to invalidate(). |
| 1157 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(0); |
| 1158 | |
| 1159 | // -------------------------------------------------------------------- |
| 1160 | // Invocation |
| 1161 | |
| 1162 | // Call with an unexpected sequence id |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1163 | mFlinger.onHotplugReceived(otherSequenceId, displayId, Connection::INVALID); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 1164 | |
| 1165 | // -------------------------------------------------------------------- |
| 1166 | // Postconditions |
| 1167 | |
| 1168 | // The display transaction needed flag should not be set |
| 1169 | EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 1170 | |
| 1171 | // There should be no pending events |
| 1172 | EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty()); |
| 1173 | } |
| 1174 | |
| 1175 | TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) { |
| 1176 | constexpr int currentSequenceId = 123; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1177 | constexpr HWDisplayId displayId1 = 456; |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 1178 | |
| 1179 | // -------------------------------------------------------------------- |
| 1180 | // Note: |
| 1181 | // -------------------------------------------------------------------- |
| 1182 | // This test case is a bit tricky. We want to verify that |
| 1183 | // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we |
| 1184 | // don't really want to provide coverage for everything the later function |
| 1185 | // does as there are specific tests for it. |
| 1186 | // -------------------------------------------------------------------- |
| 1187 | |
| 1188 | // -------------------------------------------------------------------- |
| 1189 | // Preconditions |
| 1190 | |
| 1191 | // Set the current sequence id for accepted events |
| 1192 | mFlinger.mutableComposerSequenceId() = currentSequenceId; |
| 1193 | |
| 1194 | // Set the main thread id so that the current thread does appear to be the |
| 1195 | // main thread. |
| 1196 | mFlinger.mutableMainThreadId() = std::this_thread::get_id(); |
| 1197 | |
| 1198 | // -------------------------------------------------------------------- |
| 1199 | // Call Expectations |
| 1200 | |
| 1201 | // We expect invalidate() to be invoked once to trigger display transaction |
| 1202 | // processing. |
| 1203 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 1204 | |
| 1205 | // -------------------------------------------------------------------- |
| 1206 | // Invocation |
| 1207 | |
| 1208 | // Simulate a disconnect on a display id that is not connected. This should |
| 1209 | // be enqueued by onHotplugReceived(), and dequeued by |
| 1210 | // processDisplayHotplugEventsLocked(), but then ignored as invalid. |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1211 | mFlinger.onHotplugReceived(currentSequenceId, displayId1, Connection::DISCONNECTED); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 1212 | |
| 1213 | // -------------------------------------------------------------------- |
| 1214 | // Postconditions |
| 1215 | |
| 1216 | // The display transaction needed flag should be set. |
| 1217 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 1218 | |
| 1219 | // There should be no event queued on return, as it should have been |
| 1220 | // processed. |
| 1221 | EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty()); |
| 1222 | } |
| 1223 | |
| 1224 | /* ------------------------------------------------------------------------ |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 1225 | * SurfaceFlinger::createDisplay |
| 1226 | */ |
| 1227 | |
| 1228 | TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) { |
| 1229 | const String8 name("virtual.test"); |
| 1230 | |
| 1231 | // -------------------------------------------------------------------- |
| 1232 | // Call Expectations |
| 1233 | |
| 1234 | // The call should notify the interceptor that a display was created. |
| 1235 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
| 1236 | |
| 1237 | // -------------------------------------------------------------------- |
| 1238 | // Invocation |
| 1239 | |
| 1240 | sp<IBinder> displayToken = mFlinger.createDisplay(name, false); |
| 1241 | |
| 1242 | // -------------------------------------------------------------------- |
| 1243 | // Postconditions |
| 1244 | |
| 1245 | // The display should have been added to the current state |
| 1246 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 1247 | const auto& display = getCurrentDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1248 | EXPECT_TRUE(display.isVirtual()); |
| 1249 | EXPECT_FALSE(display.isSecure); |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 1250 | EXPECT_EQ(name.string(), display.displayName); |
| 1251 | |
| 1252 | // -------------------------------------------------------------------- |
| 1253 | // Cleanup conditions |
| 1254 | |
| 1255 | // Destroying the display invalidates the display state. |
| 1256 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 1257 | } |
| 1258 | |
| 1259 | TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) { |
| 1260 | const String8 name("virtual.test"); |
| 1261 | |
| 1262 | // -------------------------------------------------------------------- |
| 1263 | // Call Expectations |
| 1264 | |
| 1265 | // The call should notify the interceptor that a display was created. |
| 1266 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
| 1267 | |
| 1268 | // -------------------------------------------------------------------- |
| 1269 | // Invocation |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 1270 | int64_t oldId = IPCThreadState::self()->clearCallingIdentity(); |
| 1271 | // Set the calling identity to graphics so captureDisplay with secure is allowed. |
| 1272 | IPCThreadState::self()->restoreCallingIdentity(static_cast<int64_t>(AID_GRAPHICS) << 32 | |
| 1273 | AID_GRAPHICS); |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 1274 | sp<IBinder> displayToken = mFlinger.createDisplay(name, true); |
chaviw | d4a6164 | 2020-09-01 14:53:46 -0700 | [diff] [blame] | 1275 | IPCThreadState::self()->restoreCallingIdentity(oldId); |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 1276 | |
| 1277 | // -------------------------------------------------------------------- |
| 1278 | // Postconditions |
| 1279 | |
| 1280 | // The display should have been added to the current state |
| 1281 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 1282 | const auto& display = getCurrentDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1283 | EXPECT_TRUE(display.isVirtual()); |
| 1284 | EXPECT_TRUE(display.isSecure); |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 1285 | EXPECT_EQ(name.string(), display.displayName); |
| 1286 | |
| 1287 | // -------------------------------------------------------------------- |
| 1288 | // Cleanup conditions |
| 1289 | |
| 1290 | // Destroying the display invalidates the display state. |
| 1291 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 1292 | } |
| 1293 | |
| 1294 | /* ------------------------------------------------------------------------ |
| 1295 | * SurfaceFlinger::destroyDisplay |
| 1296 | */ |
| 1297 | |
| 1298 | TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) { |
| 1299 | using Case = NonHwcVirtualDisplayCase; |
| 1300 | |
| 1301 | // -------------------------------------------------------------------- |
| 1302 | // Preconditions |
| 1303 | |
| 1304 | // A virtual display exists |
| 1305 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1306 | existing.inject(); |
| 1307 | |
| 1308 | // -------------------------------------------------------------------- |
| 1309 | // Call Expectations |
| 1310 | |
| 1311 | // The call should notify the interceptor that a display was created. |
| 1312 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1); |
| 1313 | |
| 1314 | // Destroying the display invalidates the display state. |
| 1315 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 1316 | |
| 1317 | // -------------------------------------------------------------------- |
| 1318 | // Invocation |
| 1319 | |
| 1320 | mFlinger.destroyDisplay(existing.token()); |
| 1321 | |
| 1322 | // -------------------------------------------------------------------- |
| 1323 | // Postconditions |
| 1324 | |
| 1325 | // The display should have been removed from the current state |
| 1326 | EXPECT_FALSE(hasCurrentDisplayState(existing.token())); |
| 1327 | |
| 1328 | // Ths display should still exist in the drawing state |
| 1329 | EXPECT_TRUE(hasDrawingDisplayState(existing.token())); |
| 1330 | |
| 1331 | // The display transaction needed flasg should be set |
| 1332 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 1333 | } |
| 1334 | |
| 1335 | TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) { |
| 1336 | // -------------------------------------------------------------------- |
| 1337 | // Preconditions |
| 1338 | |
| 1339 | sp<BBinder> displayToken = new BBinder(); |
| 1340 | |
| 1341 | // -------------------------------------------------------------------- |
| 1342 | // Invocation |
| 1343 | |
| 1344 | mFlinger.destroyDisplay(displayToken); |
| 1345 | } |
| 1346 | |
| 1347 | /* ------------------------------------------------------------------------ |
Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 1348 | * SurfaceFlinger::notifyPowerBoost |
| 1349 | */ |
| 1350 | |
| 1351 | TEST_F(DisplayTransactionTest, notifyPowerBoostNotifiesTouchEvent) { |
| 1352 | mFlinger.scheduler()->replaceTouchTimer(100); |
| 1353 | std::this_thread::sleep_for(10ms); // wait for callback to be triggered |
| 1354 | EXPECT_TRUE(mFlinger.scheduler()->isTouchActive()); // Starting timer activates touch |
| 1355 | |
| 1356 | std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback |
| 1357 | EXPECT_FALSE(mFlinger.scheduler()->isTouchActive()); |
| 1358 | |
| 1359 | EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::CAMERA_SHOT))); |
| 1360 | std::this_thread::sleep_for(10ms); // wait for callback to maybe be triggered |
| 1361 | EXPECT_FALSE(mFlinger.scheduler()->isTouchActive()); |
| 1362 | |
| 1363 | std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback |
| 1364 | EXPECT_FALSE(mFlinger.scheduler()->isTouchActive()); |
| 1365 | |
| 1366 | EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::INTERACTION))); |
| 1367 | std::this_thread::sleep_for(10ms); // wait for callback to be triggered. |
| 1368 | EXPECT_TRUE(mFlinger.scheduler()->isTouchActive()); |
| 1369 | } |
| 1370 | |
| 1371 | /* ------------------------------------------------------------------------ |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1372 | * DisplayDevice::GetBestColorMode |
| 1373 | */ |
| 1374 | class GetBestColorModeTest : public DisplayTransactionTest { |
| 1375 | public: |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1376 | void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; } |
| 1377 | |
| 1378 | void addHwcColorModesMapping(ui::ColorMode colorMode, |
| 1379 | std::vector<ui::RenderIntent> renderIntents) { |
| 1380 | mHwcColorModes[colorMode] = renderIntents; |
| 1381 | } |
| 1382 | |
| 1383 | void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; } |
| 1384 | |
| 1385 | void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; } |
| 1386 | |
| 1387 | void getBestColorMode() { |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 1388 | auto displayDevice = |
| 1389 | injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) { |
| 1390 | injector.setHwcColorModes(mHwcColorModes); |
| 1391 | injector.setHasWideColorGamut(mHasWideColorGamut); |
| 1392 | injector.setNativeWindow(mNativeWindow); |
| 1393 | }); |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1394 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 1395 | displayDevice->getCompositionDisplay() |
| 1396 | ->getDisplayColorProfile() |
| 1397 | ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace, |
| 1398 | &mOutColorMode, &mOutRenderIntent); |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | ui::Dataspace mOutDataspace; |
| 1402 | ui::ColorMode mOutColorMode; |
| 1403 | ui::RenderIntent mOutRenderIntent; |
| 1404 | |
| 1405 | private: |
| 1406 | ui::Dataspace mInputDataspace; |
| 1407 | ui::RenderIntent mInputRenderIntent; |
| 1408 | bool mHasWideColorGamut = false; |
| 1409 | std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes; |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1410 | }; |
| 1411 | |
| 1412 | TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) { |
| 1413 | addHwcColorModesMapping(ui::ColorMode::SRGB, |
| 1414 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1415 | setInputDataspace(ui::Dataspace::DISPLAY_P3); |
| 1416 | setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); |
| 1417 | setHasWideColorGamut(true); |
| 1418 | |
| 1419 | getBestColorMode(); |
| 1420 | |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 1421 | ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace); |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1422 | ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode); |
| 1423 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); |
| 1424 | } |
| 1425 | |
| 1426 | TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) { |
| 1427 | addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3, |
| 1428 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1429 | addHwcColorModesMapping(ui::ColorMode::SRGB, |
| 1430 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1431 | addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020, |
| 1432 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1433 | setInputDataspace(ui::Dataspace::DISPLAY_P3); |
| 1434 | setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); |
| 1435 | setHasWideColorGamut(true); |
| 1436 | |
| 1437 | getBestColorMode(); |
| 1438 | |
| 1439 | ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace); |
| 1440 | ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode); |
| 1441 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); |
| 1442 | } |
| 1443 | |
| 1444 | TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) { |
| 1445 | addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020, |
| 1446 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1447 | setInputDataspace(ui::Dataspace::DISPLAY_P3); |
| 1448 | setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); |
| 1449 | setHasWideColorGamut(true); |
| 1450 | |
| 1451 | getBestColorMode(); |
| 1452 | |
| 1453 | ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace); |
| 1454 | ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode); |
| 1455 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); |
| 1456 | } |
| 1457 | |
| 1458 | /* ------------------------------------------------------------------------ |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1459 | * DisplayDevice::setProjection |
| 1460 | */ |
| 1461 | |
| 1462 | class DisplayDeviceSetProjectionTest : public DisplayTransactionTest { |
| 1463 | public: |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1464 | static constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1080; // arbitrary |
| 1465 | static constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1920; // arbitrary |
| 1466 | |
| 1467 | static constexpr int32_t TRANSFORM_FLAGS_ROT_0 = 0; |
| 1468 | static constexpr int32_t TRANSFORM_FLAGS_ROT_90 = HAL_TRANSFORM_ROT_90; |
| 1469 | static constexpr int32_t TRANSFORM_FLAGS_ROT_180 = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V; |
| 1470 | static constexpr int32_t TRANSFORM_FLAGS_ROT_270 = |
| 1471 | HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90; |
| 1472 | |
| 1473 | DisplayDeviceSetProjectionTest(ui::Size flingerDisplaySize, ui::Size hardwareDisplaySize, |
| 1474 | ui::Rotation physicalOrientation) |
| 1475 | : mFlingerDisplaySize(flingerDisplaySize), |
| 1476 | mHardwareDisplaySize(hardwareDisplaySize), |
| 1477 | mPhysicalOrientation(physicalOrientation), |
| 1478 | mDisplayDevice(createDisplayDevice()) {} |
| 1479 | |
| 1480 | sp<DisplayDevice> createDisplayDevice() { |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 1481 | return injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) { |
| 1482 | injector.setPhysicalOrientation(mPhysicalOrientation); |
| 1483 | }); |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 1486 | ui::Size swapWH(const ui::Size size) const { return ui::Size(size.height, size.width); } |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1487 | |
| 1488 | void setProjectionForRotation0() { |
| 1489 | // A logical rotation of 0 uses the SurfaceFlinger display size |
| 1490 | mDisplayDevice->setProjection(ui::ROTATION_0, Rect(mFlingerDisplaySize), |
| 1491 | Rect(mFlingerDisplaySize)); |
| 1492 | } |
| 1493 | |
| 1494 | void setProjectionForRotation90() { |
| 1495 | // A logical rotation of 90 uses the SurfaceFlinger display size with |
| 1496 | // the width/height swapped. |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 1497 | mDisplayDevice->setProjection(ui::ROTATION_90, Rect(swapWH(mFlingerDisplaySize)), |
| 1498 | Rect(swapWH(mFlingerDisplaySize))); |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | void setProjectionForRotation180() { |
| 1502 | // A logical rotation of 180 uses the SurfaceFlinger display size |
| 1503 | mDisplayDevice->setProjection(ui::ROTATION_180, Rect(mFlingerDisplaySize), |
| 1504 | Rect(mFlingerDisplaySize)); |
| 1505 | } |
| 1506 | |
| 1507 | void setProjectionForRotation270() { |
| 1508 | // A logical rotation of 270 uses the SurfaceFlinger display size with |
| 1509 | // the width/height swapped. |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 1510 | mDisplayDevice->setProjection(ui::ROTATION_270, Rect(swapWH(mFlingerDisplaySize)), |
| 1511 | Rect(swapWH(mFlingerDisplaySize))); |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | void expectStateForHardwareTransform0() { |
| 1515 | const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState(); |
| 1516 | EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_0, mHardwareDisplaySize.width, |
| 1517 | mHardwareDisplaySize.height), |
| 1518 | compositionState.transform); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 1519 | EXPECT_EQ(ui::ROTATION_0, compositionState.displaySpace.orientation); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1520 | EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content); |
| 1521 | EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.orientedDisplaySpace.content); |
| 1522 | EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.layerStackSpace.content); |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1523 | EXPECT_EQ(false, compositionState.needsFiltering); |
| 1524 | } |
| 1525 | |
| 1526 | void expectStateForHardwareTransform90() { |
| 1527 | const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState(); |
| 1528 | EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width, |
| 1529 | mHardwareDisplaySize.height), |
| 1530 | compositionState.transform); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 1531 | EXPECT_EQ(ui::ROTATION_90, compositionState.displaySpace.orientation); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1532 | EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content); |
| 1533 | // For 90, the orientedDisplaySpaceRect and layerStackSpaceRect have the hardware display |
| 1534 | // size width and height swapped |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 1535 | EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)), |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1536 | compositionState.orientedDisplaySpace.content); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 1537 | EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)), compositionState.layerStackSpace.content); |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1538 | EXPECT_EQ(false, compositionState.needsFiltering); |
| 1539 | } |
| 1540 | |
| 1541 | void expectStateForHardwareTransform180() { |
| 1542 | const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState(); |
| 1543 | EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width, |
| 1544 | mHardwareDisplaySize.height), |
| 1545 | compositionState.transform); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 1546 | EXPECT_EQ(ui::ROTATION_180, compositionState.displaySpace.orientation); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1547 | EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.orientedDisplaySpace.content); |
| 1548 | EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.layerStackSpace.content); |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1549 | EXPECT_EQ(false, compositionState.needsFiltering); |
| 1550 | } |
| 1551 | |
| 1552 | void expectStateForHardwareTransform270() { |
| 1553 | const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState(); |
| 1554 | EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width, |
| 1555 | mHardwareDisplaySize.height), |
| 1556 | compositionState.transform); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 1557 | EXPECT_EQ(ui::ROTATION_270, compositionState.displaySpace.orientation); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1558 | EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content); |
| 1559 | // For 270, the orientedDisplaySpaceRect and layerStackSpaceRect have the hardware display |
| 1560 | // size width and height swapped |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 1561 | EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)), |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1562 | compositionState.orientedDisplaySpace.content); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 1563 | EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)), compositionState.layerStackSpace.content); |
Lloyd Pique | 3305047 | 2019-12-19 17:12:44 -0800 | [diff] [blame] | 1564 | EXPECT_EQ(false, compositionState.needsFiltering); |
| 1565 | } |
| 1566 | |
| 1567 | const ui::Size mFlingerDisplaySize; |
| 1568 | const ui::Size mHardwareDisplaySize; |
| 1569 | const ui::Rotation mPhysicalOrientation; |
| 1570 | const sp<DisplayDevice> mDisplayDevice; |
| 1571 | }; |
| 1572 | |
| 1573 | struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest { |
| 1574 | DisplayDeviceSetProjectionTest_Installed0() |
| 1575 | : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 1576 | ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 1577 | ui::ROTATION_0) {} |
| 1578 | }; |
| 1579 | |
| 1580 | TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) { |
| 1581 | setProjectionForRotation0(); |
| 1582 | expectStateForHardwareTransform0(); |
| 1583 | } |
| 1584 | |
| 1585 | TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) { |
| 1586 | setProjectionForRotation90(); |
| 1587 | expectStateForHardwareTransform90(); |
| 1588 | } |
| 1589 | |
| 1590 | TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) { |
| 1591 | setProjectionForRotation180(); |
| 1592 | expectStateForHardwareTransform180(); |
| 1593 | } |
| 1594 | |
| 1595 | TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) { |
| 1596 | setProjectionForRotation270(); |
| 1597 | expectStateForHardwareTransform270(); |
| 1598 | } |
| 1599 | |
| 1600 | struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest { |
| 1601 | DisplayDeviceSetProjectionTest_Installed90() |
| 1602 | : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH), |
| 1603 | ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 1604 | ui::ROTATION_90) {} |
| 1605 | }; |
| 1606 | |
| 1607 | TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) { |
| 1608 | setProjectionForRotation0(); |
| 1609 | expectStateForHardwareTransform90(); |
| 1610 | } |
| 1611 | |
| 1612 | TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) { |
| 1613 | setProjectionForRotation90(); |
| 1614 | expectStateForHardwareTransform180(); |
| 1615 | } |
| 1616 | |
| 1617 | TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) { |
| 1618 | setProjectionForRotation180(); |
| 1619 | expectStateForHardwareTransform270(); |
| 1620 | } |
| 1621 | |
| 1622 | TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) { |
| 1623 | setProjectionForRotation270(); |
| 1624 | expectStateForHardwareTransform0(); |
| 1625 | } |
| 1626 | |
| 1627 | struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest { |
| 1628 | DisplayDeviceSetProjectionTest_Installed180() |
| 1629 | : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 1630 | ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 1631 | ui::ROTATION_180) {} |
| 1632 | }; |
| 1633 | |
| 1634 | TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) { |
| 1635 | setProjectionForRotation0(); |
| 1636 | expectStateForHardwareTransform180(); |
| 1637 | } |
| 1638 | |
| 1639 | TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) { |
| 1640 | setProjectionForRotation90(); |
| 1641 | expectStateForHardwareTransform270(); |
| 1642 | } |
| 1643 | |
| 1644 | TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) { |
| 1645 | setProjectionForRotation180(); |
| 1646 | expectStateForHardwareTransform0(); |
| 1647 | } |
| 1648 | |
| 1649 | TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) { |
| 1650 | setProjectionForRotation270(); |
| 1651 | expectStateForHardwareTransform90(); |
| 1652 | } |
| 1653 | |
| 1654 | struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest { |
| 1655 | DisplayDeviceSetProjectionTest_Installed270() |
| 1656 | : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH), |
| 1657 | ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 1658 | ui::ROTATION_270) {} |
| 1659 | }; |
| 1660 | |
| 1661 | TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) { |
| 1662 | setProjectionForRotation0(); |
| 1663 | expectStateForHardwareTransform270(); |
| 1664 | } |
| 1665 | |
| 1666 | TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) { |
| 1667 | setProjectionForRotation90(); |
| 1668 | expectStateForHardwareTransform0(); |
| 1669 | } |
| 1670 | |
| 1671 | TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) { |
| 1672 | setProjectionForRotation180(); |
| 1673 | expectStateForHardwareTransform90(); |
| 1674 | } |
| 1675 | |
| 1676 | TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) { |
| 1677 | setProjectionForRotation270(); |
| 1678 | expectStateForHardwareTransform180(); |
| 1679 | } |
| 1680 | |
| 1681 | /* ------------------------------------------------------------------------ |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1682 | * SurfaceFlinger::getDisplayNativePrimaries |
| 1683 | */ |
| 1684 | |
| 1685 | class GetDisplayNativePrimaries : public DisplayTransactionTest { |
| 1686 | public: |
| 1687 | GetDisplayNativePrimaries(); |
| 1688 | void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries); |
| 1689 | void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries); |
| 1690 | |
| 1691 | private: |
| 1692 | static constexpr float mStartingTestValue = 1.0f; |
| 1693 | }; |
| 1694 | |
| 1695 | GetDisplayNativePrimaries::GetDisplayNativePrimaries() { |
| 1696 | SimplePrimaryDisplayCase::Display::injectHwcDisplay(this); |
| 1697 | injectFakeNativeWindowSurfaceFactory(); |
| 1698 | } |
| 1699 | |
| 1700 | void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries( |
| 1701 | ui::DisplayPrimaries& primaries) { |
| 1702 | float startingVal = mStartingTestValue; |
| 1703 | primaries.red.X = startingVal++; |
| 1704 | primaries.red.Y = startingVal++; |
| 1705 | primaries.red.Z = startingVal++; |
| 1706 | primaries.green.X = startingVal++; |
| 1707 | primaries.green.Y = startingVal++; |
| 1708 | primaries.green.Z = startingVal++; |
| 1709 | primaries.blue.X = startingVal++; |
| 1710 | primaries.blue.Y = startingVal++; |
| 1711 | primaries.blue.Z = startingVal++; |
| 1712 | primaries.white.X = startingVal++; |
| 1713 | primaries.white.Y = startingVal++; |
| 1714 | primaries.white.Z = startingVal++; |
| 1715 | } |
| 1716 | |
| 1717 | void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries( |
| 1718 | const ui::DisplayPrimaries& primaries) { |
| 1719 | float startingVal = mStartingTestValue; |
| 1720 | EXPECT_EQ(primaries.red.X, startingVal++); |
| 1721 | EXPECT_EQ(primaries.red.Y, startingVal++); |
| 1722 | EXPECT_EQ(primaries.red.Z, startingVal++); |
| 1723 | EXPECT_EQ(primaries.green.X, startingVal++); |
| 1724 | EXPECT_EQ(primaries.green.Y, startingVal++); |
| 1725 | EXPECT_EQ(primaries.green.Z, startingVal++); |
| 1726 | EXPECT_EQ(primaries.blue.X, startingVal++); |
| 1727 | EXPECT_EQ(primaries.blue.Y, startingVal++); |
| 1728 | EXPECT_EQ(primaries.blue.Z, startingVal++); |
| 1729 | EXPECT_EQ(primaries.white.X, startingVal++); |
| 1730 | EXPECT_EQ(primaries.white.Y, startingVal++); |
| 1731 | EXPECT_EQ(primaries.white.Z, startingVal++); |
| 1732 | } |
| 1733 | |
| 1734 | TEST_F(GetDisplayNativePrimaries, nullDisplayToken) { |
| 1735 | ui::DisplayPrimaries primaries; |
| 1736 | EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries)); |
| 1737 | } |
| 1738 | |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1739 | TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) { |
| 1740 | auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this); |
| 1741 | injector.inject(); |
| 1742 | auto internalDisplayToken = injector.token(); |
| 1743 | |
| 1744 | ui::DisplayPrimaries expectedPrimaries; |
| 1745 | populateDummyDisplayNativePrimaries(expectedPrimaries); |
| 1746 | mFlinger.setInternalDisplayPrimaries(expectedPrimaries); |
| 1747 | |
| 1748 | ui::DisplayPrimaries primaries; |
| 1749 | EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries)); |
| 1750 | |
| 1751 | checkDummyDisplayNativePrimaries(primaries); |
| 1752 | } |
| 1753 | |
| 1754 | TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) { |
| 1755 | sp<BBinder> notInternalDisplayToken = new BBinder(); |
| 1756 | |
| 1757 | ui::DisplayPrimaries primaries; |
| 1758 | populateDummyDisplayNativePrimaries(primaries); |
Dominik Laskowski | 470df5f | 2020-04-02 22:27:42 -0700 | [diff] [blame] | 1759 | EXPECT_EQ(NAME_NOT_FOUND, |
| 1760 | mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries)); |
Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 1761 | |
| 1762 | // Check primaries argument wasn't modified in case of failure |
| 1763 | checkDummyDisplayNativePrimaries(primaries); |
| 1764 | } |
| 1765 | |
| 1766 | /* ------------------------------------------------------------------------ |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1767 | * SurfaceFlinger::setupNewDisplayDeviceInternal |
| 1768 | */ |
| 1769 | |
| 1770 | class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest { |
| 1771 | public: |
| 1772 | template <typename T> |
| 1773 | void setupNewDisplayDeviceInternalTest(); |
| 1774 | }; |
| 1775 | |
| 1776 | template <typename Case> |
| 1777 | void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() { |
| 1778 | const sp<BBinder> displayToken = new BBinder(); |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 1779 | const sp<compositionengine::mock::DisplaySurface> displaySurface = |
| 1780 | new compositionengine::mock::DisplaySurface(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1781 | const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1782 | |
| 1783 | // -------------------------------------------------------------------- |
| 1784 | // Preconditions |
| 1785 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1786 | // Wide color displays support is configured appropriately |
| 1787 | Case::WideColorSupport::injectConfigChange(this); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1788 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1789 | // The display is setup with the HWC. |
| 1790 | Case::Display::injectHwcDisplay(this); |
| 1791 | |
| 1792 | // SurfaceFlinger will use a test-controlled factory for native window |
| 1793 | // surfaces. |
| 1794 | injectFakeNativeWindowSurfaceFactory(); |
| 1795 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 1796 | // A compositionengine::Display has already been created |
| 1797 | auto compositionDisplay = Case::Display::injectCompositionDisplay(this); |
| 1798 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1799 | // -------------------------------------------------------------------- |
| 1800 | // Call Expectations |
| 1801 | |
| 1802 | // Various native window calls will be made. |
| 1803 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 1804 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1805 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 1806 | Case::HdrSupport::setupComposerCallExpectations(this); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1807 | Case::PerFrameMetadataSupport::setupComposerCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1808 | |
| 1809 | // -------------------------------------------------------------------- |
| 1810 | // Invocation |
| 1811 | |
| 1812 | DisplayDeviceState state; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1813 | if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 1814 | const auto displayId = PhysicalDisplayId::tryCast(Case::Display::DISPLAY_ID::get()); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1815 | ASSERT_TRUE(displayId); |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 1816 | const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value; |
| 1817 | ASSERT_TRUE(hwcDisplayId); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 1818 | state.physical = {.id = *displayId, .type = *connectionType, .hwcDisplayId = *hwcDisplayId}; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1819 | } |
| 1820 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1821 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
| 1822 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 1823 | auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state, |
| 1824 | displaySurface, producer); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1825 | |
| 1826 | // -------------------------------------------------------------------- |
| 1827 | // Postconditions |
| 1828 | |
| 1829 | ASSERT_TRUE(device != nullptr); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1830 | EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId()); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1831 | EXPECT_EQ(Case::Display::CONNECTION_TYPE::value, device->getConnectionType()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1832 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1833 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1834 | EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1835 | EXPECT_EQ(Case::Display::WIDTH, device->getWidth()); |
| 1836 | EXPECT_EQ(Case::Display::HEIGHT, device->getHeight()); |
| 1837 | EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut()); |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 1838 | EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1839 | EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support()); |
| 1840 | EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport()); |
| 1841 | EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 1842 | // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are |
| 1843 | // remapped, and the test only ever sets up one config. If there were an error |
| 1844 | // looking up the remapped index, device->getActiveConfig() would be -1 instead. |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 1845 | EXPECT_EQ(0, device->getActiveConfig().value()); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1846 | EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS, |
| 1847 | device->getSupportedPerFrameMetadata()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) { |
| 1851 | setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>(); |
| 1852 | } |
| 1853 | |
| 1854 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) { |
| 1855 | setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>(); |
| 1856 | } |
| 1857 | |
| 1858 | TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) { |
| 1859 | setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>(); |
| 1860 | } |
| 1861 | |
| 1862 | TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) { |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 1863 | setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) { |
| 1867 | setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>(); |
| 1868 | } |
| 1869 | |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 1870 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) { |
| 1871 | setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>(); |
| 1872 | } |
| 1873 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1874 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) { |
| 1875 | setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>(); |
| 1876 | } |
| 1877 | |
| 1878 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) { |
| 1879 | setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>(); |
| 1880 | } |
| 1881 | |
| 1882 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) { |
| 1883 | setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>(); |
| 1884 | } |
| 1885 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1886 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) { |
| 1887 | setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>(); |
| 1888 | } |
| 1889 | |
| 1890 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) { |
| 1891 | setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>(); |
| 1892 | } |
| 1893 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1894 | /* ------------------------------------------------------------------------ |
| 1895 | * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded) |
| 1896 | */ |
| 1897 | |
| 1898 | class HandleTransactionLockedTest : public DisplayTransactionTest { |
| 1899 | public: |
| 1900 | template <typename Case> |
| 1901 | void setupCommonPreconditions(); |
| 1902 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 1903 | template <typename Case, bool connected> |
| 1904 | static void expectHotplugReceived(mock::EventThread*); |
| 1905 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1906 | template <typename Case> |
| 1907 | void setupCommonCallExpectationsForConnectProcessing(); |
| 1908 | |
| 1909 | template <typename Case> |
| 1910 | void setupCommonCallExpectationsForDisconnectProcessing(); |
| 1911 | |
| 1912 | template <typename Case> |
| 1913 | void processesHotplugConnectCommon(); |
| 1914 | |
| 1915 | template <typename Case> |
| 1916 | void ignoresHotplugConnectCommon(); |
| 1917 | |
| 1918 | template <typename Case> |
| 1919 | void processesHotplugDisconnectCommon(); |
| 1920 | |
| 1921 | template <typename Case> |
| 1922 | void verifyDisplayIsConnected(const sp<IBinder>& displayToken); |
| 1923 | |
| 1924 | template <typename Case> |
| 1925 | void verifyPhysicalDisplayIsConnected(); |
| 1926 | |
| 1927 | void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken); |
| 1928 | }; |
| 1929 | |
| 1930 | template <typename Case> |
| 1931 | void HandleTransactionLockedTest::setupCommonPreconditions() { |
| 1932 | // Wide color displays support is configured appropriately |
| 1933 | Case::WideColorSupport::injectConfigChange(this); |
| 1934 | |
| 1935 | // SurfaceFlinger will use a test-controlled factory for BufferQueues |
| 1936 | injectFakeBufferQueueFactory(); |
| 1937 | |
| 1938 | // SurfaceFlinger will use a test-controlled factory for native window |
| 1939 | // surfaces. |
| 1940 | injectFakeNativeWindowSurfaceFactory(); |
| 1941 | } |
| 1942 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 1943 | template <typename Case, bool connected> |
| 1944 | void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) { |
| 1945 | const auto convert = [](auto physicalDisplayId) { |
| 1946 | return std::make_optional(DisplayId{physicalDisplayId}); |
| 1947 | }; |
| 1948 | |
| 1949 | EXPECT_CALL(*eventThread, |
| 1950 | onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected)) |
| 1951 | .Times(1); |
| 1952 | } |
| 1953 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1954 | template <typename Case> |
| 1955 | void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() { |
| 1956 | Case::Display::setupHwcHotplugCallExpectations(this); |
| 1957 | |
| 1958 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); |
| 1959 | Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this); |
| 1960 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
| 1961 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
| 1962 | |
| 1963 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 1964 | Case::HdrSupport::setupComposerCallExpectations(this); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1965 | Case::PerFrameMetadataSupport::setupComposerCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1966 | |
| 1967 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 1968 | expectHotplugReceived<Case, true>(mEventThread); |
| 1969 | expectHotplugReceived<Case, true>(mSFEventThread); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | template <typename Case> |
| 1973 | void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() { |
| 1974 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1); |
Dominik Laskowski | 1eba020 | 2019-01-24 09:14:40 -0800 | [diff] [blame] | 1975 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 1976 | expectHotplugReceived<Case, false>(mEventThread); |
| 1977 | expectHotplugReceived<Case, false>(mSFEventThread); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | template <typename Case> |
| 1981 | void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) { |
| 1982 | // The display device should have been set up in the list of displays. |
| 1983 | ASSERT_TRUE(hasDisplayDevice(displayToken)); |
| 1984 | const auto& device = getDisplayDevice(displayToken); |
| 1985 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 1986 | EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1987 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1988 | std::optional<DisplayDeviceState::Physical> expectedPhysical; |
| 1989 | if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) { |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 1990 | const auto displayId = PhysicalDisplayId::tryCast(Case::Display::DISPLAY_ID::get()); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1991 | ASSERT_TRUE(displayId); |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 1992 | const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value; |
| 1993 | ASSERT_TRUE(hwcDisplayId); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 1994 | expectedPhysical = {.id = *displayId, |
Marin Shalamanov | 7ce8764 | 2020-05-06 13:45:58 +0200 | [diff] [blame] | 1995 | .type = *connectionType, |
| 1996 | .hwcDisplayId = *hwcDisplayId}; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 1997 | } |
| 1998 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1999 | // The display should have been set up in the current display state |
| 2000 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 2001 | const auto& current = getCurrentDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2002 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual()); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 2003 | EXPECT_EQ(expectedPhysical, current.physical); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2004 | |
| 2005 | // The display should have been set up in the drawing display state |
| 2006 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); |
| 2007 | const auto& draw = getDrawingDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2008 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual()); |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 2009 | EXPECT_EQ(expectedPhysical, draw.physical); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | template <typename Case> |
| 2013 | void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() { |
| 2014 | // HWComposer should have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2015 | EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2016 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2017 | // SF should have a display token. |
| 2018 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2019 | ASSERT_TRUE(PhysicalDisplayId::tryCast(displayId)); |
| 2020 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(displayId) == 1); |
| 2021 | auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[displayId]; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2022 | |
| 2023 | verifyDisplayIsConnected<Case>(displayToken); |
| 2024 | } |
| 2025 | |
| 2026 | void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) { |
| 2027 | EXPECT_FALSE(hasDisplayDevice(displayToken)); |
| 2028 | EXPECT_FALSE(hasCurrentDisplayState(displayToken)); |
| 2029 | EXPECT_FALSE(hasDrawingDisplayState(displayToken)); |
| 2030 | } |
| 2031 | |
| 2032 | template <typename Case> |
| 2033 | void HandleTransactionLockedTest::processesHotplugConnectCommon() { |
| 2034 | // -------------------------------------------------------------------- |
| 2035 | // Preconditions |
| 2036 | |
| 2037 | setupCommonPreconditions<Case>(); |
| 2038 | |
| 2039 | // A hotplug connect event is enqueued for a display |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 2040 | Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 2041 | |
| 2042 | // -------------------------------------------------------------------- |
| 2043 | // Call Expectations |
| 2044 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2045 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 2046 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 2047 | // -------------------------------------------------------------------- |
| 2048 | // Invocation |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 2049 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 2050 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 2051 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 2052 | // -------------------------------------------------------------------- |
| 2053 | // Postconditions |
| 2054 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2055 | verifyPhysicalDisplayIsConnected<Case>(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 2056 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 2057 | // -------------------------------------------------------------------- |
| 2058 | // Cleanup conditions |
| 2059 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2060 | EXPECT_CALL(*mComposer, |
| 2061 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 2062 | .WillOnce(Return(Error::NONE)); |
| 2063 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 2064 | } |
| 2065 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2066 | template <typename Case> |
| 2067 | void HandleTransactionLockedTest::ignoresHotplugConnectCommon() { |
| 2068 | // -------------------------------------------------------------------- |
| 2069 | // Preconditions |
| 2070 | |
| 2071 | setupCommonPreconditions<Case>(); |
| 2072 | |
| 2073 | // A hotplug connect event is enqueued for a display |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 2074 | Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2075 | |
| 2076 | // -------------------------------------------------------------------- |
| 2077 | // Invocation |
| 2078 | |
| 2079 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2080 | |
| 2081 | // -------------------------------------------------------------------- |
| 2082 | // Postconditions |
| 2083 | |
| 2084 | // HWComposer should not have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2085 | EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | template <typename Case> |
| 2089 | void HandleTransactionLockedTest::processesHotplugDisconnectCommon() { |
| 2090 | // -------------------------------------------------------------------- |
| 2091 | // Preconditions |
| 2092 | |
| 2093 | setupCommonPreconditions<Case>(); |
| 2094 | |
| 2095 | // A hotplug disconnect event is enqueued for a display |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 2096 | Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2097 | |
| 2098 | // The display is already completely set up. |
| 2099 | Case::Display::injectHwcDisplay(this); |
| 2100 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2101 | existing.inject(); |
| 2102 | |
| 2103 | // -------------------------------------------------------------------- |
| 2104 | // Call Expectations |
| 2105 | |
Lloyd Pique | 438e9e7 | 2018-09-04 18:06:08 -0700 | [diff] [blame] | 2106 | EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _)) |
| 2107 | .Times(0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2108 | |
| 2109 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 2110 | |
| 2111 | // -------------------------------------------------------------------- |
| 2112 | // Invocation |
| 2113 | |
| 2114 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2115 | |
| 2116 | // -------------------------------------------------------------------- |
| 2117 | // Postconditions |
| 2118 | |
| 2119 | // HWComposer should not have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2120 | EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2121 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2122 | // SF should not have a display token. |
| 2123 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2124 | ASSERT_TRUE(PhysicalDisplayId::tryCast(displayId)); |
| 2125 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(displayId) == 0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2126 | |
| 2127 | // The existing token should have been removed |
| 2128 | verifyDisplayIsNotConnected(existing.token()); |
| 2129 | } |
| 2130 | |
| 2131 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) { |
| 2132 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); |
| 2133 | } |
| 2134 | |
| 2135 | TEST_F(HandleTransactionLockedTest, |
| 2136 | processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) { |
| 2137 | // Inject an external display. |
| 2138 | ExternalDisplayVariant::injectHwcDisplay(this); |
| 2139 | |
| 2140 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); |
| 2141 | } |
| 2142 | |
| 2143 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) { |
| 2144 | // Inject a primary display. |
| 2145 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 2146 | |
| 2147 | processesHotplugConnectCommon<SimpleExternalDisplayCase>(); |
| 2148 | } |
| 2149 | |
| 2150 | TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) { |
| 2151 | // Inject both a primary and external display. |
| 2152 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 2153 | ExternalDisplayVariant::injectHwcDisplay(this); |
| 2154 | |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 2155 | // TODO: This is an unnecessary call. |
| 2156 | EXPECT_CALL(*mComposer, |
| 2157 | getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _)) |
| 2158 | .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT), |
| 2159 | SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()), |
| 2160 | Return(Error::NONE))); |
| 2161 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2162 | ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>(); |
| 2163 | } |
| 2164 | |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 2165 | TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectPrimaryDisplay) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2166 | processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>(); |
| 2167 | } |
| 2168 | |
Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 2169 | TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectExternalDisplay) { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2170 | processesHotplugDisconnectCommon<SimpleExternalDisplayCase>(); |
| 2171 | } |
| 2172 | |
| 2173 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) { |
| 2174 | using Case = SimplePrimaryDisplayCase; |
| 2175 | |
| 2176 | // -------------------------------------------------------------------- |
| 2177 | // Preconditions |
| 2178 | |
| 2179 | setupCommonPreconditions<Case>(); |
| 2180 | |
| 2181 | // A hotplug connect event is enqueued for a display |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 2182 | Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2183 | // A hotplug disconnect event is also enqueued for the same display |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 2184 | Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2185 | |
| 2186 | // -------------------------------------------------------------------- |
| 2187 | // Call Expectations |
| 2188 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2189 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
| 2190 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 2191 | |
| 2192 | EXPECT_CALL(*mComposer, |
| 2193 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
| 2194 | .WillOnce(Return(Error::NONE)); |
| 2195 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 2196 | |
| 2197 | // -------------------------------------------------------------------- |
| 2198 | // Invocation |
| 2199 | |
| 2200 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2201 | |
| 2202 | // -------------------------------------------------------------------- |
| 2203 | // Postconditions |
| 2204 | |
| 2205 | // HWComposer should not have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2206 | EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2207 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2208 | // SF should not have a display token. |
| 2209 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2210 | ASSERT_TRUE(PhysicalDisplayId::tryCast(displayId)); |
| 2211 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(displayId) == 0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) { |
| 2215 | using Case = SimplePrimaryDisplayCase; |
| 2216 | |
| 2217 | // -------------------------------------------------------------------- |
| 2218 | // Preconditions |
| 2219 | |
| 2220 | setupCommonPreconditions<Case>(); |
| 2221 | |
| 2222 | // The display is already completely set up. |
| 2223 | Case::Display::injectHwcDisplay(this); |
| 2224 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2225 | existing.inject(); |
| 2226 | |
| 2227 | // A hotplug disconnect event is enqueued for a display |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 2228 | Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2229 | // A hotplug connect event is also enqueued for the same display |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 2230 | Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2231 | |
| 2232 | // -------------------------------------------------------------------- |
| 2233 | // Call Expectations |
| 2234 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2235 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
| 2236 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 2237 | |
| 2238 | // -------------------------------------------------------------------- |
| 2239 | // Invocation |
| 2240 | |
| 2241 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2242 | |
| 2243 | // -------------------------------------------------------------------- |
| 2244 | // Postconditions |
| 2245 | |
| 2246 | // The existing token should have been removed |
| 2247 | verifyDisplayIsNotConnected(existing.token()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2248 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2249 | ASSERT_TRUE(PhysicalDisplayId::tryCast(displayId)); |
| 2250 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(displayId) == 1); |
| 2251 | EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[displayId]); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2252 | |
| 2253 | // A new display should be connected in its place |
| 2254 | |
| 2255 | verifyPhysicalDisplayIsConnected<Case>(); |
| 2256 | |
| 2257 | // -------------------------------------------------------------------- |
| 2258 | // Cleanup conditions |
| 2259 | |
| 2260 | EXPECT_CALL(*mComposer, |
| 2261 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
| 2262 | .WillOnce(Return(Error::NONE)); |
| 2263 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 2264 | } |
| 2265 | |
| 2266 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) { |
| 2267 | using Case = HwcVirtualDisplayCase; |
| 2268 | |
| 2269 | // -------------------------------------------------------------------- |
| 2270 | // Preconditions |
| 2271 | |
| 2272 | // The HWC supports at least one virtual display |
| 2273 | injectMockComposer(1); |
| 2274 | |
| 2275 | setupCommonPreconditions<Case>(); |
| 2276 | |
| 2277 | // A virtual display was added to the current state, and it has a |
| 2278 | // surface(producer) |
| 2279 | sp<BBinder> displayToken = new BBinder(); |
Lloyd Pique | 4c2ac02 | 2018-04-27 12:08:03 -0700 | [diff] [blame] | 2280 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2281 | DisplayDeviceState state; |
| 2282 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2283 | |
| 2284 | sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2285 | state.surface = surface; |
| 2286 | mFlinger.mutableCurrentState().displays.add(displayToken, state); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2287 | |
| 2288 | // -------------------------------------------------------------------- |
| 2289 | // Call Expectations |
| 2290 | |
| 2291 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); |
| 2292 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
| 2293 | |
| 2294 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _)) |
| 2295 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR))); |
| 2296 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _)) |
| 2297 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR))); |
| 2298 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _)) |
| 2299 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT), |
| 2300 | Return(NO_ERROR))); |
| 2301 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _)) |
| 2302 | .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR))); |
| 2303 | |
| 2304 | EXPECT_CALL(*surface, setAsyncMode(true)).Times(1); |
| 2305 | |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 2306 | EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2307 | EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1); |
| 2308 | |
| 2309 | Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this); |
| 2310 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 2311 | Case::HdrSupport::setupComposerCallExpectations(this); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 2312 | Case::PerFrameMetadataSupport::setupComposerCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2313 | |
| 2314 | // -------------------------------------------------------------------- |
| 2315 | // Invocation |
| 2316 | |
| 2317 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2318 | |
| 2319 | // -------------------------------------------------------------------- |
| 2320 | // Postconditions |
| 2321 | |
| 2322 | // The display device should have been set up in the list of displays. |
| 2323 | verifyDisplayIsConnected<Case>(displayToken); |
| 2324 | |
| 2325 | // -------------------------------------------------------------------- |
| 2326 | // Cleanup conditions |
| 2327 | |
| 2328 | EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID)) |
| 2329 | .WillOnce(Return(Error::NONE)); |
| 2330 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
Lloyd Pique | 9e9800c | 2019-02-26 16:26:09 -0800 | [diff] [blame] | 2331 | |
| 2332 | // Cleanup |
| 2333 | mFlinger.mutableCurrentState().displays.removeItem(displayToken); |
| 2334 | mFlinger.mutableDrawingState().displays.removeItem(displayToken); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) { |
| 2338 | using Case = HwcVirtualDisplayCase; |
| 2339 | |
| 2340 | // -------------------------------------------------------------------- |
| 2341 | // Preconditions |
| 2342 | |
| 2343 | // The HWC supports at least one virtual display |
| 2344 | injectMockComposer(1); |
| 2345 | |
| 2346 | setupCommonPreconditions<Case>(); |
| 2347 | |
| 2348 | // A virtual display was added to the current state, but it does not have a |
| 2349 | // surface. |
| 2350 | sp<BBinder> displayToken = new BBinder(); |
| 2351 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2352 | DisplayDeviceState state; |
| 2353 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2354 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2355 | mFlinger.mutableCurrentState().displays.add(displayToken, state); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2356 | |
| 2357 | // -------------------------------------------------------------------- |
| 2358 | // Call Expectations |
| 2359 | |
| 2360 | // -------------------------------------------------------------------- |
| 2361 | // Invocation |
| 2362 | |
| 2363 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2364 | |
| 2365 | // -------------------------------------------------------------------- |
| 2366 | // Postconditions |
| 2367 | |
| 2368 | // There will not be a display device set up. |
| 2369 | EXPECT_FALSE(hasDisplayDevice(displayToken)); |
| 2370 | |
| 2371 | // The drawing display state will be set from the current display state. |
| 2372 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); |
| 2373 | const auto& draw = getDrawingDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2374 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) { |
| 2378 | using Case = HwcVirtualDisplayCase; |
| 2379 | |
| 2380 | // -------------------------------------------------------------------- |
| 2381 | // Preconditions |
| 2382 | |
| 2383 | // A virtual display is set up but is removed from the current state. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 2384 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 2385 | ASSERT_TRUE(HalVirtualDisplayId::tryCast(displayId)); |
| 2386 | mFlinger.mutableHwcDisplayData().try_emplace(displayId); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2387 | Case::Display::injectHwcDisplay(this); |
| 2388 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2389 | existing.inject(); |
| 2390 | mFlinger.mutableCurrentState().displays.removeItem(existing.token()); |
| 2391 | |
| 2392 | // -------------------------------------------------------------------- |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 2393 | // Invocation |
| 2394 | |
| 2395 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2396 | |
| 2397 | // -------------------------------------------------------------------- |
| 2398 | // Postconditions |
| 2399 | |
| 2400 | // The existing token should have been removed |
| 2401 | verifyDisplayIsNotConnected(existing.token()); |
| 2402 | } |
| 2403 | |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2404 | TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) { |
| 2405 | using Case = NonHwcVirtualDisplayCase; |
| 2406 | |
| 2407 | constexpr uint32_t oldLayerStack = 0u; |
| 2408 | constexpr uint32_t newLayerStack = 123u; |
| 2409 | |
| 2410 | // -------------------------------------------------------------------- |
| 2411 | // Preconditions |
| 2412 | |
| 2413 | // A display is set up |
| 2414 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2415 | display.inject(); |
| 2416 | |
| 2417 | // There is a change to the layerStack state |
| 2418 | display.mutableDrawingDisplayState().layerStack = oldLayerStack; |
| 2419 | display.mutableCurrentDisplayState().layerStack = newLayerStack; |
| 2420 | |
| 2421 | // -------------------------------------------------------------------- |
| 2422 | // Invocation |
| 2423 | |
| 2424 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2425 | |
| 2426 | // -------------------------------------------------------------------- |
| 2427 | // Postconditions |
| 2428 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2429 | EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) { |
| 2433 | using Case = NonHwcVirtualDisplayCase; |
| 2434 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 2435 | constexpr ui::Rotation oldTransform = ui::ROTATION_0; |
| 2436 | constexpr ui::Rotation newTransform = ui::ROTATION_180; |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2437 | |
| 2438 | // -------------------------------------------------------------------- |
| 2439 | // Preconditions |
| 2440 | |
| 2441 | // A display is set up |
| 2442 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2443 | display.inject(); |
| 2444 | |
| 2445 | // There is a change to the orientation state |
| 2446 | display.mutableDrawingDisplayState().orientation = oldTransform; |
| 2447 | display.mutableCurrentDisplayState().orientation = newTransform; |
| 2448 | |
| 2449 | // -------------------------------------------------------------------- |
| 2450 | // Invocation |
| 2451 | |
| 2452 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2453 | |
| 2454 | // -------------------------------------------------------------------- |
| 2455 | // Postconditions |
| 2456 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2457 | EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2458 | } |
| 2459 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2460 | TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackRectChanges) { |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2461 | using Case = NonHwcVirtualDisplayCase; |
| 2462 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2463 | const Rect oldLayerStackRect(0, 0, 0, 0); |
| 2464 | const Rect newLayerStackRect(0, 0, 123, 456); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2465 | |
| 2466 | // -------------------------------------------------------------------- |
| 2467 | // Preconditions |
| 2468 | |
| 2469 | // A display is set up |
| 2470 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2471 | display.inject(); |
| 2472 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2473 | // There is a change to the layerStackSpaceRect state |
| 2474 | display.mutableDrawingDisplayState().layerStackSpaceRect = oldLayerStackRect; |
| 2475 | display.mutableCurrentDisplayState().layerStackSpaceRect = newLayerStackRect; |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2476 | |
| 2477 | // -------------------------------------------------------------------- |
| 2478 | // Invocation |
| 2479 | |
| 2480 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2481 | |
| 2482 | // -------------------------------------------------------------------- |
| 2483 | // Postconditions |
| 2484 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2485 | EXPECT_EQ(newLayerStackRect, display.mutableDisplayDevice()->getLayerStackSpaceRect()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) { |
| 2489 | using Case = NonHwcVirtualDisplayCase; |
| 2490 | |
| 2491 | const Rect oldFrame(0, 0, 0, 0); |
| 2492 | const Rect newFrame(0, 0, 123, 456); |
| 2493 | |
| 2494 | // -------------------------------------------------------------------- |
| 2495 | // Preconditions |
| 2496 | |
| 2497 | // A display is set up |
| 2498 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2499 | display.inject(); |
| 2500 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2501 | // There is a change to the layerStackSpaceRect state |
| 2502 | display.mutableDrawingDisplayState().orientedDisplaySpaceRect = oldFrame; |
| 2503 | display.mutableCurrentDisplayState().orientedDisplaySpaceRect = newFrame; |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2504 | |
| 2505 | // -------------------------------------------------------------------- |
| 2506 | // Invocation |
| 2507 | |
| 2508 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2509 | |
| 2510 | // -------------------------------------------------------------------- |
| 2511 | // Postconditions |
| 2512 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2513 | EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getOrientedDisplaySpaceRect()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) { |
| 2517 | using Case = NonHwcVirtualDisplayCase; |
| 2518 | |
| 2519 | constexpr int oldWidth = 0; |
| 2520 | constexpr int oldHeight = 10; |
| 2521 | constexpr int newWidth = 123; |
| 2522 | |
| 2523 | // -------------------------------------------------------------------- |
| 2524 | // Preconditions |
| 2525 | |
| 2526 | // A display is set up |
| 2527 | auto nativeWindow = new mock::NativeWindow(); |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 2528 | auto displaySurface = new compositionengine::mock::DisplaySurface(); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 2529 | sp<GraphicBuffer> buf = new GraphicBuffer(); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2530 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2531 | display.setNativeWindow(nativeWindow); |
| 2532 | display.setDisplaySurface(displaySurface); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 2533 | // Setup injection expections |
| 2534 | EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 2535 | .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0))); |
| 2536 | EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 2537 | .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0))); |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 2538 | EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1); |
| 2539 | EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1); |
| 2540 | EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 2541 | EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2542 | display.inject(); |
| 2543 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2544 | // There is a change to the layerStackSpaceRect state |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2545 | display.mutableDrawingDisplayState().width = oldWidth; |
| 2546 | display.mutableDrawingDisplayState().height = oldHeight; |
| 2547 | display.mutableCurrentDisplayState().width = newWidth; |
| 2548 | display.mutableCurrentDisplayState().height = oldHeight; |
| 2549 | |
| 2550 | // -------------------------------------------------------------------- |
| 2551 | // Call Expectations |
| 2552 | |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2553 | EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2554 | |
| 2555 | // -------------------------------------------------------------------- |
| 2556 | // Invocation |
| 2557 | |
| 2558 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2559 | } |
| 2560 | |
| 2561 | TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) { |
| 2562 | using Case = NonHwcVirtualDisplayCase; |
| 2563 | |
| 2564 | constexpr int oldWidth = 0; |
| 2565 | constexpr int oldHeight = 10; |
| 2566 | constexpr int newHeight = 123; |
| 2567 | |
| 2568 | // -------------------------------------------------------------------- |
| 2569 | // Preconditions |
| 2570 | |
| 2571 | // A display is set up |
| 2572 | auto nativeWindow = new mock::NativeWindow(); |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 2573 | auto displaySurface = new compositionengine::mock::DisplaySurface(); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 2574 | sp<GraphicBuffer> buf = new GraphicBuffer(); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2575 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2576 | display.setNativeWindow(nativeWindow); |
| 2577 | display.setDisplaySurface(displaySurface); |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 2578 | // Setup injection expections |
| 2579 | EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 2580 | .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0))); |
| 2581 | EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 2582 | .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0))); |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 2583 | EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1); |
| 2584 | EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1); |
| 2585 | EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 2586 | EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2587 | display.inject(); |
| 2588 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2589 | // There is a change to the layerStackSpaceRect state |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2590 | display.mutableDrawingDisplayState().width = oldWidth; |
| 2591 | display.mutableDrawingDisplayState().height = oldHeight; |
| 2592 | display.mutableCurrentDisplayState().width = oldWidth; |
| 2593 | display.mutableCurrentDisplayState().height = newHeight; |
| 2594 | |
| 2595 | // -------------------------------------------------------------------- |
| 2596 | // Call Expectations |
| 2597 | |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2598 | EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 2599 | |
| 2600 | // -------------------------------------------------------------------- |
| 2601 | // Invocation |
| 2602 | |
| 2603 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 2604 | } |
| 2605 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2606 | /* ------------------------------------------------------------------------ |
| 2607 | * SurfaceFlinger::setDisplayStateLocked |
| 2608 | */ |
| 2609 | |
| 2610 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) { |
| 2611 | // -------------------------------------------------------------------- |
| 2612 | // Preconditions |
| 2613 | |
| 2614 | // We have an unknown display token not associated with a known display |
| 2615 | sp<BBinder> displayToken = new BBinder(); |
| 2616 | |
| 2617 | // The requested display state references the unknown display. |
| 2618 | DisplayState state; |
| 2619 | state.what = DisplayState::eLayerStackChanged; |
| 2620 | state.token = displayToken; |
| 2621 | state.layerStack = 456; |
| 2622 | |
| 2623 | // -------------------------------------------------------------------- |
| 2624 | // Invocation |
| 2625 | |
| 2626 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2627 | |
| 2628 | // -------------------------------------------------------------------- |
| 2629 | // Postconditions |
| 2630 | |
| 2631 | // The returned flags are empty |
| 2632 | EXPECT_EQ(0u, flags); |
| 2633 | |
| 2634 | // The display token still doesn't match anything known. |
| 2635 | EXPECT_FALSE(hasCurrentDisplayState(displayToken)); |
| 2636 | } |
| 2637 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2638 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) { |
| 2639 | using Case = SimplePrimaryDisplayCase; |
| 2640 | |
| 2641 | // -------------------------------------------------------------------- |
| 2642 | // Preconditions |
| 2643 | |
| 2644 | // A display is already set up |
| 2645 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2646 | display.inject(); |
| 2647 | |
| 2648 | // No changes are made to the display |
| 2649 | DisplayState state; |
| 2650 | state.what = 0; |
| 2651 | state.token = display.token(); |
| 2652 | |
| 2653 | // -------------------------------------------------------------------- |
| 2654 | // Invocation |
| 2655 | |
| 2656 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2657 | |
| 2658 | // -------------------------------------------------------------------- |
| 2659 | // Postconditions |
| 2660 | |
| 2661 | // The returned flags are empty |
| 2662 | EXPECT_EQ(0u, flags); |
| 2663 | } |
| 2664 | |
| 2665 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) { |
| 2666 | using Case = SimplePrimaryDisplayCase; |
| 2667 | |
| 2668 | // -------------------------------------------------------------------- |
| 2669 | // Preconditions |
| 2670 | |
| 2671 | // A display is already set up |
| 2672 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2673 | display.inject(); |
| 2674 | |
| 2675 | // There is a surface that can be set. |
| 2676 | sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer(); |
| 2677 | |
| 2678 | // The current display state has the surface set |
| 2679 | display.mutableCurrentDisplayState().surface = surface; |
| 2680 | |
| 2681 | // The incoming request sets the same surface |
| 2682 | DisplayState state; |
| 2683 | state.what = DisplayState::eSurfaceChanged; |
| 2684 | state.token = display.token(); |
| 2685 | state.surface = surface; |
| 2686 | |
| 2687 | // -------------------------------------------------------------------- |
| 2688 | // Invocation |
| 2689 | |
| 2690 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2691 | |
| 2692 | // -------------------------------------------------------------------- |
| 2693 | // Postconditions |
| 2694 | |
| 2695 | // The returned flags are empty |
| 2696 | EXPECT_EQ(0u, flags); |
| 2697 | |
| 2698 | // The current display state is unchanged. |
| 2699 | EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get()); |
| 2700 | } |
| 2701 | |
| 2702 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) { |
| 2703 | using Case = SimplePrimaryDisplayCase; |
| 2704 | |
| 2705 | // -------------------------------------------------------------------- |
| 2706 | // Preconditions |
| 2707 | |
| 2708 | // A display is already set up |
| 2709 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2710 | display.inject(); |
| 2711 | |
| 2712 | // There is a surface that can be set. |
| 2713 | sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer(); |
| 2714 | |
| 2715 | // The current display state does not have a surface |
| 2716 | display.mutableCurrentDisplayState().surface = nullptr; |
| 2717 | |
| 2718 | // The incoming request sets a surface |
| 2719 | DisplayState state; |
| 2720 | state.what = DisplayState::eSurfaceChanged; |
| 2721 | state.token = display.token(); |
| 2722 | state.surface = surface; |
| 2723 | |
| 2724 | // -------------------------------------------------------------------- |
| 2725 | // Invocation |
| 2726 | |
| 2727 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2728 | |
| 2729 | // -------------------------------------------------------------------- |
| 2730 | // Postconditions |
| 2731 | |
| 2732 | // The returned flags indicate a transaction is needed |
| 2733 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2734 | |
| 2735 | // The current display layer stack state is set to the new value |
| 2736 | EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get()); |
| 2737 | } |
| 2738 | |
| 2739 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) { |
| 2740 | using Case = SimplePrimaryDisplayCase; |
| 2741 | |
| 2742 | // -------------------------------------------------------------------- |
| 2743 | // Preconditions |
| 2744 | |
| 2745 | // A display is already set up |
| 2746 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2747 | display.inject(); |
| 2748 | |
| 2749 | // The display has a layer stack set |
| 2750 | display.mutableCurrentDisplayState().layerStack = 456u; |
| 2751 | |
| 2752 | // The incoming request sets the same layer stack |
| 2753 | DisplayState state; |
| 2754 | state.what = DisplayState::eLayerStackChanged; |
| 2755 | state.token = display.token(); |
| 2756 | state.layerStack = 456u; |
| 2757 | |
| 2758 | // -------------------------------------------------------------------- |
| 2759 | // Invocation |
| 2760 | |
| 2761 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2762 | |
| 2763 | // -------------------------------------------------------------------- |
| 2764 | // Postconditions |
| 2765 | |
| 2766 | // The returned flags are empty |
| 2767 | EXPECT_EQ(0u, flags); |
| 2768 | |
| 2769 | // The current display state is unchanged |
| 2770 | EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack); |
| 2771 | } |
| 2772 | |
| 2773 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) { |
| 2774 | using Case = SimplePrimaryDisplayCase; |
| 2775 | |
| 2776 | // -------------------------------------------------------------------- |
| 2777 | // Preconditions |
| 2778 | |
| 2779 | // A display is set up |
| 2780 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2781 | display.inject(); |
| 2782 | |
| 2783 | // The display has a layer stack set |
| 2784 | display.mutableCurrentDisplayState().layerStack = 654u; |
| 2785 | |
| 2786 | // The incoming request sets a different layer stack |
| 2787 | DisplayState state; |
| 2788 | state.what = DisplayState::eLayerStackChanged; |
| 2789 | state.token = display.token(); |
| 2790 | state.layerStack = 456u; |
| 2791 | |
| 2792 | // -------------------------------------------------------------------- |
| 2793 | // Invocation |
| 2794 | |
| 2795 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2796 | |
| 2797 | // -------------------------------------------------------------------- |
| 2798 | // Postconditions |
| 2799 | |
| 2800 | // The returned flags indicate a transaction is needed |
| 2801 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2802 | |
| 2803 | // The desired display state has been set to the new value. |
| 2804 | EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack); |
| 2805 | } |
| 2806 | |
| 2807 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) { |
| 2808 | using Case = SimplePrimaryDisplayCase; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 2809 | constexpr ui::Rotation initialOrientation = ui::ROTATION_180; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2810 | const Rect initialOrientedDisplayRect = {1, 2, 3, 4}; |
| 2811 | const Rect initialLayerStackRect = {5, 6, 7, 8}; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2812 | |
| 2813 | // -------------------------------------------------------------------- |
| 2814 | // Preconditions |
| 2815 | |
| 2816 | // A display is set up |
| 2817 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2818 | display.inject(); |
| 2819 | |
| 2820 | // The current display state projection state is all set |
| 2821 | display.mutableCurrentDisplayState().orientation = initialOrientation; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2822 | display.mutableCurrentDisplayState().orientedDisplaySpaceRect = initialOrientedDisplayRect; |
| 2823 | display.mutableCurrentDisplayState().layerStackSpaceRect = initialLayerStackRect; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2824 | |
| 2825 | // The incoming request sets the same projection state |
| 2826 | DisplayState state; |
| 2827 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2828 | state.token = display.token(); |
| 2829 | state.orientation = initialOrientation; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2830 | state.orientedDisplaySpaceRect = initialOrientedDisplayRect; |
| 2831 | state.layerStackSpaceRect = initialLayerStackRect; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2832 | |
| 2833 | // -------------------------------------------------------------------- |
| 2834 | // Invocation |
| 2835 | |
| 2836 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2837 | |
| 2838 | // -------------------------------------------------------------------- |
| 2839 | // Postconditions |
| 2840 | |
| 2841 | // The returned flags are empty |
| 2842 | EXPECT_EQ(0u, flags); |
| 2843 | |
| 2844 | // The current display state is unchanged |
| 2845 | EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation); |
| 2846 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2847 | EXPECT_EQ(initialOrientedDisplayRect, |
| 2848 | display.getCurrentDisplayState().orientedDisplaySpaceRect); |
| 2849 | EXPECT_EQ(initialLayerStackRect, display.getCurrentDisplayState().layerStackSpaceRect); |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) { |
| 2853 | using Case = SimplePrimaryDisplayCase; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 2854 | constexpr ui::Rotation initialOrientation = ui::ROTATION_90; |
| 2855 | constexpr ui::Rotation desiredOrientation = ui::ROTATION_180; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2856 | |
| 2857 | // -------------------------------------------------------------------- |
| 2858 | // Preconditions |
| 2859 | |
| 2860 | // A display is set up |
| 2861 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2862 | display.inject(); |
| 2863 | |
| 2864 | // The current display state has an orientation set |
| 2865 | display.mutableCurrentDisplayState().orientation = initialOrientation; |
| 2866 | |
| 2867 | // The incoming request sets a different orientation |
| 2868 | DisplayState state; |
| 2869 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2870 | state.token = display.token(); |
| 2871 | state.orientation = desiredOrientation; |
| 2872 | |
| 2873 | // -------------------------------------------------------------------- |
| 2874 | // Invocation |
| 2875 | |
| 2876 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2877 | |
| 2878 | // -------------------------------------------------------------------- |
| 2879 | // Postconditions |
| 2880 | |
| 2881 | // The returned flags indicate a transaction is needed |
| 2882 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2883 | |
| 2884 | // The current display state has the new value. |
| 2885 | EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation); |
| 2886 | } |
| 2887 | |
| 2888 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) { |
| 2889 | using Case = SimplePrimaryDisplayCase; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2890 | const Rect initialOrientedDisplayRect = {0, 0, 0, 0}; |
| 2891 | const Rect desiredOrientedDisplayRect = {5, 6, 7, 8}; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2892 | |
| 2893 | // -------------------------------------------------------------------- |
| 2894 | // Preconditions |
| 2895 | |
| 2896 | // A display is set up |
| 2897 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2898 | display.inject(); |
| 2899 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2900 | // The current display state does not have a orientedDisplaySpaceRect |
| 2901 | display.mutableCurrentDisplayState().orientedDisplaySpaceRect = initialOrientedDisplayRect; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2902 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2903 | // The incoming request sets a orientedDisplaySpaceRect |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2904 | DisplayState state; |
| 2905 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2906 | state.token = display.token(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2907 | state.orientedDisplaySpaceRect = desiredOrientedDisplayRect; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2908 | |
| 2909 | // -------------------------------------------------------------------- |
| 2910 | // Invocation |
| 2911 | |
| 2912 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2913 | |
| 2914 | // -------------------------------------------------------------------- |
| 2915 | // Postconditions |
| 2916 | |
| 2917 | // The returned flags indicate a transaction is needed |
| 2918 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2919 | |
| 2920 | // The current display state has the new value. |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2921 | EXPECT_EQ(desiredOrientedDisplayRect, |
| 2922 | display.getCurrentDisplayState().orientedDisplaySpaceRect); |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2923 | } |
| 2924 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2925 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackRectChanged) { |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2926 | using Case = SimplePrimaryDisplayCase; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2927 | const Rect initialLayerStackRect = {0, 0, 0, 0}; |
| 2928 | const Rect desiredLayerStackRect = {5, 6, 7, 8}; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2929 | |
| 2930 | // -------------------------------------------------------------------- |
| 2931 | // Preconditions |
| 2932 | |
| 2933 | // A display is set up |
| 2934 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2935 | display.inject(); |
| 2936 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2937 | // The current display state does not have a layerStackSpaceRect |
| 2938 | display.mutableCurrentDisplayState().layerStackSpaceRect = initialLayerStackRect; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2939 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2940 | // The incoming request sets a layerStackSpaceRect |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2941 | DisplayState state; |
| 2942 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2943 | state.token = display.token(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2944 | state.layerStackSpaceRect = desiredLayerStackRect; |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2945 | |
| 2946 | // -------------------------------------------------------------------- |
| 2947 | // Invocation |
| 2948 | |
| 2949 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2950 | |
| 2951 | // -------------------------------------------------------------------- |
| 2952 | // Postconditions |
| 2953 | |
| 2954 | // The returned flags indicate a transaction is needed |
| 2955 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2956 | |
| 2957 | // The current display state has the new value. |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2958 | EXPECT_EQ(desiredLayerStackRect, display.getCurrentDisplayState().layerStackSpaceRect); |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) { |
| 2962 | using Case = SimplePrimaryDisplayCase; |
| 2963 | constexpr uint32_t initialWidth = 1024; |
| 2964 | constexpr uint32_t initialHeight = 768; |
| 2965 | |
| 2966 | // -------------------------------------------------------------------- |
| 2967 | // Preconditions |
| 2968 | |
| 2969 | // A display is set up |
| 2970 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2971 | display.inject(); |
| 2972 | |
| 2973 | // The current display state has a size set |
| 2974 | display.mutableCurrentDisplayState().width = initialWidth; |
| 2975 | display.mutableCurrentDisplayState().height = initialHeight; |
| 2976 | |
| 2977 | // The incoming request sets the same display size |
| 2978 | DisplayState state; |
| 2979 | state.what = DisplayState::eDisplaySizeChanged; |
| 2980 | state.token = display.token(); |
| 2981 | state.width = initialWidth; |
| 2982 | state.height = initialHeight; |
| 2983 | |
| 2984 | // -------------------------------------------------------------------- |
| 2985 | // Invocation |
| 2986 | |
| 2987 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2988 | |
| 2989 | // -------------------------------------------------------------------- |
| 2990 | // Postconditions |
| 2991 | |
| 2992 | // The returned flags are empty |
| 2993 | EXPECT_EQ(0u, flags); |
| 2994 | |
| 2995 | // The current display state is unchanged |
| 2996 | EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width); |
| 2997 | EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height); |
| 2998 | } |
| 2999 | |
| 3000 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) { |
| 3001 | using Case = SimplePrimaryDisplayCase; |
| 3002 | constexpr uint32_t initialWidth = 0; |
| 3003 | constexpr uint32_t desiredWidth = 1024; |
| 3004 | |
| 3005 | // -------------------------------------------------------------------- |
| 3006 | // Preconditions |
| 3007 | |
| 3008 | // A display is set up |
| 3009 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 3010 | display.inject(); |
| 3011 | |
| 3012 | // The display does not yet have a width |
| 3013 | display.mutableCurrentDisplayState().width = initialWidth; |
| 3014 | |
| 3015 | // The incoming request sets a display width |
| 3016 | DisplayState state; |
| 3017 | state.what = DisplayState::eDisplaySizeChanged; |
| 3018 | state.token = display.token(); |
| 3019 | state.width = desiredWidth; |
| 3020 | |
| 3021 | // -------------------------------------------------------------------- |
| 3022 | // Invocation |
| 3023 | |
| 3024 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 3025 | |
| 3026 | // -------------------------------------------------------------------- |
| 3027 | // Postconditions |
| 3028 | |
| 3029 | // The returned flags indicate a transaction is needed |
| 3030 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 3031 | |
| 3032 | // The current display state has the new value. |
| 3033 | EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width); |
| 3034 | } |
| 3035 | |
| 3036 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) { |
| 3037 | using Case = SimplePrimaryDisplayCase; |
| 3038 | constexpr uint32_t initialHeight = 0; |
| 3039 | constexpr uint32_t desiredHeight = 768; |
| 3040 | |
| 3041 | // -------------------------------------------------------------------- |
| 3042 | // Preconditions |
| 3043 | |
| 3044 | // A display is set up |
| 3045 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 3046 | display.inject(); |
| 3047 | |
| 3048 | // The display does not yet have a height |
| 3049 | display.mutableCurrentDisplayState().height = initialHeight; |
| 3050 | |
| 3051 | // The incoming request sets a display height |
| 3052 | DisplayState state; |
| 3053 | state.what = DisplayState::eDisplaySizeChanged; |
| 3054 | state.token = display.token(); |
| 3055 | state.height = desiredHeight; |
| 3056 | |
| 3057 | // -------------------------------------------------------------------- |
| 3058 | // Invocation |
| 3059 | |
| 3060 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 3061 | |
| 3062 | // -------------------------------------------------------------------- |
| 3063 | // Postconditions |
| 3064 | |
| 3065 | // The returned flags indicate a transaction is needed |
| 3066 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 3067 | |
| 3068 | // The current display state has the new value. |
| 3069 | EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height); |
| 3070 | } |
| 3071 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 3072 | /* ------------------------------------------------------------------------ |
| 3073 | * SurfaceFlinger::onInitializeDisplays |
| 3074 | */ |
| 3075 | |
| 3076 | TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) { |
| 3077 | using Case = SimplePrimaryDisplayCase; |
| 3078 | |
| 3079 | // -------------------------------------------------------------------- |
| 3080 | // Preconditions |
| 3081 | |
| 3082 | // A primary display is set up |
| 3083 | Case::Display::injectHwcDisplay(this); |
| 3084 | auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this); |
| 3085 | primaryDisplay.inject(); |
| 3086 | |
| 3087 | // -------------------------------------------------------------------- |
| 3088 | // Call Expectations |
| 3089 | |
| 3090 | // We expect the surface interceptor to possibly be used, but we treat it as |
| 3091 | // disabled since it is called as a side effect rather than directly by this |
| 3092 | // function. |
| 3093 | EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false)); |
| 3094 | |
| 3095 | // We expect a call to get the active display config. |
| 3096 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
| 3097 | |
| 3098 | // We expect invalidate() to be invoked once to trigger display transaction |
| 3099 | // processing. |
| 3100 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 3101 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 3102 | EXPECT_CALL(*mVSyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 3103 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 3104 | // -------------------------------------------------------------------- |
| 3105 | // Invocation |
| 3106 | |
| 3107 | mFlinger.onInitializeDisplays(); |
| 3108 | |
| 3109 | // -------------------------------------------------------------------- |
| 3110 | // Postconditions |
| 3111 | |
| 3112 | // The primary display should have a current state |
| 3113 | ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token())); |
| 3114 | const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token()); |
| 3115 | // The layer stack state should be set to zero |
| 3116 | EXPECT_EQ(0u, primaryDisplayState.layerStack); |
| 3117 | // The orientation state should be set to zero |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 3118 | EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation); |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 3119 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3120 | // The orientedDisplaySpaceRect state should be set to INVALID |
| 3121 | EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.orientedDisplaySpaceRect); |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 3122 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3123 | // The layerStackSpaceRect state should be set to INVALID |
| 3124 | EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.layerStackSpaceRect); |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 3125 | |
| 3126 | // The width and height should both be zero |
| 3127 | EXPECT_EQ(0u, primaryDisplayState.width); |
| 3128 | EXPECT_EQ(0u, primaryDisplayState.height); |
| 3129 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3130 | // The display should be set to PowerMode::ON |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 3131 | ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token())); |
| 3132 | auto displayDevice = primaryDisplay.mutableDisplayDevice(); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3133 | EXPECT_EQ(PowerMode::ON, displayDevice->getPowerMode()); |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 3134 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 3135 | // The display refresh period should be set in the orientedDisplaySpaceRect tracker. |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 3136 | FrameStats stats; |
| 3137 | mFlinger.getAnimFrameTracker().getStats(&stats); |
| 3138 | EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano); |
| 3139 | |
| 3140 | // The display transaction needed flag should be set. |
| 3141 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 3142 | |
| 3143 | // The compositor timing should be set to default values |
| 3144 | const auto& compositorTiming = mFlinger.getCompositorTiming(); |
| 3145 | EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline); |
| 3146 | EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval); |
| 3147 | EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency); |
| 3148 | } |
| 3149 | |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3150 | /* ------------------------------------------------------------------------ |
| 3151 | * SurfaceFlinger::setPowerModeInternal |
| 3152 | */ |
| 3153 | |
| 3154 | // Used when we simulate a display that supports doze. |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3155 | template <typename Display> |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3156 | struct DozeIsSupportedVariant { |
| 3157 | static constexpr bool DOZE_SUPPORTED = true; |
| 3158 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE = |
| 3159 | IComposerClient::PowerMode::DOZE; |
| 3160 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND = |
| 3161 | IComposerClient::PowerMode::DOZE_SUSPEND; |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3162 | |
| 3163 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 3164 | EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _)) |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 3165 | .WillOnce(DoAll(SetArgPointee<1>( |
| 3166 | std::vector<DisplayCapability>({DisplayCapability::DOZE})), |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3167 | Return(Error::NONE))); |
| 3168 | } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3169 | }; |
| 3170 | |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3171 | template <typename Display> |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3172 | // Used when we simulate a display that does not support doze. |
| 3173 | struct DozeNotSupportedVariant { |
| 3174 | static constexpr bool DOZE_SUPPORTED = false; |
| 3175 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE = |
| 3176 | IComposerClient::PowerMode::ON; |
| 3177 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND = |
| 3178 | IComposerClient::PowerMode::ON; |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3179 | |
| 3180 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 3181 | EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _)) |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 3182 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})), |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3183 | Return(Error::NONE))); |
| 3184 | } |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3185 | }; |
| 3186 | |
| 3187 | struct EventThreadBaseSupportedVariant { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3188 | static void setupVsyncAndEventThreadNoCallExpectations(DisplayTransactionTest* test) { |
| 3189 | // The callback should not be notified to toggle VSYNC. |
| 3190 | EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(_)).Times(0); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3191 | |
| 3192 | // The event thread should not be notified. |
| 3193 | EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0); |
| 3194 | EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0); |
| 3195 | } |
| 3196 | }; |
| 3197 | |
| 3198 | struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant { |
| 3199 | static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 3200 | // These calls are only expected for the primary display. |
| 3201 | |
| 3202 | // Instead expect no calls. |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3203 | setupVsyncAndEventThreadNoCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 3207 | // These calls are only expected for the primary display. |
| 3208 | |
| 3209 | // Instead expect no calls. |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3210 | setupVsyncAndEventThreadNoCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3211 | } |
| 3212 | }; |
| 3213 | |
| 3214 | struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant { |
| 3215 | static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3216 | // The callback should be notified to enable VSYNC. |
| 3217 | EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(true)).Times(1); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3218 | |
| 3219 | // The event thread should be notified that the screen was acquired. |
| 3220 | EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1); |
| 3221 | } |
| 3222 | |
| 3223 | static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3224 | // The callback should be notified to disable VSYNC. |
| 3225 | EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(false)).Times(1); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3226 | |
| 3227 | // The event thread should not be notified that the screen was released. |
| 3228 | EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1); |
| 3229 | } |
| 3230 | }; |
| 3231 | |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 3232 | struct DispSyncIsSupportedVariant { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 3233 | static void setupResetModelCallExpectations(DisplayTransactionTest* test) { |
| 3234 | EXPECT_CALL(*test->mVsyncController, startPeriodTransition(DEFAULT_REFRESH_RATE)).Times(1); |
| 3235 | EXPECT_CALL(*test->mVSyncTracker, resetModel()).Times(1); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 3236 | } |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 3237 | }; |
| 3238 | |
| 3239 | struct DispSyncNotSupportedVariant { |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 3240 | static void setupResetModelCallExpectations(DisplayTransactionTest* /* test */) {} |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 3241 | }; |
| 3242 | |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3243 | // -------------------------------------------------------------------- |
| 3244 | // Note: |
| 3245 | // |
| 3246 | // There are a large number of transitions we could test, however we only test a |
| 3247 | // selected subset which provides complete test coverage of the implementation. |
| 3248 | // -------------------------------------------------------------------- |
| 3249 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3250 | template <PowerMode initialPowerMode, PowerMode targetPowerMode> |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3251 | struct TransitionVariantCommon { |
| 3252 | static constexpr auto INITIAL_POWER_MODE = initialPowerMode; |
| 3253 | static constexpr auto TARGET_POWER_MODE = targetPowerMode; |
| 3254 | |
| 3255 | static void verifyPostconditions(DisplayTransactionTest*) {} |
| 3256 | }; |
| 3257 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3258 | struct TransitionOffToOnVariant : public TransitionVariantCommon<PowerMode::OFF, PowerMode::ON> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3259 | template <typename Case> |
| 3260 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 3261 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON); |
| 3262 | Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test); |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 3263 | Case::DispSync::setupResetModelCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3264 | Case::setupRepaintEverythingCallExpectations(test); |
| 3265 | } |
| 3266 | |
| 3267 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 3268 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 3269 | EXPECT_TRUE(test->mFlinger.getHasPoweredOff()); |
| 3270 | } |
| 3271 | }; |
| 3272 | |
| 3273 | struct TransitionOffToDozeSuspendVariant |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3274 | : public TransitionVariantCommon<PowerMode::OFF, PowerMode::DOZE_SUSPEND> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3275 | template <typename Case> |
| 3276 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 3277 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND); |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3278 | Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3279 | Case::setupRepaintEverythingCallExpectations(test); |
| 3280 | } |
| 3281 | |
| 3282 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 3283 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 3284 | EXPECT_TRUE(test->mFlinger.getHasPoweredOff()); |
| 3285 | } |
| 3286 | }; |
| 3287 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3288 | struct TransitionOnToOffVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::OFF> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3289 | template <typename Case> |
| 3290 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 3291 | Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test); |
| 3292 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF); |
| 3293 | } |
| 3294 | |
| 3295 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 3296 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 3297 | } |
| 3298 | }; |
| 3299 | |
| 3300 | struct TransitionDozeSuspendToOffVariant |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3301 | : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::OFF> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3302 | template <typename Case> |
| 3303 | static void setupCallExpectations(DisplayTransactionTest* test) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3304 | Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3305 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF); |
| 3306 | } |
| 3307 | |
| 3308 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 3309 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 3310 | } |
| 3311 | }; |
| 3312 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3313 | struct TransitionOnToDozeVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3314 | template <typename Case> |
| 3315 | static void setupCallExpectations(DisplayTransactionTest* test) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3316 | Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3317 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE); |
| 3318 | } |
| 3319 | }; |
| 3320 | |
| 3321 | struct TransitionDozeSuspendToDozeVariant |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3322 | : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::DOZE> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3323 | template <typename Case> |
| 3324 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 3325 | Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test); |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 3326 | Case::DispSync::setupResetModelCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3327 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE); |
| 3328 | } |
| 3329 | }; |
| 3330 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3331 | struct TransitionDozeToOnVariant : public TransitionVariantCommon<PowerMode::DOZE, PowerMode::ON> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3332 | template <typename Case> |
| 3333 | static void setupCallExpectations(DisplayTransactionTest* test) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3334 | Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3335 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON); |
| 3336 | } |
| 3337 | }; |
| 3338 | |
| 3339 | struct TransitionDozeSuspendToOnVariant |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3340 | : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::ON> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3341 | template <typename Case> |
| 3342 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 3343 | Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test); |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 3344 | Case::DispSync::setupResetModelCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3345 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON); |
| 3346 | } |
| 3347 | }; |
| 3348 | |
| 3349 | struct TransitionOnToDozeSuspendVariant |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3350 | : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE_SUSPEND> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3351 | template <typename Case> |
| 3352 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 3353 | Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test); |
| 3354 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND); |
| 3355 | } |
| 3356 | }; |
| 3357 | |
| 3358 | struct TransitionOnToUnknownVariant |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3359 | : public TransitionVariantCommon<PowerMode::ON, static_cast<PowerMode>(POWER_MODE_LEET)> { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3360 | template <typename Case> |
| 3361 | static void setupCallExpectations(DisplayTransactionTest* test) { |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 3362 | Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3363 | Case::setupNoComposerPowerModeCallExpectations(test); |
| 3364 | } |
| 3365 | }; |
| 3366 | |
| 3367 | // -------------------------------------------------------------------- |
| 3368 | // Note: |
| 3369 | // |
| 3370 | // Rather than testing the cartesian product of of |
| 3371 | // DozeIsSupported/DozeNotSupported with all other options, we use one for one |
| 3372 | // display type, and the other for another display type. |
| 3373 | // -------------------------------------------------------------------- |
| 3374 | |
| 3375 | template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant, |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 3376 | typename DispSyncVariant, typename TransitionVariant> |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3377 | struct DisplayPowerCase { |
| 3378 | using Display = DisplayVariant; |
| 3379 | using Doze = DozeVariant; |
| 3380 | using EventThread = EventThreadVariant; |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 3381 | using DispSync = DispSyncVariant; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3382 | using Transition = TransitionVariant; |
| 3383 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3384 | static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, PowerMode mode) { |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 3385 | Display::injectHwcDisplayWithNoDefaultCapabilities(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3386 | auto display = Display::makeFakeExistingDisplayInjector(test); |
| 3387 | display.inject(); |
| 3388 | display.mutableDisplayDevice()->setPowerMode(mode); |
| 3389 | return display; |
| 3390 | } |
| 3391 | |
| 3392 | static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) { |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 3393 | test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3394 | } |
| 3395 | |
| 3396 | static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) { |
| 3397 | EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1); |
| 3398 | } |
| 3399 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3400 | static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, |
| 3401 | PowerMode mode) { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3402 | EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true)); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3403 | EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, static_cast<int32_t>(mode))) |
| 3404 | .Times(1); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3405 | } |
| 3406 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3407 | static void setupComposerCallExpectations(DisplayTransactionTest* test, PowerMode mode) { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3408 | // Any calls to get the active config will return a default value. |
| 3409 | EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _)) |
| 3410 | .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID), |
| 3411 | Return(Error::NONE))); |
| 3412 | |
| 3413 | // Any calls to get whether the display supports dozing will return the value set by the |
| 3414 | // policy variant. |
| 3415 | EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _)) |
| 3416 | .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE))); |
| 3417 | |
| 3418 | EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1); |
| 3419 | } |
| 3420 | |
| 3421 | static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) { |
| 3422 | EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0); |
| 3423 | } |
| 3424 | }; |
| 3425 | |
| 3426 | // A sample configuration for the primary display. |
| 3427 | // In addition to having event thread support, we emulate doze support. |
| 3428 | template <typename TransitionVariant> |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3429 | using PrimaryDisplayPowerCase = |
| 3430 | DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>, |
| 3431 | EventThreadIsSupportedVariant, DispSyncIsSupportedVariant, |
| 3432 | TransitionVariant>; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3433 | |
| 3434 | // A sample configuration for the external display. |
| 3435 | // In addition to not having event thread support, we emulate not having doze |
| 3436 | // support. |
| 3437 | template <typename TransitionVariant> |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3438 | using ExternalDisplayPowerCase = |
| 3439 | DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>, |
| 3440 | EventThreadNotSupportedVariant, DispSyncNotSupportedVariant, |
| 3441 | TransitionVariant>; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3442 | |
| 3443 | class SetPowerModeInternalTest : public DisplayTransactionTest { |
| 3444 | public: |
| 3445 | template <typename Case> |
| 3446 | void transitionDisplayCommon(); |
| 3447 | }; |
| 3448 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3449 | template <PowerMode PowerMode> |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3450 | struct PowerModeInitialVSyncEnabled : public std::false_type {}; |
| 3451 | |
| 3452 | template <> |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3453 | struct PowerModeInitialVSyncEnabled<PowerMode::ON> : public std::true_type {}; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3454 | |
| 3455 | template <> |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3456 | struct PowerModeInitialVSyncEnabled<PowerMode::DOZE> : public std::true_type {}; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3457 | |
| 3458 | template <typename Case> |
| 3459 | void SetPowerModeInternalTest::transitionDisplayCommon() { |
| 3460 | // -------------------------------------------------------------------- |
| 3461 | // Preconditions |
| 3462 | |
Peiyong Lin | ed531a3 | 2018-10-26 18:27:56 -0700 | [diff] [blame] | 3463 | Case::Doze::setupComposerCallExpectations(this); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3464 | auto display = |
| 3465 | Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE); |
| 3466 | Case::setInitialPrimaryHWVsyncEnabled(this, |
| 3467 | PowerModeInitialVSyncEnabled< |
| 3468 | Case::Transition::INITIAL_POWER_MODE>::value); |
| 3469 | |
| 3470 | // -------------------------------------------------------------------- |
| 3471 | // Call Expectations |
| 3472 | |
| 3473 | Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE); |
| 3474 | Case::Transition::template setupCallExpectations<Case>(this); |
| 3475 | |
| 3476 | // -------------------------------------------------------------------- |
| 3477 | // Invocation |
| 3478 | |
| 3479 | mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), |
| 3480 | Case::Transition::TARGET_POWER_MODE); |
| 3481 | |
| 3482 | // -------------------------------------------------------------------- |
| 3483 | // Postconditions |
| 3484 | |
| 3485 | Case::Transition::verifyPostconditions(this); |
| 3486 | } |
| 3487 | |
| 3488 | TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) { |
| 3489 | using Case = SimplePrimaryDisplayCase; |
| 3490 | |
| 3491 | // -------------------------------------------------------------------- |
| 3492 | // Preconditions |
| 3493 | |
| 3494 | // A primary display device is set up |
| 3495 | Case::Display::injectHwcDisplay(this); |
| 3496 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 3497 | display.inject(); |
| 3498 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3499 | // The display is already set to PowerMode::ON |
| 3500 | display.mutableDisplayDevice()->setPowerMode(PowerMode::ON); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3501 | |
| 3502 | // -------------------------------------------------------------------- |
| 3503 | // Invocation |
| 3504 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3505 | mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::ON); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3506 | |
| 3507 | // -------------------------------------------------------------------- |
| 3508 | // Postconditions |
| 3509 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3510 | EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode()); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3511 | } |
| 3512 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 3513 | TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3514 | using Case = HwcVirtualDisplayCase; |
| 3515 | |
| 3516 | // -------------------------------------------------------------------- |
| 3517 | // Preconditions |
| 3518 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 3519 | // Insert display data so that the HWC thinks it created the virtual display. |
| 3520 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 3521 | ASSERT_TRUE(HalVirtualDisplayId::tryCast(displayId)); |
| 3522 | mFlinger.mutableHwcDisplayData().try_emplace(displayId); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3523 | |
| 3524 | // A virtual display device is set up |
| 3525 | Case::Display::injectHwcDisplay(this); |
| 3526 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 3527 | display.inject(); |
| 3528 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3529 | // The display is set to PowerMode::ON |
| 3530 | getDisplayDevice(display.token())->setPowerMode(PowerMode::ON); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3531 | |
| 3532 | // -------------------------------------------------------------------- |
| 3533 | // Invocation |
| 3534 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3535 | mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::OFF); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3536 | |
| 3537 | // -------------------------------------------------------------------- |
| 3538 | // Postconditions |
| 3539 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 3540 | EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode()); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) { |
| 3544 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>(); |
| 3545 | } |
| 3546 | |
| 3547 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) { |
| 3548 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>(); |
| 3549 | } |
| 3550 | |
| 3551 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) { |
| 3552 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>(); |
| 3553 | } |
| 3554 | |
| 3555 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) { |
| 3556 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>(); |
| 3557 | } |
| 3558 | |
| 3559 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) { |
| 3560 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>(); |
| 3561 | } |
| 3562 | |
| 3563 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) { |
| 3564 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>(); |
| 3565 | } |
| 3566 | |
| 3567 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) { |
| 3568 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>(); |
| 3569 | } |
| 3570 | |
| 3571 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) { |
| 3572 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>(); |
| 3573 | } |
| 3574 | |
| 3575 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) { |
| 3576 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>(); |
| 3577 | } |
| 3578 | |
| 3579 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) { |
| 3580 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>(); |
| 3581 | } |
| 3582 | |
| 3583 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) { |
| 3584 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>(); |
| 3585 | } |
| 3586 | |
| 3587 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) { |
| 3588 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>(); |
| 3589 | } |
| 3590 | |
| 3591 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) { |
| 3592 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>(); |
| 3593 | } |
| 3594 | |
| 3595 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) { |
| 3596 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>(); |
| 3597 | } |
| 3598 | |
| 3599 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) { |
| 3600 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>(); |
| 3601 | } |
| 3602 | |
| 3603 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) { |
| 3604 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>(); |
| 3605 | } |
| 3606 | |
| 3607 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) { |
| 3608 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>(); |
| 3609 | } |
| 3610 | |
| 3611 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) { |
| 3612 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>(); |
| 3613 | } |
| 3614 | |
| 3615 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) { |
| 3616 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>(); |
| 3617 | } |
| 3618 | |
| 3619 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) { |
| 3620 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>(); |
| 3621 | } |
| 3622 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 3623 | } // namespace |
| 3624 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 3625 | |
| 3626 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 3627 | #pragma clang diagnostic pop // ignored "-Wconversion" |