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 | |
| 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "LibSurfaceFlingerUnittests" |
| 19 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 20 | #include <type_traits> |
| 21 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 22 | #include <gmock/gmock.h> |
| 23 | #include <gtest/gtest.h> |
| 24 | |
| 25 | #include <log/log.h> |
| 26 | |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 27 | #include <ui/DebugUtils.h> |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 28 | |
| 29 | #include "DisplayIdentificationTest.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 30 | #include "TestableSurfaceFlinger.h" |
Lloyd Pique | cbe0001 | 2018-02-02 15:40:42 -0800 | [diff] [blame] | 31 | #include "mock/DisplayHardware/MockComposer.h" |
| 32 | #include "mock/DisplayHardware/MockDisplaySurface.h" |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 33 | #include "mock/MockDispSync.h" |
Lloyd Pique | cbe0001 | 2018-02-02 15:40:42 -0800 | [diff] [blame] | 34 | #include "mock/MockEventControlThread.h" |
| 35 | #include "mock/MockEventThread.h" |
| 36 | #include "mock/MockMessageQueue.h" |
| 37 | #include "mock/MockNativeWindowSurface.h" |
| 38 | #include "mock/MockSurfaceInterceptor.h" |
| 39 | #include "mock/RenderEngine/MockRenderEngine.h" |
| 40 | #include "mock/gui/MockGraphicBufferConsumer.h" |
| 41 | #include "mock/gui/MockGraphicBufferProducer.h" |
| 42 | #include "mock/system/window/MockNativeWindow.h" |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 43 | |
| 44 | namespace android { |
| 45 | namespace { |
| 46 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 47 | using testing::_; |
| 48 | using testing::ByMove; |
| 49 | using testing::DoAll; |
| 50 | using testing::Mock; |
| 51 | using testing::Return; |
| 52 | using testing::SetArgPointee; |
| 53 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 54 | using android::Hwc2::ColorMode; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 55 | using android::Hwc2::Error; |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 56 | using android::Hwc2::Hdr; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 57 | using android::Hwc2::IComposer; |
| 58 | using android::Hwc2::IComposerClient; |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 59 | using android::Hwc2::PerFrameMetadataKey; |
| 60 | using android::Hwc2::RenderIntent; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 61 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 62 | using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector; |
| 63 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 64 | using HotplugEvent = TestableSurfaceFlinger::HotplugEvent; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 65 | using HWC2Display = TestableSurfaceFlinger::HWC2Display; |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 66 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 67 | constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 68 | constexpr int32_t DEFAULT_DPI = 320; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 69 | constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 70 | |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 71 | constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value |
| 72 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 73 | /* ------------------------------------------------------------------------ |
| 74 | * Boolean avoidance |
| 75 | * |
| 76 | * To make calls and template instantiations more readable, we define some |
| 77 | * local enums along with an implicit bool conversion. |
| 78 | */ |
| 79 | |
| 80 | #define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true }; |
| 81 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 82 | BOOL_SUBSTITUTE(Async); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 83 | BOOL_SUBSTITUTE(Critical); |
| 84 | BOOL_SUBSTITUTE(Primary); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 85 | BOOL_SUBSTITUTE(Secure); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 86 | BOOL_SUBSTITUTE(Virtual); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 87 | |
| 88 | /* ------------------------------------------------------------------------ |
| 89 | * |
| 90 | */ |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 91 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 92 | class DisplayTransactionTest : public testing::Test { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 93 | public: |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 94 | DisplayTransactionTest(); |
| 95 | ~DisplayTransactionTest() override; |
| 96 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 97 | // -------------------------------------------------------------------- |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 98 | // Mock/Fake injection |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 99 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 100 | void injectMockComposer(int virtualDisplayCount); |
| 101 | void injectFakeBufferQueueFactory(); |
| 102 | void injectFakeNativeWindowSurfaceFactory(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 103 | |
| 104 | // -------------------------------------------------------------------- |
| 105 | // Postcondition helpers |
| 106 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 107 | bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 108 | bool hasTransactionFlagSet(int flag); |
| 109 | bool hasDisplayDevice(sp<IBinder> displayToken); |
| 110 | sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken); |
| 111 | bool hasCurrentDisplayState(sp<IBinder> displayToken); |
| 112 | const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken); |
| 113 | bool hasDrawingDisplayState(sp<IBinder> displayToken); |
| 114 | const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken); |
| 115 | |
| 116 | // -------------------------------------------------------------------- |
| 117 | // Test instances |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 118 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 119 | TestableSurfaceFlinger mFlinger; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 120 | mock::EventThread* mEventThread = new mock::EventThread(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 121 | mock::EventControlThread* mEventControlThread = new mock::EventControlThread(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 122 | |
| 123 | // These mocks are created by the test, but are destroyed by SurfaceFlinger |
| 124 | // by virtue of being stored into a std::unique_ptr. However we still need |
| 125 | // 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] | 126 | renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 127 | Hwc2::mock::Composer* mComposer = nullptr; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 128 | mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); |
| 129 | mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor(); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 130 | mock::DispSync* mPrimaryDispSync = new mock::DispSync(); |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 131 | |
| 132 | // These mocks are created only when expected to be created via a factory. |
| 133 | sp<mock::GraphicBufferConsumer> mConsumer; |
| 134 | sp<mock::GraphicBufferProducer> mProducer; |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 135 | surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 136 | sp<mock::NativeWindow> mNativeWindow; |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 137 | renderengine::mock::Surface* mRenderSurface = nullptr; |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | DisplayTransactionTest::DisplayTransactionTest() { |
| 141 | const ::testing::TestInfo* const test_info = |
| 142 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 143 | 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] | 144 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 145 | // Default to no wide color display support configured |
| 146 | mFlinger.mutableHasWideColorDisplay() = false; |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 147 | mFlinger.mutableUseColorManagement() = false; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 148 | mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; |
| 149 | |
| 150 | // Default to using HWC virtual displays |
| 151 | mFlinger.mutableUseHwcVirtualDisplays() = true; |
| 152 | |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 153 | mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) { |
| 154 | ADD_FAILURE() << "Unexpected request to create a buffer queue."; |
| 155 | }); |
| 156 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 157 | mFlinger.setCreateNativeWindowSurface([](auto) { |
| 158 | ADD_FAILURE() << "Unexpected request to create a native window surface."; |
| 159 | return nullptr; |
| 160 | }); |
| 161 | |
| 162 | mFlinger.mutableEventControlThread().reset(mEventControlThread); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 163 | mFlinger.mutableEventThread().reset(mEventThread); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 164 | mFlinger.mutableEventQueue().reset(mMessageQueue); |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 165 | mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 166 | mFlinger.mutableInterceptor().reset(mSurfaceInterceptor); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 167 | mFlinger.mutablePrimaryDispSync().reset(mPrimaryDispSync); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 168 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 169 | injectMockComposer(0); |
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("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 176 | } |
| 177 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 178 | void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) { |
| 179 | mComposer = new Hwc2::mock::Composer(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 180 | EXPECT_CALL(*mComposer, getCapabilities()) |
| 181 | .WillOnce(Return(std::vector<IComposer::Capability>())); |
| 182 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); |
| 183 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 184 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 185 | Mock::VerifyAndClear(mComposer); |
| 186 | } |
| 187 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 188 | void DisplayTransactionTest::injectFakeBufferQueueFactory() { |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 189 | // This setup is only expected once per test. |
| 190 | ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr); |
| 191 | |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 192 | mConsumer = new mock::GraphicBufferConsumer(); |
| 193 | mProducer = new mock::GraphicBufferProducer(); |
| 194 | |
| 195 | mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) { |
| 196 | *outProducer = mProducer; |
| 197 | *outConsumer = mConsumer; |
| 198 | }); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 199 | } |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 200 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 201 | void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() { |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 202 | // This setup is only expected once per test. |
| 203 | ASSERT_TRUE(mNativeWindowSurface == nullptr); |
| 204 | |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 205 | mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 206 | mNativeWindow = new mock::NativeWindow(); |
| 207 | |
Lloyd Pique | 2209836 | 2018-09-13 11:46:49 -0700 | [diff] [blame] | 208 | mFlinger.setCreateNativeWindowSurface([this](auto) { |
| 209 | return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface); |
| 210 | }); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 213 | bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) { |
| 214 | return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | bool DisplayTransactionTest::hasTransactionFlagSet(int flag) { |
| 218 | return mFlinger.mutableTransactionFlags() & flag; |
| 219 | } |
| 220 | |
| 221 | bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 222 | return mFlinger.mutableDisplays().count(displayToken) == 1; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) { |
Dominik Laskowski | 9fae102 | 2018-05-29 13:17:40 -0700 | [diff] [blame] | 226 | return mFlinger.mutableDisplays()[displayToken]; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) { |
| 230 | return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0; |
| 231 | } |
| 232 | |
| 233 | const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) { |
| 234 | return mFlinger.mutableCurrentState().displays.valueFor(displayToken); |
| 235 | } |
| 236 | |
| 237 | bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) { |
| 238 | return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0; |
| 239 | } |
| 240 | |
| 241 | const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) { |
| 242 | return mFlinger.mutableDrawingState().displays.valueFor(displayToken); |
| 243 | } |
| 244 | |
| 245 | /* ------------------------------------------------------------------------ |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 246 | * |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 247 | */ |
| 248 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 249 | template <typename PhysicalDisplay> |
| 250 | struct PhysicalDisplayId {}; |
| 251 | |
| 252 | template <DisplayId displayId> |
| 253 | using VirtualDisplayId = std::integral_constant<DisplayId, displayId>; |
| 254 | |
| 255 | struct NoDisplayId {}; |
| 256 | |
| 257 | template <typename> |
| 258 | struct IsPhysicalDisplayId : std::bool_constant<false> {}; |
| 259 | |
| 260 | template <typename PhysicalDisplay> |
| 261 | struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {}; |
| 262 | |
| 263 | template <typename> |
| 264 | struct DisplayIdGetter; |
| 265 | |
| 266 | template <typename PhysicalDisplay> |
| 267 | struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> { |
| 268 | static std::optional<DisplayId> get() { |
| 269 | if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) { |
| 270 | return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY) |
| 271 | ? HWC_DISPLAY_PRIMARY |
| 272 | : HWC_DISPLAY_EXTERNAL); |
| 273 | } |
| 274 | |
| 275 | const auto info = |
| 276 | parseDisplayIdentificationData(PhysicalDisplay::PORT, |
| 277 | PhysicalDisplay::GET_IDENTIFICATION_DATA()); |
| 278 | return info ? std::make_optional(info->id) : std::nullopt; |
| 279 | } |
| 280 | }; |
| 281 | |
| 282 | template <DisplayId displayId> |
| 283 | struct DisplayIdGetter<VirtualDisplayId<displayId>> { |
| 284 | static std::optional<DisplayId> get() { return displayId; } |
| 285 | }; |
| 286 | |
| 287 | template <> |
| 288 | struct DisplayIdGetter<NoDisplayId> { |
| 289 | static std::optional<DisplayId> get() { return {}; } |
| 290 | }; |
| 291 | |
| 292 | // DisplayIdType can be: |
| 293 | // 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC. |
| 294 | // 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC. |
| 295 | // 3) NoDisplayId for virtual display without HWC backing. |
| 296 | template <typename DisplayIdType, int width, int height, Critical critical, Async async, |
| 297 | Secure secure, Primary primary, int grallocUsage> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 298 | struct DisplayVariant { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 299 | using DISPLAY_ID = DisplayIdGetter<DisplayIdType>; |
| 300 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 301 | // The display width and height |
| 302 | static constexpr int WIDTH = width; |
| 303 | static constexpr int HEIGHT = height; |
| 304 | |
| 305 | static constexpr int GRALLOC_USAGE = grallocUsage; |
| 306 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 307 | // Whether the display is virtual or physical |
| 308 | static constexpr Virtual VIRTUAL = |
| 309 | IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 310 | |
| 311 | // When creating native window surfaces for the framebuffer, whether those should be critical |
| 312 | static constexpr Critical CRITICAL = critical; |
| 313 | |
| 314 | // When creating native window surfaces for the framebuffer, whether those should be async |
| 315 | static constexpr Async ASYNC = async; |
| 316 | |
| 317 | // Whether the display should be treated as secure |
| 318 | static constexpr Secure SECURE = secure; |
| 319 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 320 | // Whether the display is primary |
| 321 | static constexpr Primary PRIMARY = primary; |
| 322 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 323 | static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 324 | auto injector = |
| 325 | FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(), |
| 326 | static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY)); |
| 327 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 328 | injector.setSecure(static_cast<bool>(SECURE)); |
| 329 | return injector; |
| 330 | } |
| 331 | |
| 332 | // Called by tests to set up any native window creation call expectations. |
| 333 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 334 | EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow()) |
| 335 | .WillOnce(Return(test->mNativeWindow)); |
| 336 | EXPECT_CALL(*test->mNativeWindow, perform(19)).WillRepeatedly(Return(NO_ERROR)); |
| 337 | |
| 338 | // For simplicity, we only expect to create a single render surface for |
| 339 | // each test. |
| 340 | ASSERT_TRUE(test->mRenderSurface == nullptr); |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 341 | test->mRenderSurface = new renderengine::mock::Surface(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 342 | EXPECT_CALL(*test->mRenderEngine, createSurface()) |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 343 | .WillOnce(Return(ByMove( |
| 344 | std::unique_ptr<renderengine::Surface>(test->mRenderSurface)))); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 345 | EXPECT_CALL(*test->mRenderSurface, setAsync(static_cast<bool>(ASYNC))).Times(1); |
| 346 | EXPECT_CALL(*test->mRenderSurface, setCritical(static_cast<bool>(CRITICAL))).Times(1); |
| 347 | EXPECT_CALL(*test->mRenderSurface, setNativeWindow(test->mNativeWindow.get())).Times(1); |
Alec Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame] | 348 | EXPECT_CALL(*test->mRenderSurface, getWidth()).WillOnce(Return(WIDTH)); |
| 349 | EXPECT_CALL(*test->mRenderSurface, getHeight()).WillOnce(Return(HEIGHT)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) { |
| 353 | EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR)); |
| 354 | EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR)); |
| 355 | EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE)) |
| 356 | .WillRepeatedly(Return(NO_ERROR)); |
| 357 | EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT)) |
| 358 | .WillRepeatedly(Return(NO_ERROR)); |
| 359 | EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_)) |
| 360 | .WillRepeatedly(Return(NO_ERROR)); |
| 361 | } |
| 362 | |
| 363 | static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) { |
| 364 | EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return()); |
| 365 | } |
| 366 | }; |
| 367 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 368 | template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant, |
| 369 | typename PhysicalDisplay = void> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 370 | struct HwcDisplayVariant { |
| 371 | // The display id supplied by the HWC |
| 372 | static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId; |
| 373 | |
| 374 | // The HWC display type |
| 375 | static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType; |
| 376 | |
| 377 | // The HWC active configuration id |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 378 | static constexpr int HWC_ACTIVE_CONFIG_ID = 2001; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 379 | |
| 380 | static void injectPendingHotplugEvent(DisplayTransactionTest* test, |
| 381 | HWC2::Connection connection) { |
| 382 | test->mFlinger.mutablePendingHotplugEvents().emplace_back( |
| 383 | HotplugEvent{HWC_DISPLAY_ID, connection}); |
| 384 | } |
| 385 | |
| 386 | // Called by tests to inject a HWC display setup |
| 387 | static void injectHwcDisplay(DisplayTransactionTest* test) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 388 | const auto displayId = DisplayVariant::DISPLAY_ID::get(); |
| 389 | ASSERT_TRUE(displayId); |
| 390 | FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE, |
| 391 | static_cast<bool>(DisplayVariant::PRIMARY)) |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 392 | .setHwcDisplayId(HWC_DISPLAY_ID) |
| 393 | .setWidth(DisplayVariant::WIDTH) |
| 394 | .setHeight(DisplayVariant::HEIGHT) |
| 395 | .setActiveConfig(HWC_ACTIVE_CONFIG_ID) |
| 396 | .inject(&test->mFlinger, test->mComposer); |
| 397 | } |
| 398 | |
| 399 | static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) { |
| 400 | EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _)) |
| 401 | .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>( |
| 402 | HWC_DISPLAY_TYPE)), |
| 403 | Return(Error::NONE))); |
| 404 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); |
| 405 | EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _)) |
| 406 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}), |
| 407 | Return(Error::NONE))); |
| 408 | EXPECT_CALL(*test->mComposer, |
| 409 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 410 | IComposerClient::Attribute::WIDTH, _)) |
| 411 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE))); |
| 412 | EXPECT_CALL(*test->mComposer, |
| 413 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 414 | IComposerClient::Attribute::HEIGHT, _)) |
| 415 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE))); |
| 416 | EXPECT_CALL(*test->mComposer, |
| 417 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 418 | IComposerClient::Attribute::VSYNC_PERIOD, _)) |
| 419 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE))); |
| 420 | EXPECT_CALL(*test->mComposer, |
| 421 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 422 | IComposerClient::Attribute::DPI_X, _)) |
| 423 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); |
| 424 | EXPECT_CALL(*test->mComposer, |
| 425 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 426 | IComposerClient::Attribute::DPI_Y, _)) |
| 427 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 428 | |
| 429 | if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) { |
| 430 | EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _)) |
| 431 | .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT), |
| 432 | SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()), |
| 433 | Return(Error::NONE))); |
| 434 | } else { |
| 435 | EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _)) |
| 436 | .WillOnce(Return(Error::UNSUPPORTED)); |
| 437 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | // Called by tests to set up HWC call expectations |
| 441 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { |
| 442 | EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _)) |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 443 | .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE))); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 444 | } |
| 445 | }; |
| 446 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 447 | // Physical displays are expected to be synchronous, secure, and have a HWC display for output. |
| 448 | constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY = |
| 449 | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB; |
| 450 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 451 | template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height, |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 452 | Critical critical> |
| 453 | struct PhysicalDisplayVariant |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 454 | : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE, |
| 455 | Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>, |
| 456 | HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical, |
| 457 | DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, |
| 458 | critical, Async::FALSE, Secure::TRUE, |
| 459 | PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>, |
| 460 | PhysicalDisplay> {}; |
| 461 | |
| 462 | template <bool hasIdentificationData> |
| 463 | struct PrimaryDisplay { |
| 464 | static constexpr Primary PRIMARY = Primary::TRUE; |
| 465 | static constexpr uint8_t PORT = 255; |
| 466 | static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData; |
| 467 | static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid; |
| 468 | }; |
| 469 | |
| 470 | template <bool hasIdentificationData> |
| 471 | struct ExternalDisplay { |
| 472 | static constexpr Primary PRIMARY = Primary::FALSE; |
| 473 | static constexpr uint8_t PORT = 254; |
| 474 | static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData; |
| 475 | static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid; |
| 476 | }; |
| 477 | |
| 478 | struct TertiaryDisplay { |
| 479 | static constexpr Primary PRIMARY = Primary::FALSE; |
| 480 | }; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 481 | |
| 482 | // A primary display is a physical display that is critical |
| 483 | using PrimaryDisplayVariant = |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 484 | PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 485 | |
| 486 | // An external display is physical display that is not critical. |
| 487 | using ExternalDisplayVariant = |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 488 | PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 489 | |
| 490 | using TertiaryDisplayVariant = |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 491 | PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 492 | |
| 493 | // A virtual display not supported by the HWC. |
| 494 | constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0; |
| 495 | |
| 496 | template <int width, int height, Secure secure> |
| 497 | struct NonHwcVirtualDisplayVariant |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 498 | : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure, |
| 499 | Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> { |
| 500 | using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure, |
| 501 | Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>; |
| 502 | |
| 503 | static void injectHwcDisplay(DisplayTransactionTest*) {} |
| 504 | |
| 505 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { |
| 506 | EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0); |
| 507 | } |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 508 | |
| 509 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 510 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); |
| 511 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); |
| 512 | } |
| 513 | }; |
| 514 | |
| 515 | // A virtual display supported by the HWC. |
| 516 | constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER; |
| 517 | |
| 518 | template <int width, int height, Secure secure> |
| 519 | struct HwcVirtualDisplayVariant |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 520 | : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure, |
| 521 | Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>, |
| 522 | HwcDisplayVariant< |
| 523 | 1010, HWC2::DisplayType::Virtual, |
| 524 | DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, |
| 525 | secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> { |
| 526 | using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, |
| 527 | secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 528 | using Self = HwcVirtualDisplayVariant<width, height, secure>; |
| 529 | |
| 530 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 531 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); |
| 532 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); |
| 533 | } |
| 534 | |
| 535 | static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) { |
| 536 | EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _)) |
| 537 | .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE))); |
| 538 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); |
| 539 | } |
| 540 | }; |
| 541 | |
| 542 | // For this variant, SurfaceFlinger should not configure itself with wide |
| 543 | // display support, so the display should not be configured for wide-color |
| 544 | // support. |
| 545 | struct WideColorSupportNotConfiguredVariant { |
| 546 | static constexpr bool WIDE_COLOR_SUPPORTED = false; |
| 547 | |
| 548 | static void injectConfigChange(DisplayTransactionTest* test) { |
| 549 | test->mFlinger.mutableHasWideColorDisplay() = false; |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 550 | test->mFlinger.mutableUseColorManagement() = false; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 551 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; |
| 552 | } |
| 553 | |
| 554 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 555 | EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0); |
| 556 | EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0); |
| 557 | EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0); |
| 558 | } |
| 559 | }; |
| 560 | |
| 561 | // For this variant, SurfaceFlinger should configure itself with wide display |
| 562 | // support, and the display should respond with an non-empty list of supported |
| 563 | // color modes. Wide-color support should be configured. |
| 564 | template <typename Display> |
| 565 | struct WideColorP3ColorimetricSupportedVariant { |
| 566 | static constexpr bool WIDE_COLOR_SUPPORTED = true; |
| 567 | |
| 568 | static void injectConfigChange(DisplayTransactionTest* test) { |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 569 | test->mFlinger.mutableUseColorManagement() = true; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 570 | test->mFlinger.mutableHasWideColorDisplay() = true; |
| 571 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; |
| 572 | } |
| 573 | |
| 574 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 575 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) |
| 576 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})), |
| 577 | Return(Error::NONE))); |
| 578 | EXPECT_CALL(*test->mComposer, |
| 579 | getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _)) |
| 580 | .WillOnce(DoAll(SetArgPointee<2>( |
| 581 | std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})), |
| 582 | Return(Error::NONE))); |
| 583 | EXPECT_CALL(*test->mComposer, |
| 584 | setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB, |
| 585 | RenderIntent::COLORIMETRIC)) |
| 586 | .WillOnce(Return(Error::NONE)); |
| 587 | } |
| 588 | }; |
| 589 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 590 | // For this variant, SurfaceFlinger should configure itself with wide display |
| 591 | // support, but the display should respond with an empty list of supported color |
| 592 | // modes. Wide-color support for the display should not be configured. |
| 593 | template <typename Display> |
| 594 | struct WideColorNotSupportedVariant { |
| 595 | static constexpr bool WIDE_COLOR_SUPPORTED = false; |
| 596 | |
| 597 | static void injectConfigChange(DisplayTransactionTest* test) { |
Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 598 | test->mFlinger.mutableUseColorManagement() = true; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 599 | test->mFlinger.mutableHasWideColorDisplay() = true; |
| 600 | } |
| 601 | |
| 602 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 603 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) |
| 604 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE))); |
Chia-I Wu | 614e142 | 2018-05-23 02:17:03 -0700 | [diff] [blame] | 605 | EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 606 | } |
| 607 | }; |
| 608 | |
| 609 | // For this variant, the display is not a HWC display, so no HDR support should |
| 610 | // be configured. |
| 611 | struct NonHwcDisplayHdrSupportVariant { |
| 612 | static constexpr bool HDR10_SUPPORTED = false; |
| 613 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 614 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 615 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 616 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0); |
| 617 | } |
| 618 | }; |
| 619 | |
| 620 | // For this variant, the composer should respond with a non-empty list of HDR |
| 621 | // modes containing HDR10, so HDR10 support should be configured. |
| 622 | template <typename Display> |
| 623 | struct Hdr10SupportedVariant { |
| 624 | static constexpr bool HDR10_SUPPORTED = true; |
| 625 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 626 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 627 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 628 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 629 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})), |
| 630 | Return(Error::NONE))); |
| 631 | } |
| 632 | }; |
| 633 | |
| 634 | // For this variant, the composer should respond with a non-empty list of HDR |
| 635 | // modes containing HLG, so HLG support should be configured. |
| 636 | template <typename Display> |
| 637 | struct HdrHlgSupportedVariant { |
| 638 | static constexpr bool HDR10_SUPPORTED = false; |
| 639 | static constexpr bool HDR_HLG_SUPPORTED = true; |
| 640 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 641 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 642 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 643 | .WillOnce( |
| 644 | DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE))); |
| 645 | } |
| 646 | }; |
| 647 | |
| 648 | // For this variant, the composer should respond with a non-empty list of HDR |
| 649 | // modes containing DOLBY_VISION, so DOLBY_VISION support should be configured. |
| 650 | template <typename Display> |
| 651 | struct HdrDolbyVisionSupportedVariant { |
| 652 | static constexpr bool HDR10_SUPPORTED = false; |
| 653 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 654 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true; |
| 655 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 656 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 657 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})), |
| 658 | Return(Error::NONE))); |
| 659 | } |
| 660 | }; |
| 661 | |
| 662 | // For this variant, the composer should respond with am empty list of HDR |
| 663 | // modes, so no HDR support should be configured. |
| 664 | template <typename Display> |
| 665 | struct HdrNotSupportedVariant { |
| 666 | static constexpr bool HDR10_SUPPORTED = false; |
| 667 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 668 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 669 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 670 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 671 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE))); |
| 672 | } |
| 673 | }; |
| 674 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 675 | struct NonHwcPerFrameMetadataSupportVariant { |
| 676 | static constexpr int PER_FRAME_METADATA_KEYS = 0; |
| 677 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 678 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 679 | } |
| 680 | }; |
| 681 | |
| 682 | template <typename Display> |
| 683 | struct NoPerFrameMetadataSupportVariant { |
| 684 | static constexpr int PER_FRAME_METADATA_KEYS = 0; |
| 685 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 686 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 687 | .WillOnce(Return(std::vector<PerFrameMetadataKey>())); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 688 | } |
| 689 | }; |
| 690 | |
| 691 | template <typename Display> |
| 692 | struct Smpte2086PerFrameMetadataSupportVariant { |
| 693 | static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086; |
| 694 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 695 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 696 | .WillOnce(Return(std::vector<PerFrameMetadataKey>({ |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 697 | PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, |
| 698 | PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, |
| 699 | PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, |
| 700 | PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, |
| 701 | PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, |
| 702 | PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, |
| 703 | PerFrameMetadataKey::WHITE_POINT_X, |
| 704 | PerFrameMetadataKey::WHITE_POINT_Y, |
| 705 | PerFrameMetadataKey::MAX_LUMINANCE, |
| 706 | PerFrameMetadataKey::MIN_LUMINANCE, |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 707 | }))); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 708 | } |
| 709 | }; |
| 710 | |
| 711 | template <typename Display> |
| 712 | struct Cta861_3_PerFrameMetadataSupportVariant { |
| 713 | static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3; |
| 714 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 715 | EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID)) |
| 716 | .WillOnce(Return(std::vector<PerFrameMetadataKey>({ |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 717 | PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, |
| 718 | PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, |
Chia-I Wu | d7e01d7 | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 719 | }))); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 720 | } |
| 721 | }; |
| 722 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 723 | /* ------------------------------------------------------------------------ |
| 724 | * Typical display configurations to test |
| 725 | */ |
| 726 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 727 | template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy, |
| 728 | typename PerFrameMetadataSupportPolicy> |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 729 | struct Case { |
| 730 | using Display = DisplayPolicy; |
| 731 | using WideColorSupport = WideColorSupportPolicy; |
| 732 | using HdrSupport = HdrSupportPolicy; |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 733 | using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 734 | }; |
| 735 | |
| 736 | using SimplePrimaryDisplayCase = |
| 737 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 738 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 739 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 740 | using SimpleExternalDisplayCase = |
| 741 | Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 742 | HdrNotSupportedVariant<ExternalDisplayVariant>, |
| 743 | NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 744 | using SimpleTertiaryDisplayCase = |
| 745 | Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 746 | HdrNotSupportedVariant<TertiaryDisplayVariant>, |
| 747 | NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 748 | using NonHwcVirtualDisplayCase = |
| 749 | Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 750 | WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant, |
| 751 | NonHwcPerFrameMetadataSupportVariant>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 752 | using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>; |
| 753 | using HwcVirtualDisplayCase = |
| 754 | Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant, |
Lloyd Pique | 438e9e7 | 2018-09-04 18:06:08 -0700 | [diff] [blame] | 755 | HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>, |
tangrobin | 6753a02 | 2018-08-10 10:58:54 +0800 | [diff] [blame] | 756 | NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 757 | using WideColorP3ColorimetricDisplayCase = |
| 758 | Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 759 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 760 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 761 | using Hdr10DisplayCase = |
| 762 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 763 | Hdr10SupportedVariant<PrimaryDisplayVariant>, |
| 764 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 765 | using HdrHlgDisplayCase = |
| 766 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 767 | HdrHlgSupportedVariant<PrimaryDisplayVariant>, |
| 768 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 769 | using HdrDolbyVisionDisplayCase = |
| 770 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 771 | HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>, |
| 772 | NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
| 773 | using HdrSmpte2086DisplayCase = |
| 774 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 775 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 776 | Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
| 777 | using HdrCta861_3_DisplayCase = |
| 778 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 779 | HdrNotSupportedVariant<PrimaryDisplayVariant>, |
| 780 | Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>; |
Dominik Laskowski | f07b85b | 2018-06-11 12:49:15 -0700 | [diff] [blame] | 781 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 782 | /* ------------------------------------------------------------------------ |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 783 | * |
| 784 | * SurfaceFlinger::onHotplugReceived |
| 785 | */ |
| 786 | |
| 787 | TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) { |
| 788 | constexpr int currentSequenceId = 123; |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 789 | constexpr hwc2_display_t hwcDisplayId1 = 456; |
| 790 | constexpr hwc2_display_t hwcDisplayId2 = 654; |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 791 | |
| 792 | // -------------------------------------------------------------------- |
| 793 | // Preconditions |
| 794 | |
| 795 | // Set the current sequence id for accepted events |
| 796 | mFlinger.mutableComposerSequenceId() = currentSequenceId; |
| 797 | |
| 798 | // Set the main thread id so that the current thread does not appear to be |
| 799 | // the main thread. |
| 800 | mFlinger.mutableMainThreadId() = std::thread::id(); |
| 801 | |
| 802 | // -------------------------------------------------------------------- |
| 803 | // Call Expectations |
| 804 | |
| 805 | // We expect invalidate() to be invoked once to trigger display transaction |
| 806 | // processing. |
| 807 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 808 | |
| 809 | // -------------------------------------------------------------------- |
| 810 | // Invocation |
| 811 | |
| 812 | // Simulate two hotplug events (a connect and a disconnect) |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 813 | mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected); |
| 814 | mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 815 | |
| 816 | // -------------------------------------------------------------------- |
| 817 | // Postconditions |
| 818 | |
| 819 | // The display transaction needed flag should be set. |
| 820 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 821 | |
| 822 | // All events should be in the pending event queue. |
| 823 | const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents(); |
| 824 | ASSERT_EQ(2u, pendingEvents.size()); |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 825 | EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 826 | EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection); |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 827 | EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId); |
Lloyd Pique | 6cf1103 | 2018-01-22 18:57:44 -0800 | [diff] [blame] | 828 | EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection); |
| 829 | } |
| 830 | |
| 831 | TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) { |
| 832 | constexpr int currentSequenceId = 123; |
| 833 | constexpr int otherSequenceId = 321; |
| 834 | constexpr hwc2_display_t displayId = 456; |
| 835 | |
| 836 | // -------------------------------------------------------------------- |
| 837 | // Preconditions |
| 838 | |
| 839 | // Set the current sequence id for accepted events |
| 840 | mFlinger.mutableComposerSequenceId() = currentSequenceId; |
| 841 | |
| 842 | // Set the main thread id so that the current thread does not appear to be |
| 843 | // the main thread. |
| 844 | mFlinger.mutableMainThreadId() = std::thread::id(); |
| 845 | |
| 846 | // -------------------------------------------------------------------- |
| 847 | // Call Expectations |
| 848 | |
| 849 | // We do not expect any calls to invalidate(). |
| 850 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(0); |
| 851 | |
| 852 | // -------------------------------------------------------------------- |
| 853 | // Invocation |
| 854 | |
| 855 | // Call with an unexpected sequence id |
| 856 | mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid); |
| 857 | |
| 858 | // -------------------------------------------------------------------- |
| 859 | // Postconditions |
| 860 | |
| 861 | // The display transaction needed flag should not be set |
| 862 | EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 863 | |
| 864 | // There should be no pending events |
| 865 | EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty()); |
| 866 | } |
| 867 | |
| 868 | TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) { |
| 869 | constexpr int currentSequenceId = 123; |
| 870 | constexpr hwc2_display_t displayId1 = 456; |
| 871 | |
| 872 | // -------------------------------------------------------------------- |
| 873 | // Note: |
| 874 | // -------------------------------------------------------------------- |
| 875 | // This test case is a bit tricky. We want to verify that |
| 876 | // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we |
| 877 | // don't really want to provide coverage for everything the later function |
| 878 | // does as there are specific tests for it. |
| 879 | // -------------------------------------------------------------------- |
| 880 | |
| 881 | // -------------------------------------------------------------------- |
| 882 | // Preconditions |
| 883 | |
| 884 | // Set the current sequence id for accepted events |
| 885 | mFlinger.mutableComposerSequenceId() = currentSequenceId; |
| 886 | |
| 887 | // Set the main thread id so that the current thread does appear to be the |
| 888 | // main thread. |
| 889 | mFlinger.mutableMainThreadId() = std::this_thread::get_id(); |
| 890 | |
| 891 | // -------------------------------------------------------------------- |
| 892 | // Call Expectations |
| 893 | |
| 894 | // We expect invalidate() to be invoked once to trigger display transaction |
| 895 | // processing. |
| 896 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 897 | |
| 898 | // -------------------------------------------------------------------- |
| 899 | // Invocation |
| 900 | |
| 901 | // Simulate a disconnect on a display id that is not connected. This should |
| 902 | // be enqueued by onHotplugReceived(), and dequeued by |
| 903 | // processDisplayHotplugEventsLocked(), but then ignored as invalid. |
| 904 | mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected); |
| 905 | |
| 906 | // -------------------------------------------------------------------- |
| 907 | // Postconditions |
| 908 | |
| 909 | // The display transaction needed flag should be set. |
| 910 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 911 | |
| 912 | // There should be no event queued on return, as it should have been |
| 913 | // processed. |
| 914 | EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty()); |
| 915 | } |
| 916 | |
| 917 | /* ------------------------------------------------------------------------ |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 918 | * SurfaceFlinger::createDisplay |
| 919 | */ |
| 920 | |
| 921 | TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) { |
| 922 | const String8 name("virtual.test"); |
| 923 | |
| 924 | // -------------------------------------------------------------------- |
| 925 | // Call Expectations |
| 926 | |
| 927 | // The call should notify the interceptor that a display was created. |
| 928 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
| 929 | |
| 930 | // -------------------------------------------------------------------- |
| 931 | // Invocation |
| 932 | |
| 933 | sp<IBinder> displayToken = mFlinger.createDisplay(name, false); |
| 934 | |
| 935 | // -------------------------------------------------------------------- |
| 936 | // Postconditions |
| 937 | |
| 938 | // The display should have been added to the current state |
| 939 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 940 | const auto& display = getCurrentDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 941 | EXPECT_TRUE(display.isVirtual()); |
| 942 | EXPECT_FALSE(display.isSecure); |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 943 | EXPECT_EQ(name.string(), display.displayName); |
| 944 | |
| 945 | // -------------------------------------------------------------------- |
| 946 | // Cleanup conditions |
| 947 | |
| 948 | // Destroying the display invalidates the display state. |
| 949 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 950 | } |
| 951 | |
| 952 | TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) { |
| 953 | const String8 name("virtual.test"); |
| 954 | |
| 955 | // -------------------------------------------------------------------- |
| 956 | // Call Expectations |
| 957 | |
| 958 | // The call should notify the interceptor that a display was created. |
| 959 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
| 960 | |
| 961 | // -------------------------------------------------------------------- |
| 962 | // Invocation |
| 963 | |
| 964 | sp<IBinder> displayToken = mFlinger.createDisplay(name, true); |
| 965 | |
| 966 | // -------------------------------------------------------------------- |
| 967 | // Postconditions |
| 968 | |
| 969 | // The display should have been added to the current state |
| 970 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 971 | const auto& display = getCurrentDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 972 | EXPECT_TRUE(display.isVirtual()); |
| 973 | EXPECT_TRUE(display.isSecure); |
Lloyd Pique | a482f99 | 2018-01-22 19:00:34 -0800 | [diff] [blame] | 974 | EXPECT_EQ(name.string(), display.displayName); |
| 975 | |
| 976 | // -------------------------------------------------------------------- |
| 977 | // Cleanup conditions |
| 978 | |
| 979 | // Destroying the display invalidates the display state. |
| 980 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 981 | } |
| 982 | |
| 983 | /* ------------------------------------------------------------------------ |
| 984 | * SurfaceFlinger::destroyDisplay |
| 985 | */ |
| 986 | |
| 987 | TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) { |
| 988 | using Case = NonHwcVirtualDisplayCase; |
| 989 | |
| 990 | // -------------------------------------------------------------------- |
| 991 | // Preconditions |
| 992 | |
| 993 | // A virtual display exists |
| 994 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 995 | existing.inject(); |
| 996 | |
| 997 | // -------------------------------------------------------------------- |
| 998 | // Call Expectations |
| 999 | |
| 1000 | // The call should notify the interceptor that a display was created. |
| 1001 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1); |
| 1002 | |
| 1003 | // Destroying the display invalidates the display state. |
| 1004 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 1005 | |
| 1006 | // -------------------------------------------------------------------- |
| 1007 | // Invocation |
| 1008 | |
| 1009 | mFlinger.destroyDisplay(existing.token()); |
| 1010 | |
| 1011 | // -------------------------------------------------------------------- |
| 1012 | // Postconditions |
| 1013 | |
| 1014 | // The display should have been removed from the current state |
| 1015 | EXPECT_FALSE(hasCurrentDisplayState(existing.token())); |
| 1016 | |
| 1017 | // Ths display should still exist in the drawing state |
| 1018 | EXPECT_TRUE(hasDrawingDisplayState(existing.token())); |
| 1019 | |
| 1020 | // The display transaction needed flasg should be set |
| 1021 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 1022 | } |
| 1023 | |
| 1024 | TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) { |
| 1025 | // -------------------------------------------------------------------- |
| 1026 | // Preconditions |
| 1027 | |
| 1028 | sp<BBinder> displayToken = new BBinder(); |
| 1029 | |
| 1030 | // -------------------------------------------------------------------- |
| 1031 | // Invocation |
| 1032 | |
| 1033 | mFlinger.destroyDisplay(displayToken); |
| 1034 | } |
| 1035 | |
| 1036 | /* ------------------------------------------------------------------------ |
Lloyd Pique | d6fbb8a | 2018-01-22 19:08:36 -0800 | [diff] [blame] | 1037 | * SurfaceFlinger::resetDisplayState |
| 1038 | */ |
| 1039 | |
| 1040 | TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) { |
| 1041 | using Case = NonHwcVirtualDisplayCase; |
| 1042 | |
| 1043 | // -------------------------------------------------------------------- |
| 1044 | // Preconditions |
| 1045 | |
| 1046 | // vsync is enabled and available |
| 1047 | mFlinger.mutablePrimaryHWVsyncEnabled() = true; |
| 1048 | mFlinger.mutableHWVsyncAvailable() = true; |
| 1049 | |
| 1050 | // A display exists |
| 1051 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1052 | existing.inject(); |
| 1053 | |
| 1054 | // -------------------------------------------------------------------- |
| 1055 | // Call Expectations |
| 1056 | |
| 1057 | // The call disable vsyncs |
| 1058 | EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1); |
| 1059 | |
| 1060 | // The call clears the current render engine surface |
| 1061 | EXPECT_CALL(*mRenderEngine, resetCurrentSurface()); |
| 1062 | |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 1063 | // The call ends any display resyncs |
| 1064 | EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1); |
| 1065 | |
Lloyd Pique | d6fbb8a | 2018-01-22 19:08:36 -0800 | [diff] [blame] | 1066 | // -------------------------------------------------------------------- |
| 1067 | // Invocation |
| 1068 | |
| 1069 | mFlinger.resetDisplayState(); |
| 1070 | |
| 1071 | // -------------------------------------------------------------------- |
| 1072 | // Postconditions |
| 1073 | |
| 1074 | // vsyncs should be off and not available. |
| 1075 | EXPECT_FALSE(mFlinger.mutablePrimaryHWVsyncEnabled()); |
| 1076 | EXPECT_FALSE(mFlinger.mutableHWVsyncAvailable()); |
| 1077 | |
| 1078 | // The display should have been removed from the display map. |
| 1079 | EXPECT_FALSE(hasDisplayDevice(existing.token())); |
| 1080 | |
| 1081 | // The display should still exist in the current state |
| 1082 | EXPECT_TRUE(hasCurrentDisplayState(existing.token())); |
| 1083 | |
| 1084 | // The display should have been removed from the drawing state |
| 1085 | EXPECT_FALSE(hasDrawingDisplayState(existing.token())); |
| 1086 | } |
| 1087 | |
| 1088 | /* ------------------------------------------------------------------------ |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1089 | * DisplayDevice::GetBestColorMode |
| 1090 | */ |
| 1091 | class GetBestColorModeTest : public DisplayTransactionTest { |
| 1092 | public: |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1093 | static constexpr DisplayId DEFAULT_DISPLAY_ID = 777; |
| 1094 | |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1095 | GetBestColorModeTest() |
| 1096 | : DisplayTransactionTest(), |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1097 | mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */, |
| 1098 | true /* isPrimary */)) {} |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 1099 | |
| 1100 | void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; } |
| 1101 | |
| 1102 | void addHwcColorModesMapping(ui::ColorMode colorMode, |
| 1103 | std::vector<ui::RenderIntent> renderIntents) { |
| 1104 | mHwcColorModes[colorMode] = renderIntents; |
| 1105 | } |
| 1106 | |
| 1107 | void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; } |
| 1108 | |
| 1109 | void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; } |
| 1110 | |
| 1111 | void getBestColorMode() { |
| 1112 | mInjector.setHwcColorModes(mHwcColorModes); |
| 1113 | mInjector.setHasWideColorGamut(mHasWideColorGamut); |
| 1114 | auto displayDevice = mInjector.inject(); |
| 1115 | |
| 1116 | displayDevice->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace, |
| 1117 | &mOutColorMode, &mOutRenderIntent); |
| 1118 | } |
| 1119 | |
| 1120 | ui::Dataspace mOutDataspace; |
| 1121 | ui::ColorMode mOutColorMode; |
| 1122 | ui::RenderIntent mOutRenderIntent; |
| 1123 | |
| 1124 | private: |
| 1125 | ui::Dataspace mInputDataspace; |
| 1126 | ui::RenderIntent mInputRenderIntent; |
| 1127 | bool mHasWideColorGamut = false; |
| 1128 | std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes; |
| 1129 | FakeDisplayDeviceInjector mInjector; |
| 1130 | }; |
| 1131 | |
| 1132 | TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) { |
| 1133 | addHwcColorModesMapping(ui::ColorMode::SRGB, |
| 1134 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1135 | setInputDataspace(ui::Dataspace::DISPLAY_P3); |
| 1136 | setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); |
| 1137 | setHasWideColorGamut(true); |
| 1138 | |
| 1139 | getBestColorMode(); |
| 1140 | |
| 1141 | ASSERT_EQ(ui::Dataspace::SRGB, mOutDataspace); |
| 1142 | ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode); |
| 1143 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); |
| 1144 | } |
| 1145 | |
| 1146 | TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) { |
| 1147 | addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3, |
| 1148 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1149 | addHwcColorModesMapping(ui::ColorMode::SRGB, |
| 1150 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1151 | addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020, |
| 1152 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1153 | setInputDataspace(ui::Dataspace::DISPLAY_P3); |
| 1154 | setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); |
| 1155 | setHasWideColorGamut(true); |
| 1156 | |
| 1157 | getBestColorMode(); |
| 1158 | |
| 1159 | ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace); |
| 1160 | ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode); |
| 1161 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); |
| 1162 | } |
| 1163 | |
| 1164 | TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) { |
| 1165 | addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020, |
| 1166 | std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC)); |
| 1167 | setInputDataspace(ui::Dataspace::DISPLAY_P3); |
| 1168 | setInputRenderIntent(ui::RenderIntent::COLORIMETRIC); |
| 1169 | setHasWideColorGamut(true); |
| 1170 | |
| 1171 | getBestColorMode(); |
| 1172 | |
| 1173 | ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace); |
| 1174 | ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode); |
| 1175 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent); |
| 1176 | } |
| 1177 | |
| 1178 | /* ------------------------------------------------------------------------ |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1179 | * SurfaceFlinger::setupNewDisplayDeviceInternal |
| 1180 | */ |
| 1181 | |
| 1182 | class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest { |
| 1183 | public: |
| 1184 | template <typename T> |
| 1185 | void setupNewDisplayDeviceInternalTest(); |
| 1186 | }; |
| 1187 | |
| 1188 | template <typename Case> |
| 1189 | void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() { |
| 1190 | const sp<BBinder> displayToken = new BBinder(); |
| 1191 | const sp<mock::DisplaySurface> displaySurface = new mock::DisplaySurface(); |
| 1192 | const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1193 | |
| 1194 | // -------------------------------------------------------------------- |
| 1195 | // Preconditions |
| 1196 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1197 | // Wide color displays support is configured appropriately |
| 1198 | Case::WideColorSupport::injectConfigChange(this); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1199 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1200 | // The display is setup with the HWC. |
| 1201 | Case::Display::injectHwcDisplay(this); |
| 1202 | |
| 1203 | // SurfaceFlinger will use a test-controlled factory for native window |
| 1204 | // surfaces. |
| 1205 | injectFakeNativeWindowSurfaceFactory(); |
| 1206 | |
| 1207 | // -------------------------------------------------------------------- |
| 1208 | // Call Expectations |
| 1209 | |
| 1210 | // Various native window calls will be made. |
| 1211 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 1212 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1213 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 1214 | Case::HdrSupport::setupComposerCallExpectations(this); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1215 | Case::PerFrameMetadataSupport::setupComposerCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1216 | |
| 1217 | // -------------------------------------------------------------------- |
| 1218 | // Invocation |
| 1219 | |
| 1220 | DisplayDeviceState state; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1221 | state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt |
| 1222 | : Case::Display::DISPLAY_ID::get(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1223 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
| 1224 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1225 | auto device = |
| 1226 | mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(), |
| 1227 | state, displaySurface, producer); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1228 | |
| 1229 | // -------------------------------------------------------------------- |
| 1230 | // Postconditions |
| 1231 | |
| 1232 | ASSERT_TRUE(device != nullptr); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1233 | EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId()); |
| 1234 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1235 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1236 | EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1237 | EXPECT_EQ(Case::Display::WIDTH, device->getWidth()); |
| 1238 | EXPECT_EQ(Case::Display::HEIGHT, device->getHeight()); |
| 1239 | EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut()); |
| 1240 | EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support()); |
| 1241 | EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport()); |
| 1242 | EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport()); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 1243 | // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are |
| 1244 | // remapped, and the test only ever sets up one config. If there were an error |
| 1245 | // looking up the remapped index, device->getActiveConfig() would be -1 instead. |
| 1246 | EXPECT_EQ(0, device->getActiveConfig()); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1247 | EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS, |
| 1248 | device->getSupportedPerFrameMetadata()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) { |
| 1252 | setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>(); |
| 1253 | } |
| 1254 | |
| 1255 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) { |
| 1256 | setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>(); |
| 1257 | } |
| 1258 | |
| 1259 | TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) { |
| 1260 | setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>(); |
| 1261 | } |
| 1262 | |
| 1263 | TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1264 | using Case = HwcVirtualDisplayCase; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1265 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1266 | // Insert display data so that the HWC thinks it created the virtual display. |
| 1267 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1268 | ASSERT_TRUE(displayId); |
| 1269 | mFlinger.mutableHwcDisplayData()[*displayId] = {}; |
| 1270 | |
| 1271 | setupNewDisplayDeviceInternalTest<Case>(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) { |
| 1275 | setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>(); |
| 1276 | } |
| 1277 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1278 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) { |
| 1279 | setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>(); |
| 1280 | } |
| 1281 | |
| 1282 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) { |
| 1283 | setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>(); |
| 1284 | } |
| 1285 | |
| 1286 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) { |
| 1287 | setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>(); |
| 1288 | } |
| 1289 | |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1290 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) { |
| 1291 | setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>(); |
| 1292 | } |
| 1293 | |
| 1294 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) { |
| 1295 | setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>(); |
| 1296 | } |
| 1297 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1298 | /* ------------------------------------------------------------------------ |
| 1299 | * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded) |
| 1300 | */ |
| 1301 | |
| 1302 | class HandleTransactionLockedTest : public DisplayTransactionTest { |
| 1303 | public: |
| 1304 | template <typename Case> |
| 1305 | void setupCommonPreconditions(); |
| 1306 | |
| 1307 | template <typename Case> |
| 1308 | void setupCommonCallExpectationsForConnectProcessing(); |
| 1309 | |
| 1310 | template <typename Case> |
| 1311 | void setupCommonCallExpectationsForDisconnectProcessing(); |
| 1312 | |
| 1313 | template <typename Case> |
| 1314 | void processesHotplugConnectCommon(); |
| 1315 | |
| 1316 | template <typename Case> |
| 1317 | void ignoresHotplugConnectCommon(); |
| 1318 | |
| 1319 | template <typename Case> |
| 1320 | void processesHotplugDisconnectCommon(); |
| 1321 | |
| 1322 | template <typename Case> |
| 1323 | void verifyDisplayIsConnected(const sp<IBinder>& displayToken); |
| 1324 | |
| 1325 | template <typename Case> |
| 1326 | void verifyPhysicalDisplayIsConnected(); |
| 1327 | |
| 1328 | void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken); |
| 1329 | }; |
| 1330 | |
| 1331 | template <typename Case> |
| 1332 | void HandleTransactionLockedTest::setupCommonPreconditions() { |
| 1333 | // Wide color displays support is configured appropriately |
| 1334 | Case::WideColorSupport::injectConfigChange(this); |
| 1335 | |
| 1336 | // SurfaceFlinger will use a test-controlled factory for BufferQueues |
| 1337 | injectFakeBufferQueueFactory(); |
| 1338 | |
| 1339 | // SurfaceFlinger will use a test-controlled factory for native window |
| 1340 | // surfaces. |
| 1341 | injectFakeNativeWindowSurfaceFactory(); |
| 1342 | } |
| 1343 | |
| 1344 | template <typename Case> |
| 1345 | void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() { |
| 1346 | Case::Display::setupHwcHotplugCallExpectations(this); |
| 1347 | |
| 1348 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); |
| 1349 | Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this); |
| 1350 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
| 1351 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
| 1352 | |
| 1353 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 1354 | Case::HdrSupport::setupComposerCallExpectations(this); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1355 | Case::PerFrameMetadataSupport::setupComposerCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1356 | |
| 1357 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 1358 | EXPECT_CALL(*mEventThread, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1359 | onHotplugReceived(static_cast<bool>(Case::Display::PRIMARY) |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 1360 | ? EventThread::DisplayType::Primary |
| 1361 | : EventThread::DisplayType::External, |
| 1362 | true)) |
| 1363 | .Times(1); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | template <typename Case> |
| 1367 | void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() { |
| 1368 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1); |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 1369 | EXPECT_CALL(*mEventThread, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1370 | onHotplugReceived(static_cast<bool>(Case::Display::PRIMARY) |
Dominik Laskowski | 00a6fa2 | 2018-06-06 16:42:02 -0700 | [diff] [blame] | 1371 | ? EventThread::DisplayType::Primary |
| 1372 | : EventThread::DisplayType::External, |
| 1373 | false)) |
| 1374 | .Times(1); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | template <typename Case> |
| 1378 | void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) { |
| 1379 | // The display device should have been set up in the list of displays. |
| 1380 | ASSERT_TRUE(hasDisplayDevice(displayToken)); |
| 1381 | const auto& device = getDisplayDevice(displayToken); |
| 1382 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1383 | EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1384 | |
| 1385 | // The display should have been set up in the current display state |
| 1386 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 1387 | const auto& current = getCurrentDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1388 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual()); |
| 1389 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt |
| 1390 | : Case::Display::DISPLAY_ID::get(), |
| 1391 | current.displayId); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1392 | |
| 1393 | // The display should have been set up in the drawing display state |
| 1394 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); |
| 1395 | const auto& draw = getDrawingDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1396 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual()); |
| 1397 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt |
| 1398 | : Case::Display::DISPLAY_ID::get(), |
| 1399 | draw.displayId); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | template <typename Case> |
| 1403 | void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() { |
| 1404 | // HWComposer should have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1405 | EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1406 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1407 | // SF should have a display token. |
| 1408 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1409 | ASSERT_TRUE(displayId); |
| 1410 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1); |
| 1411 | auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId]; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1412 | |
| 1413 | verifyDisplayIsConnected<Case>(displayToken); |
| 1414 | } |
| 1415 | |
| 1416 | void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) { |
| 1417 | EXPECT_FALSE(hasDisplayDevice(displayToken)); |
| 1418 | EXPECT_FALSE(hasCurrentDisplayState(displayToken)); |
| 1419 | EXPECT_FALSE(hasDrawingDisplayState(displayToken)); |
| 1420 | } |
| 1421 | |
| 1422 | template <typename Case> |
| 1423 | void HandleTransactionLockedTest::processesHotplugConnectCommon() { |
| 1424 | // -------------------------------------------------------------------- |
| 1425 | // Preconditions |
| 1426 | |
| 1427 | setupCommonPreconditions<Case>(); |
| 1428 | |
| 1429 | // A hotplug connect event is enqueued for a display |
| 1430 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1431 | |
| 1432 | // -------------------------------------------------------------------- |
| 1433 | // Call Expectations |
| 1434 | |
| 1435 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false)); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1436 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1437 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1438 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1439 | // -------------------------------------------------------------------- |
| 1440 | // Invocation |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1441 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1442 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1443 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1444 | // -------------------------------------------------------------------- |
| 1445 | // Postconditions |
| 1446 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1447 | verifyPhysicalDisplayIsConnected<Case>(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 1448 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1449 | // -------------------------------------------------------------------- |
| 1450 | // Cleanup conditions |
| 1451 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1452 | EXPECT_CALL(*mComposer, |
| 1453 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 1454 | .WillOnce(Return(Error::NONE)); |
| 1455 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 1456 | } |
| 1457 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1458 | template <typename Case> |
| 1459 | void HandleTransactionLockedTest::ignoresHotplugConnectCommon() { |
| 1460 | // -------------------------------------------------------------------- |
| 1461 | // Preconditions |
| 1462 | |
| 1463 | setupCommonPreconditions<Case>(); |
| 1464 | |
| 1465 | // A hotplug connect event is enqueued for a display |
| 1466 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
| 1467 | |
| 1468 | // -------------------------------------------------------------------- |
| 1469 | // Invocation |
| 1470 | |
| 1471 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1472 | |
| 1473 | // -------------------------------------------------------------------- |
| 1474 | // Postconditions |
| 1475 | |
| 1476 | // HWComposer should not have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1477 | EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | template <typename Case> |
| 1481 | void HandleTransactionLockedTest::processesHotplugDisconnectCommon() { |
| 1482 | // -------------------------------------------------------------------- |
| 1483 | // Preconditions |
| 1484 | |
| 1485 | setupCommonPreconditions<Case>(); |
| 1486 | |
| 1487 | // A hotplug disconnect event is enqueued for a display |
| 1488 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); |
| 1489 | |
| 1490 | // The display is already completely set up. |
| 1491 | Case::Display::injectHwcDisplay(this); |
| 1492 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1493 | existing.inject(); |
| 1494 | |
| 1495 | // -------------------------------------------------------------------- |
| 1496 | // Call Expectations |
| 1497 | |
| 1498 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
Lloyd Pique | 438e9e7 | 2018-09-04 18:06:08 -0700 | [diff] [blame] | 1499 | EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _)) |
| 1500 | .Times(0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1501 | |
| 1502 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 1503 | |
| 1504 | // -------------------------------------------------------------------- |
| 1505 | // Invocation |
| 1506 | |
| 1507 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1508 | |
| 1509 | // -------------------------------------------------------------------- |
| 1510 | // Postconditions |
| 1511 | |
| 1512 | // HWComposer should not have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1513 | EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1514 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1515 | // SF should not have a display token. |
| 1516 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1517 | ASSERT_TRUE(displayId); |
| 1518 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1519 | |
| 1520 | // The existing token should have been removed |
| 1521 | verifyDisplayIsNotConnected(existing.token()); |
| 1522 | } |
| 1523 | |
| 1524 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) { |
| 1525 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); |
| 1526 | } |
| 1527 | |
| 1528 | TEST_F(HandleTransactionLockedTest, |
| 1529 | processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) { |
| 1530 | // Inject an external display. |
| 1531 | ExternalDisplayVariant::injectHwcDisplay(this); |
| 1532 | |
| 1533 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); |
| 1534 | } |
| 1535 | |
| 1536 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) { |
| 1537 | // Inject a primary display. |
| 1538 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 1539 | |
| 1540 | processesHotplugConnectCommon<SimpleExternalDisplayCase>(); |
| 1541 | } |
| 1542 | |
| 1543 | TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) { |
| 1544 | // Inject both a primary and external display. |
| 1545 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 1546 | ExternalDisplayVariant::injectHwcDisplay(this); |
| 1547 | |
| 1548 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1549 | |
| 1550 | ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>(); |
| 1551 | } |
| 1552 | |
| 1553 | TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) { |
| 1554 | // Inject a primary display. |
| 1555 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 1556 | |
| 1557 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true)); |
| 1558 | |
| 1559 | ignoresHotplugConnectCommon<SimpleExternalDisplayCase>(); |
| 1560 | } |
| 1561 | |
| 1562 | TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) { |
| 1563 | processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>(); |
| 1564 | } |
| 1565 | |
| 1566 | TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) { |
| 1567 | processesHotplugDisconnectCommon<SimpleExternalDisplayCase>(); |
| 1568 | } |
| 1569 | |
| 1570 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) { |
| 1571 | using Case = SimplePrimaryDisplayCase; |
| 1572 | |
| 1573 | // -------------------------------------------------------------------- |
| 1574 | // Preconditions |
| 1575 | |
| 1576 | setupCommonPreconditions<Case>(); |
| 1577 | |
| 1578 | // A hotplug connect event is enqueued for a display |
| 1579 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
| 1580 | // A hotplug disconnect event is also enqueued for the same display |
| 1581 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); |
| 1582 | |
| 1583 | // -------------------------------------------------------------------- |
| 1584 | // Call Expectations |
| 1585 | |
| 1586 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1587 | |
| 1588 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
| 1589 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 1590 | |
| 1591 | EXPECT_CALL(*mComposer, |
| 1592 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
| 1593 | .WillOnce(Return(Error::NONE)); |
| 1594 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 1595 | |
| 1596 | // -------------------------------------------------------------------- |
| 1597 | // Invocation |
| 1598 | |
| 1599 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1600 | |
| 1601 | // -------------------------------------------------------------------- |
| 1602 | // Postconditions |
| 1603 | |
| 1604 | // HWComposer should not have an entry for the display |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1605 | EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1606 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1607 | // SF should not have a display token. |
| 1608 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1609 | ASSERT_TRUE(displayId); |
| 1610 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) { |
| 1614 | using Case = SimplePrimaryDisplayCase; |
| 1615 | |
| 1616 | // -------------------------------------------------------------------- |
| 1617 | // Preconditions |
| 1618 | |
| 1619 | setupCommonPreconditions<Case>(); |
| 1620 | |
| 1621 | // The display is already completely set up. |
| 1622 | Case::Display::injectHwcDisplay(this); |
| 1623 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1624 | existing.inject(); |
| 1625 | |
| 1626 | // A hotplug disconnect event is enqueued for a display |
| 1627 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); |
| 1628 | // A hotplug connect event is also enqueued for the same display |
| 1629 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
| 1630 | |
| 1631 | // -------------------------------------------------------------------- |
| 1632 | // Call Expectations |
| 1633 | |
| 1634 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1635 | |
| 1636 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
| 1637 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 1638 | |
| 1639 | // -------------------------------------------------------------------- |
| 1640 | // Invocation |
| 1641 | |
| 1642 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1643 | |
| 1644 | // -------------------------------------------------------------------- |
| 1645 | // Postconditions |
| 1646 | |
| 1647 | // The existing token should have been removed |
| 1648 | verifyDisplayIsNotConnected(existing.token()); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1649 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1650 | ASSERT_TRUE(displayId); |
| 1651 | ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1); |
| 1652 | EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1653 | |
| 1654 | // A new display should be connected in its place |
| 1655 | |
| 1656 | verifyPhysicalDisplayIsConnected<Case>(); |
| 1657 | |
| 1658 | // -------------------------------------------------------------------- |
| 1659 | // Cleanup conditions |
| 1660 | |
| 1661 | EXPECT_CALL(*mComposer, |
| 1662 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
| 1663 | .WillOnce(Return(Error::NONE)); |
| 1664 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 1665 | } |
| 1666 | |
| 1667 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) { |
| 1668 | using Case = HwcVirtualDisplayCase; |
| 1669 | |
| 1670 | // -------------------------------------------------------------------- |
| 1671 | // Preconditions |
| 1672 | |
| 1673 | // The HWC supports at least one virtual display |
| 1674 | injectMockComposer(1); |
| 1675 | |
| 1676 | setupCommonPreconditions<Case>(); |
| 1677 | |
| 1678 | // A virtual display was added to the current state, and it has a |
| 1679 | // surface(producer) |
| 1680 | sp<BBinder> displayToken = new BBinder(); |
Lloyd Pique | 4c2ac02 | 2018-04-27 12:08:03 -0700 | [diff] [blame] | 1681 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1682 | DisplayDeviceState state; |
| 1683 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1684 | |
| 1685 | sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1686 | state.surface = surface; |
| 1687 | mFlinger.mutableCurrentState().displays.add(displayToken, state); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1688 | |
| 1689 | // -------------------------------------------------------------------- |
| 1690 | // Call Expectations |
| 1691 | |
| 1692 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); |
| 1693 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
| 1694 | |
| 1695 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _)) |
| 1696 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR))); |
| 1697 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _)) |
| 1698 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR))); |
| 1699 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _)) |
| 1700 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT), |
| 1701 | Return(NO_ERROR))); |
| 1702 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _)) |
| 1703 | .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR))); |
| 1704 | |
| 1705 | EXPECT_CALL(*surface, setAsyncMode(true)).Times(1); |
| 1706 | |
| 1707 | EXPECT_CALL(*mProducer, connect(_, _, _, _)).Times(1); |
| 1708 | EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1); |
| 1709 | |
| 1710 | Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this); |
| 1711 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 1712 | Case::HdrSupport::setupComposerCallExpectations(this); |
Lloyd Pique | d883d5a | 2018-04-27 19:32:30 -0700 | [diff] [blame] | 1713 | Case::PerFrameMetadataSupport::setupComposerCallExpectations(this); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1714 | |
| 1715 | // -------------------------------------------------------------------- |
| 1716 | // Invocation |
| 1717 | |
| 1718 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1719 | |
| 1720 | // -------------------------------------------------------------------- |
| 1721 | // Postconditions |
| 1722 | |
| 1723 | // The display device should have been set up in the list of displays. |
| 1724 | verifyDisplayIsConnected<Case>(displayToken); |
| 1725 | |
| 1726 | // -------------------------------------------------------------------- |
| 1727 | // Cleanup conditions |
| 1728 | |
| 1729 | EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID)) |
| 1730 | .WillOnce(Return(Error::NONE)); |
| 1731 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 1732 | } |
| 1733 | |
| 1734 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) { |
| 1735 | using Case = HwcVirtualDisplayCase; |
| 1736 | |
| 1737 | // -------------------------------------------------------------------- |
| 1738 | // Preconditions |
| 1739 | |
| 1740 | // The HWC supports at least one virtual display |
| 1741 | injectMockComposer(1); |
| 1742 | |
| 1743 | setupCommonPreconditions<Case>(); |
| 1744 | |
| 1745 | // A virtual display was added to the current state, but it does not have a |
| 1746 | // surface. |
| 1747 | sp<BBinder> displayToken = new BBinder(); |
| 1748 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1749 | DisplayDeviceState state; |
| 1750 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1751 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1752 | mFlinger.mutableCurrentState().displays.add(displayToken, state); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1753 | |
| 1754 | // -------------------------------------------------------------------- |
| 1755 | // Call Expectations |
| 1756 | |
| 1757 | // -------------------------------------------------------------------- |
| 1758 | // Invocation |
| 1759 | |
| 1760 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1761 | |
| 1762 | // -------------------------------------------------------------------- |
| 1763 | // Postconditions |
| 1764 | |
| 1765 | // There will not be a display device set up. |
| 1766 | EXPECT_FALSE(hasDisplayDevice(displayToken)); |
| 1767 | |
| 1768 | // The drawing display state will be set from the current display state. |
| 1769 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); |
| 1770 | const auto& draw = getDrawingDisplayState(displayToken); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 1771 | EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual()); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) { |
| 1775 | using Case = HwcVirtualDisplayCase; |
| 1776 | |
| 1777 | // -------------------------------------------------------------------- |
| 1778 | // Preconditions |
| 1779 | |
| 1780 | // 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^] | 1781 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 1782 | ASSERT_TRUE(displayId); |
| 1783 | mFlinger.mutableHwcDisplayData()[*displayId] = {}; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 1784 | Case::Display::injectHwcDisplay(this); |
| 1785 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1786 | existing.inject(); |
| 1787 | mFlinger.mutableCurrentState().displays.removeItem(existing.token()); |
| 1788 | |
| 1789 | // -------------------------------------------------------------------- |
| 1790 | // Call Expectations |
| 1791 | |
| 1792 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1793 | |
| 1794 | // -------------------------------------------------------------------- |
| 1795 | // Invocation |
| 1796 | |
| 1797 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1798 | |
| 1799 | // -------------------------------------------------------------------- |
| 1800 | // Postconditions |
| 1801 | |
| 1802 | // The existing token should have been removed |
| 1803 | verifyDisplayIsNotConnected(existing.token()); |
| 1804 | } |
| 1805 | |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1806 | TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) { |
| 1807 | using Case = NonHwcVirtualDisplayCase; |
| 1808 | |
| 1809 | constexpr uint32_t oldLayerStack = 0u; |
| 1810 | constexpr uint32_t newLayerStack = 123u; |
| 1811 | |
| 1812 | // -------------------------------------------------------------------- |
| 1813 | // Preconditions |
| 1814 | |
| 1815 | // A display is set up |
| 1816 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1817 | display.inject(); |
| 1818 | |
| 1819 | // There is a change to the layerStack state |
| 1820 | display.mutableDrawingDisplayState().layerStack = oldLayerStack; |
| 1821 | display.mutableCurrentDisplayState().layerStack = newLayerStack; |
| 1822 | |
| 1823 | // -------------------------------------------------------------------- |
| 1824 | // Invocation |
| 1825 | |
| 1826 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1827 | |
| 1828 | // -------------------------------------------------------------------- |
| 1829 | // Postconditions |
| 1830 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1831 | EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) { |
| 1835 | using Case = NonHwcVirtualDisplayCase; |
| 1836 | |
| 1837 | constexpr int oldTransform = 0; |
| 1838 | constexpr int newTransform = 2; |
| 1839 | |
| 1840 | // -------------------------------------------------------------------- |
| 1841 | // Preconditions |
| 1842 | |
| 1843 | // A display is set up |
| 1844 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1845 | display.inject(); |
| 1846 | |
| 1847 | // There is a change to the orientation state |
| 1848 | display.mutableDrawingDisplayState().orientation = oldTransform; |
| 1849 | display.mutableCurrentDisplayState().orientation = newTransform; |
| 1850 | |
| 1851 | // -------------------------------------------------------------------- |
| 1852 | // Invocation |
| 1853 | |
| 1854 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1855 | |
| 1856 | // -------------------------------------------------------------------- |
| 1857 | // Postconditions |
| 1858 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1859 | EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) { |
| 1863 | using Case = NonHwcVirtualDisplayCase; |
| 1864 | |
| 1865 | const Rect oldViewport(0, 0, 0, 0); |
| 1866 | const Rect newViewport(0, 0, 123, 456); |
| 1867 | |
| 1868 | // -------------------------------------------------------------------- |
| 1869 | // Preconditions |
| 1870 | |
| 1871 | // A display is set up |
| 1872 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1873 | display.inject(); |
| 1874 | |
| 1875 | // There is a change to the viewport state |
| 1876 | display.mutableDrawingDisplayState().viewport = oldViewport; |
| 1877 | display.mutableCurrentDisplayState().viewport = newViewport; |
| 1878 | |
| 1879 | // -------------------------------------------------------------------- |
| 1880 | // Invocation |
| 1881 | |
| 1882 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1883 | |
| 1884 | // -------------------------------------------------------------------- |
| 1885 | // Postconditions |
| 1886 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1887 | EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) { |
| 1891 | using Case = NonHwcVirtualDisplayCase; |
| 1892 | |
| 1893 | const Rect oldFrame(0, 0, 0, 0); |
| 1894 | const Rect newFrame(0, 0, 123, 456); |
| 1895 | |
| 1896 | // -------------------------------------------------------------------- |
| 1897 | // Preconditions |
| 1898 | |
| 1899 | // A display is set up |
| 1900 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1901 | display.inject(); |
| 1902 | |
| 1903 | // There is a change to the viewport state |
| 1904 | display.mutableDrawingDisplayState().frame = oldFrame; |
| 1905 | display.mutableCurrentDisplayState().frame = newFrame; |
| 1906 | |
| 1907 | // -------------------------------------------------------------------- |
| 1908 | // Invocation |
| 1909 | |
| 1910 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1911 | |
| 1912 | // -------------------------------------------------------------------- |
| 1913 | // Postconditions |
| 1914 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 1915 | EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame()); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) { |
| 1919 | using Case = NonHwcVirtualDisplayCase; |
| 1920 | |
| 1921 | constexpr int oldWidth = 0; |
| 1922 | constexpr int oldHeight = 10; |
| 1923 | constexpr int newWidth = 123; |
| 1924 | |
| 1925 | // -------------------------------------------------------------------- |
| 1926 | // Preconditions |
| 1927 | |
| 1928 | // A display is set up |
| 1929 | auto nativeWindow = new mock::NativeWindow(); |
| 1930 | auto displaySurface = new mock::DisplaySurface(); |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 1931 | auto renderSurface = new renderengine::mock::Surface(); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1932 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1933 | display.setNativeWindow(nativeWindow); |
| 1934 | display.setDisplaySurface(displaySurface); |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 1935 | display.setRenderSurface(std::unique_ptr<renderengine::Surface>(renderSurface)); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1936 | display.inject(); |
| 1937 | |
| 1938 | // There is a change to the viewport state |
| 1939 | display.mutableDrawingDisplayState().width = oldWidth; |
| 1940 | display.mutableDrawingDisplayState().height = oldHeight; |
| 1941 | display.mutableCurrentDisplayState().width = newWidth; |
| 1942 | display.mutableCurrentDisplayState().height = oldHeight; |
| 1943 | |
| 1944 | // -------------------------------------------------------------------- |
| 1945 | // Call Expectations |
| 1946 | |
| 1947 | EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1); |
| 1948 | EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1); |
| 1949 | EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1); |
Alec Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame] | 1950 | EXPECT_CALL(*renderSurface, getWidth()).WillOnce(Return(newWidth)); |
| 1951 | EXPECT_CALL(*renderSurface, getHeight()).WillOnce(Return(oldHeight)); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1952 | |
| 1953 | // -------------------------------------------------------------------- |
| 1954 | // Invocation |
| 1955 | |
| 1956 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1957 | } |
| 1958 | |
| 1959 | TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) { |
| 1960 | using Case = NonHwcVirtualDisplayCase; |
| 1961 | |
| 1962 | constexpr int oldWidth = 0; |
| 1963 | constexpr int oldHeight = 10; |
| 1964 | constexpr int newHeight = 123; |
| 1965 | |
| 1966 | // -------------------------------------------------------------------- |
| 1967 | // Preconditions |
| 1968 | |
| 1969 | // A display is set up |
| 1970 | auto nativeWindow = new mock::NativeWindow(); |
| 1971 | auto displaySurface = new mock::DisplaySurface(); |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 1972 | auto renderSurface = new renderengine::mock::Surface(); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1973 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1974 | display.setNativeWindow(nativeWindow); |
| 1975 | display.setDisplaySurface(displaySurface); |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 1976 | display.setRenderSurface(std::unique_ptr<renderengine::Surface>(renderSurface)); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1977 | display.inject(); |
| 1978 | |
| 1979 | // There is a change to the viewport state |
| 1980 | display.mutableDrawingDisplayState().width = oldWidth; |
| 1981 | display.mutableDrawingDisplayState().height = oldHeight; |
| 1982 | display.mutableCurrentDisplayState().width = oldWidth; |
| 1983 | display.mutableCurrentDisplayState().height = newHeight; |
| 1984 | |
| 1985 | // -------------------------------------------------------------------- |
| 1986 | // Call Expectations |
| 1987 | |
| 1988 | EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1); |
| 1989 | EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1); |
| 1990 | EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1); |
Alec Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame] | 1991 | EXPECT_CALL(*renderSurface, getWidth()).WillOnce(Return(oldWidth)); |
| 1992 | EXPECT_CALL(*renderSurface, getHeight()).WillOnce(Return(newHeight)); |
Lloyd Pique | 0fa1d4c | 2018-01-22 18:54:42 -0800 | [diff] [blame] | 1993 | |
| 1994 | // -------------------------------------------------------------------- |
| 1995 | // Invocation |
| 1996 | |
| 1997 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1998 | } |
| 1999 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2000 | /* ------------------------------------------------------------------------ |
| 2001 | * SurfaceFlinger::setDisplayStateLocked |
| 2002 | */ |
| 2003 | |
| 2004 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) { |
| 2005 | // -------------------------------------------------------------------- |
| 2006 | // Preconditions |
| 2007 | |
| 2008 | // We have an unknown display token not associated with a known display |
| 2009 | sp<BBinder> displayToken = new BBinder(); |
| 2010 | |
| 2011 | // The requested display state references the unknown display. |
| 2012 | DisplayState state; |
| 2013 | state.what = DisplayState::eLayerStackChanged; |
| 2014 | state.token = displayToken; |
| 2015 | state.layerStack = 456; |
| 2016 | |
| 2017 | // -------------------------------------------------------------------- |
| 2018 | // Invocation |
| 2019 | |
| 2020 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2021 | |
| 2022 | // -------------------------------------------------------------------- |
| 2023 | // Postconditions |
| 2024 | |
| 2025 | // The returned flags are empty |
| 2026 | EXPECT_EQ(0u, flags); |
| 2027 | |
| 2028 | // The display token still doesn't match anything known. |
| 2029 | EXPECT_FALSE(hasCurrentDisplayState(displayToken)); |
| 2030 | } |
| 2031 | |
Lloyd Pique | 9d9cf40 | 2018-02-16 17:47:13 -0800 | [diff] [blame] | 2032 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) { |
| 2033 | using Case = SimplePrimaryDisplayCase; |
| 2034 | |
| 2035 | // -------------------------------------------------------------------- |
| 2036 | // Preconditions |
| 2037 | |
| 2038 | // A display is already set up |
| 2039 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2040 | display.inject(); |
| 2041 | |
| 2042 | // No changes are made to the display |
| 2043 | DisplayState state; |
| 2044 | state.what = 0; |
| 2045 | state.token = display.token(); |
| 2046 | |
| 2047 | // -------------------------------------------------------------------- |
| 2048 | // Invocation |
| 2049 | |
| 2050 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2051 | |
| 2052 | // -------------------------------------------------------------------- |
| 2053 | // Postconditions |
| 2054 | |
| 2055 | // The returned flags are empty |
| 2056 | EXPECT_EQ(0u, flags); |
| 2057 | } |
| 2058 | |
| 2059 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) { |
| 2060 | using Case = SimplePrimaryDisplayCase; |
| 2061 | |
| 2062 | // -------------------------------------------------------------------- |
| 2063 | // Preconditions |
| 2064 | |
| 2065 | // A display is already set up |
| 2066 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2067 | display.inject(); |
| 2068 | |
| 2069 | // There is a surface that can be set. |
| 2070 | sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer(); |
| 2071 | |
| 2072 | // The current display state has the surface set |
| 2073 | display.mutableCurrentDisplayState().surface = surface; |
| 2074 | |
| 2075 | // The incoming request sets the same surface |
| 2076 | DisplayState state; |
| 2077 | state.what = DisplayState::eSurfaceChanged; |
| 2078 | state.token = display.token(); |
| 2079 | state.surface = surface; |
| 2080 | |
| 2081 | // -------------------------------------------------------------------- |
| 2082 | // Invocation |
| 2083 | |
| 2084 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2085 | |
| 2086 | // -------------------------------------------------------------------- |
| 2087 | // Postconditions |
| 2088 | |
| 2089 | // The returned flags are empty |
| 2090 | EXPECT_EQ(0u, flags); |
| 2091 | |
| 2092 | // The current display state is unchanged. |
| 2093 | EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get()); |
| 2094 | } |
| 2095 | |
| 2096 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) { |
| 2097 | using Case = SimplePrimaryDisplayCase; |
| 2098 | |
| 2099 | // -------------------------------------------------------------------- |
| 2100 | // Preconditions |
| 2101 | |
| 2102 | // A display is already set up |
| 2103 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2104 | display.inject(); |
| 2105 | |
| 2106 | // There is a surface that can be set. |
| 2107 | sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer(); |
| 2108 | |
| 2109 | // The current display state does not have a surface |
| 2110 | display.mutableCurrentDisplayState().surface = nullptr; |
| 2111 | |
| 2112 | // The incoming request sets a surface |
| 2113 | DisplayState state; |
| 2114 | state.what = DisplayState::eSurfaceChanged; |
| 2115 | state.token = display.token(); |
| 2116 | state.surface = surface; |
| 2117 | |
| 2118 | // -------------------------------------------------------------------- |
| 2119 | // Invocation |
| 2120 | |
| 2121 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2122 | |
| 2123 | // -------------------------------------------------------------------- |
| 2124 | // Postconditions |
| 2125 | |
| 2126 | // The returned flags indicate a transaction is needed |
| 2127 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2128 | |
| 2129 | // The current display layer stack state is set to the new value |
| 2130 | EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get()); |
| 2131 | } |
| 2132 | |
| 2133 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) { |
| 2134 | using Case = SimplePrimaryDisplayCase; |
| 2135 | |
| 2136 | // -------------------------------------------------------------------- |
| 2137 | // Preconditions |
| 2138 | |
| 2139 | // A display is already set up |
| 2140 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2141 | display.inject(); |
| 2142 | |
| 2143 | // The display has a layer stack set |
| 2144 | display.mutableCurrentDisplayState().layerStack = 456u; |
| 2145 | |
| 2146 | // The incoming request sets the same layer stack |
| 2147 | DisplayState state; |
| 2148 | state.what = DisplayState::eLayerStackChanged; |
| 2149 | state.token = display.token(); |
| 2150 | state.layerStack = 456u; |
| 2151 | |
| 2152 | // -------------------------------------------------------------------- |
| 2153 | // Invocation |
| 2154 | |
| 2155 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2156 | |
| 2157 | // -------------------------------------------------------------------- |
| 2158 | // Postconditions |
| 2159 | |
| 2160 | // The returned flags are empty |
| 2161 | EXPECT_EQ(0u, flags); |
| 2162 | |
| 2163 | // The current display state is unchanged |
| 2164 | EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack); |
| 2165 | } |
| 2166 | |
| 2167 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) { |
| 2168 | using Case = SimplePrimaryDisplayCase; |
| 2169 | |
| 2170 | // -------------------------------------------------------------------- |
| 2171 | // Preconditions |
| 2172 | |
| 2173 | // A display is set up |
| 2174 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2175 | display.inject(); |
| 2176 | |
| 2177 | // The display has a layer stack set |
| 2178 | display.mutableCurrentDisplayState().layerStack = 654u; |
| 2179 | |
| 2180 | // The incoming request sets a different layer stack |
| 2181 | DisplayState state; |
| 2182 | state.what = DisplayState::eLayerStackChanged; |
| 2183 | state.token = display.token(); |
| 2184 | state.layerStack = 456u; |
| 2185 | |
| 2186 | // -------------------------------------------------------------------- |
| 2187 | // Invocation |
| 2188 | |
| 2189 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2190 | |
| 2191 | // -------------------------------------------------------------------- |
| 2192 | // Postconditions |
| 2193 | |
| 2194 | // The returned flags indicate a transaction is needed |
| 2195 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2196 | |
| 2197 | // The desired display state has been set to the new value. |
| 2198 | EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack); |
| 2199 | } |
| 2200 | |
| 2201 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) { |
| 2202 | using Case = SimplePrimaryDisplayCase; |
| 2203 | constexpr int initialOrientation = 180; |
| 2204 | const Rect initialFrame = {1, 2, 3, 4}; |
| 2205 | const Rect initialViewport = {5, 6, 7, 8}; |
| 2206 | |
| 2207 | // -------------------------------------------------------------------- |
| 2208 | // Preconditions |
| 2209 | |
| 2210 | // A display is set up |
| 2211 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2212 | display.inject(); |
| 2213 | |
| 2214 | // The current display state projection state is all set |
| 2215 | display.mutableCurrentDisplayState().orientation = initialOrientation; |
| 2216 | display.mutableCurrentDisplayState().frame = initialFrame; |
| 2217 | display.mutableCurrentDisplayState().viewport = initialViewport; |
| 2218 | |
| 2219 | // The incoming request sets the same projection state |
| 2220 | DisplayState state; |
| 2221 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2222 | state.token = display.token(); |
| 2223 | state.orientation = initialOrientation; |
| 2224 | state.frame = initialFrame; |
| 2225 | state.viewport = initialViewport; |
| 2226 | |
| 2227 | // -------------------------------------------------------------------- |
| 2228 | // Invocation |
| 2229 | |
| 2230 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2231 | |
| 2232 | // -------------------------------------------------------------------- |
| 2233 | // Postconditions |
| 2234 | |
| 2235 | // The returned flags are empty |
| 2236 | EXPECT_EQ(0u, flags); |
| 2237 | |
| 2238 | // The current display state is unchanged |
| 2239 | EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation); |
| 2240 | |
| 2241 | EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame); |
| 2242 | EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport); |
| 2243 | } |
| 2244 | |
| 2245 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) { |
| 2246 | using Case = SimplePrimaryDisplayCase; |
| 2247 | constexpr int initialOrientation = 90; |
| 2248 | constexpr int desiredOrientation = 180; |
| 2249 | |
| 2250 | // -------------------------------------------------------------------- |
| 2251 | // Preconditions |
| 2252 | |
| 2253 | // A display is set up |
| 2254 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2255 | display.inject(); |
| 2256 | |
| 2257 | // The current display state has an orientation set |
| 2258 | display.mutableCurrentDisplayState().orientation = initialOrientation; |
| 2259 | |
| 2260 | // The incoming request sets a different orientation |
| 2261 | DisplayState state; |
| 2262 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2263 | state.token = display.token(); |
| 2264 | state.orientation = desiredOrientation; |
| 2265 | |
| 2266 | // -------------------------------------------------------------------- |
| 2267 | // Invocation |
| 2268 | |
| 2269 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2270 | |
| 2271 | // -------------------------------------------------------------------- |
| 2272 | // Postconditions |
| 2273 | |
| 2274 | // The returned flags indicate a transaction is needed |
| 2275 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2276 | |
| 2277 | // The current display state has the new value. |
| 2278 | EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation); |
| 2279 | } |
| 2280 | |
| 2281 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) { |
| 2282 | using Case = SimplePrimaryDisplayCase; |
| 2283 | const Rect initialFrame = {0, 0, 0, 0}; |
| 2284 | const Rect desiredFrame = {5, 6, 7, 8}; |
| 2285 | |
| 2286 | // -------------------------------------------------------------------- |
| 2287 | // Preconditions |
| 2288 | |
| 2289 | // A display is set up |
| 2290 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2291 | display.inject(); |
| 2292 | |
| 2293 | // The current display state does not have a frame |
| 2294 | display.mutableCurrentDisplayState().frame = initialFrame; |
| 2295 | |
| 2296 | // The incoming request sets a frame |
| 2297 | DisplayState state; |
| 2298 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2299 | state.token = display.token(); |
| 2300 | state.frame = desiredFrame; |
| 2301 | |
| 2302 | // -------------------------------------------------------------------- |
| 2303 | // Invocation |
| 2304 | |
| 2305 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2306 | |
| 2307 | // -------------------------------------------------------------------- |
| 2308 | // Postconditions |
| 2309 | |
| 2310 | // The returned flags indicate a transaction is needed |
| 2311 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2312 | |
| 2313 | // The current display state has the new value. |
| 2314 | EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame); |
| 2315 | } |
| 2316 | |
| 2317 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) { |
| 2318 | using Case = SimplePrimaryDisplayCase; |
| 2319 | const Rect initialViewport = {0, 0, 0, 0}; |
| 2320 | const Rect desiredViewport = {5, 6, 7, 8}; |
| 2321 | |
| 2322 | // -------------------------------------------------------------------- |
| 2323 | // Preconditions |
| 2324 | |
| 2325 | // A display is set up |
| 2326 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2327 | display.inject(); |
| 2328 | |
| 2329 | // The current display state does not have a viewport |
| 2330 | display.mutableCurrentDisplayState().viewport = initialViewport; |
| 2331 | |
| 2332 | // The incoming request sets a viewport |
| 2333 | DisplayState state; |
| 2334 | state.what = DisplayState::eDisplayProjectionChanged; |
| 2335 | state.token = display.token(); |
| 2336 | state.viewport = desiredViewport; |
| 2337 | |
| 2338 | // -------------------------------------------------------------------- |
| 2339 | // Invocation |
| 2340 | |
| 2341 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2342 | |
| 2343 | // -------------------------------------------------------------------- |
| 2344 | // Postconditions |
| 2345 | |
| 2346 | // The returned flags indicate a transaction is needed |
| 2347 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2348 | |
| 2349 | // The current display state has the new value. |
| 2350 | EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport); |
| 2351 | } |
| 2352 | |
| 2353 | TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) { |
| 2354 | using Case = SimplePrimaryDisplayCase; |
| 2355 | constexpr uint32_t initialWidth = 1024; |
| 2356 | constexpr uint32_t initialHeight = 768; |
| 2357 | |
| 2358 | // -------------------------------------------------------------------- |
| 2359 | // Preconditions |
| 2360 | |
| 2361 | // A display is set up |
| 2362 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2363 | display.inject(); |
| 2364 | |
| 2365 | // The current display state has a size set |
| 2366 | display.mutableCurrentDisplayState().width = initialWidth; |
| 2367 | display.mutableCurrentDisplayState().height = initialHeight; |
| 2368 | |
| 2369 | // The incoming request sets the same display size |
| 2370 | DisplayState state; |
| 2371 | state.what = DisplayState::eDisplaySizeChanged; |
| 2372 | state.token = display.token(); |
| 2373 | state.width = initialWidth; |
| 2374 | state.height = initialHeight; |
| 2375 | |
| 2376 | // -------------------------------------------------------------------- |
| 2377 | // Invocation |
| 2378 | |
| 2379 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2380 | |
| 2381 | // -------------------------------------------------------------------- |
| 2382 | // Postconditions |
| 2383 | |
| 2384 | // The returned flags are empty |
| 2385 | EXPECT_EQ(0u, flags); |
| 2386 | |
| 2387 | // The current display state is unchanged |
| 2388 | EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width); |
| 2389 | EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height); |
| 2390 | } |
| 2391 | |
| 2392 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) { |
| 2393 | using Case = SimplePrimaryDisplayCase; |
| 2394 | constexpr uint32_t initialWidth = 0; |
| 2395 | constexpr uint32_t desiredWidth = 1024; |
| 2396 | |
| 2397 | // -------------------------------------------------------------------- |
| 2398 | // Preconditions |
| 2399 | |
| 2400 | // A display is set up |
| 2401 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2402 | display.inject(); |
| 2403 | |
| 2404 | // The display does not yet have a width |
| 2405 | display.mutableCurrentDisplayState().width = initialWidth; |
| 2406 | |
| 2407 | // The incoming request sets a display width |
| 2408 | DisplayState state; |
| 2409 | state.what = DisplayState::eDisplaySizeChanged; |
| 2410 | state.token = display.token(); |
| 2411 | state.width = desiredWidth; |
| 2412 | |
| 2413 | // -------------------------------------------------------------------- |
| 2414 | // Invocation |
| 2415 | |
| 2416 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2417 | |
| 2418 | // -------------------------------------------------------------------- |
| 2419 | // Postconditions |
| 2420 | |
| 2421 | // The returned flags indicate a transaction is needed |
| 2422 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2423 | |
| 2424 | // The current display state has the new value. |
| 2425 | EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width); |
| 2426 | } |
| 2427 | |
| 2428 | TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) { |
| 2429 | using Case = SimplePrimaryDisplayCase; |
| 2430 | constexpr uint32_t initialHeight = 0; |
| 2431 | constexpr uint32_t desiredHeight = 768; |
| 2432 | |
| 2433 | // -------------------------------------------------------------------- |
| 2434 | // Preconditions |
| 2435 | |
| 2436 | // A display is set up |
| 2437 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2438 | display.inject(); |
| 2439 | |
| 2440 | // The display does not yet have a height |
| 2441 | display.mutableCurrentDisplayState().height = initialHeight; |
| 2442 | |
| 2443 | // The incoming request sets a display height |
| 2444 | DisplayState state; |
| 2445 | state.what = DisplayState::eDisplaySizeChanged; |
| 2446 | state.token = display.token(); |
| 2447 | state.height = desiredHeight; |
| 2448 | |
| 2449 | // -------------------------------------------------------------------- |
| 2450 | // Invocation |
| 2451 | |
| 2452 | uint32_t flags = mFlinger.setDisplayStateLocked(state); |
| 2453 | |
| 2454 | // -------------------------------------------------------------------- |
| 2455 | // Postconditions |
| 2456 | |
| 2457 | // The returned flags indicate a transaction is needed |
| 2458 | EXPECT_EQ(eDisplayTransactionNeeded, flags); |
| 2459 | |
| 2460 | // The current display state has the new value. |
| 2461 | EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height); |
| 2462 | } |
| 2463 | |
Lloyd Pique | 86016da | 2018-03-01 16:09:38 -0800 | [diff] [blame] | 2464 | /* ------------------------------------------------------------------------ |
| 2465 | * SurfaceFlinger::onInitializeDisplays |
| 2466 | */ |
| 2467 | |
| 2468 | TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) { |
| 2469 | using Case = SimplePrimaryDisplayCase; |
| 2470 | |
| 2471 | // -------------------------------------------------------------------- |
| 2472 | // Preconditions |
| 2473 | |
| 2474 | // A primary display is set up |
| 2475 | Case::Display::injectHwcDisplay(this); |
| 2476 | auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2477 | primaryDisplay.inject(); |
| 2478 | |
| 2479 | // -------------------------------------------------------------------- |
| 2480 | // Call Expectations |
| 2481 | |
| 2482 | // We expect the surface interceptor to possibly be used, but we treat it as |
| 2483 | // disabled since it is called as a side effect rather than directly by this |
| 2484 | // function. |
| 2485 | EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false)); |
| 2486 | |
| 2487 | // We expect a call to get the active display config. |
| 2488 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
| 2489 | |
| 2490 | // We expect invalidate() to be invoked once to trigger display transaction |
| 2491 | // processing. |
| 2492 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 2493 | |
| 2494 | // -------------------------------------------------------------------- |
| 2495 | // Invocation |
| 2496 | |
| 2497 | mFlinger.onInitializeDisplays(); |
| 2498 | |
| 2499 | // -------------------------------------------------------------------- |
| 2500 | // Postconditions |
| 2501 | |
| 2502 | // The primary display should have a current state |
| 2503 | ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token())); |
| 2504 | const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token()); |
| 2505 | // The layer stack state should be set to zero |
| 2506 | EXPECT_EQ(0u, primaryDisplayState.layerStack); |
| 2507 | // The orientation state should be set to zero |
| 2508 | EXPECT_EQ(0, primaryDisplayState.orientation); |
| 2509 | |
| 2510 | // The frame state should be set to INVALID |
| 2511 | EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame); |
| 2512 | |
| 2513 | // The viewport state should be set to INVALID |
| 2514 | EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport); |
| 2515 | |
| 2516 | // The width and height should both be zero |
| 2517 | EXPECT_EQ(0u, primaryDisplayState.width); |
| 2518 | EXPECT_EQ(0u, primaryDisplayState.height); |
| 2519 | |
| 2520 | // The display should be set to HWC_POWER_MODE_NORMAL |
| 2521 | ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token())); |
| 2522 | auto displayDevice = primaryDisplay.mutableDisplayDevice(); |
| 2523 | EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode()); |
| 2524 | |
| 2525 | // The display refresh period should be set in the frame tracker. |
| 2526 | FrameStats stats; |
| 2527 | mFlinger.getAnimFrameTracker().getStats(&stats); |
| 2528 | EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano); |
| 2529 | |
| 2530 | // The display transaction needed flag should be set. |
| 2531 | EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded)); |
| 2532 | |
| 2533 | // The compositor timing should be set to default values |
| 2534 | const auto& compositorTiming = mFlinger.getCompositorTiming(); |
| 2535 | EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline); |
| 2536 | EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval); |
| 2537 | EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency); |
| 2538 | } |
| 2539 | |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2540 | /* ------------------------------------------------------------------------ |
| 2541 | * SurfaceFlinger::setPowerModeInternal |
| 2542 | */ |
| 2543 | |
| 2544 | // Used when we simulate a display that supports doze. |
| 2545 | struct DozeIsSupportedVariant { |
| 2546 | static constexpr bool DOZE_SUPPORTED = true; |
| 2547 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE = |
| 2548 | IComposerClient::PowerMode::DOZE; |
| 2549 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND = |
| 2550 | IComposerClient::PowerMode::DOZE_SUSPEND; |
| 2551 | }; |
| 2552 | |
| 2553 | // Used when we simulate a display that does not support doze. |
| 2554 | struct DozeNotSupportedVariant { |
| 2555 | static constexpr bool DOZE_SUPPORTED = false; |
| 2556 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE = |
| 2557 | IComposerClient::PowerMode::ON; |
| 2558 | static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND = |
| 2559 | IComposerClient::PowerMode::ON; |
| 2560 | }; |
| 2561 | |
| 2562 | struct EventThreadBaseSupportedVariant { |
| 2563 | static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) { |
| 2564 | // The event control thread should not be notified. |
| 2565 | EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0); |
| 2566 | |
| 2567 | // The event thread should not be notified. |
| 2568 | EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0); |
| 2569 | EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0); |
| 2570 | } |
| 2571 | }; |
| 2572 | |
| 2573 | struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant { |
| 2574 | static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 2575 | // These calls are only expected for the primary display. |
| 2576 | |
| 2577 | // Instead expect no calls. |
| 2578 | setupEventAndEventControlThreadNoCallExpectations(test); |
| 2579 | } |
| 2580 | |
| 2581 | static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 2582 | // These calls are only expected for the primary display. |
| 2583 | |
| 2584 | // Instead expect no calls. |
| 2585 | setupEventAndEventControlThreadNoCallExpectations(test); |
| 2586 | } |
| 2587 | }; |
| 2588 | |
| 2589 | struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant { |
| 2590 | static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 2591 | // The event control thread should be notified to enable vsyncs |
| 2592 | EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1); |
| 2593 | |
| 2594 | // The event thread should be notified that the screen was acquired. |
| 2595 | EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1); |
| 2596 | } |
| 2597 | |
| 2598 | static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) { |
| 2599 | // There should be a call to setVsyncEnabled(false) |
| 2600 | EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1); |
| 2601 | |
| 2602 | // The event thread should not be notified that the screen was released. |
| 2603 | EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1); |
| 2604 | } |
| 2605 | }; |
| 2606 | |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2607 | struct DispSyncIsSupportedVariant { |
| 2608 | static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) { |
| 2609 | EXPECT_CALL(*test->mPrimaryDispSync, reset()).Times(1); |
| 2610 | EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1); |
| 2611 | EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1); |
| 2612 | } |
| 2613 | |
| 2614 | static void setupEndResyncCallExpectations(DisplayTransactionTest* test) { |
| 2615 | EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1); |
| 2616 | } |
| 2617 | }; |
| 2618 | |
| 2619 | struct DispSyncNotSupportedVariant { |
| 2620 | static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {} |
| 2621 | |
| 2622 | static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {} |
| 2623 | }; |
| 2624 | |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2625 | // -------------------------------------------------------------------- |
| 2626 | // Note: |
| 2627 | // |
| 2628 | // There are a large number of transitions we could test, however we only test a |
| 2629 | // selected subset which provides complete test coverage of the implementation. |
| 2630 | // -------------------------------------------------------------------- |
| 2631 | |
| 2632 | template <int initialPowerMode, int targetPowerMode> |
| 2633 | struct TransitionVariantCommon { |
| 2634 | static constexpr auto INITIAL_POWER_MODE = initialPowerMode; |
| 2635 | static constexpr auto TARGET_POWER_MODE = targetPowerMode; |
| 2636 | |
| 2637 | static void verifyPostconditions(DisplayTransactionTest*) {} |
| 2638 | }; |
| 2639 | |
| 2640 | struct TransitionOffToOnVariant |
| 2641 | : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> { |
| 2642 | template <typename Case> |
| 2643 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2644 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON); |
| 2645 | Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2646 | Case::DispSync::setupBeginResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2647 | Case::setupRepaintEverythingCallExpectations(test); |
| 2648 | } |
| 2649 | |
| 2650 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 2651 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 2652 | EXPECT_TRUE(test->mFlinger.getHasPoweredOff()); |
| 2653 | } |
| 2654 | }; |
| 2655 | |
| 2656 | struct TransitionOffToDozeSuspendVariant |
| 2657 | : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> { |
| 2658 | template <typename Case> |
| 2659 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2660 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND); |
| 2661 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2662 | Case::setupRepaintEverythingCallExpectations(test); |
| 2663 | } |
| 2664 | |
| 2665 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 2666 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 2667 | EXPECT_TRUE(test->mFlinger.getHasPoweredOff()); |
| 2668 | } |
| 2669 | }; |
| 2670 | |
| 2671 | struct TransitionOnToOffVariant |
| 2672 | : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> { |
| 2673 | template <typename Case> |
| 2674 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2675 | Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2676 | Case::DispSync::setupEndResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2677 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF); |
| 2678 | } |
| 2679 | |
| 2680 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 2681 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 2682 | } |
| 2683 | }; |
| 2684 | |
| 2685 | struct TransitionDozeSuspendToOffVariant |
| 2686 | : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> { |
| 2687 | template <typename Case> |
| 2688 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2689 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2690 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF); |
| 2691 | } |
| 2692 | |
| 2693 | static void verifyPostconditions(DisplayTransactionTest* test) { |
| 2694 | EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty()); |
| 2695 | } |
| 2696 | }; |
| 2697 | |
| 2698 | struct TransitionOnToDozeVariant |
| 2699 | : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> { |
| 2700 | template <typename Case> |
| 2701 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2702 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2703 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE); |
| 2704 | } |
| 2705 | }; |
| 2706 | |
| 2707 | struct TransitionDozeSuspendToDozeVariant |
| 2708 | : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> { |
| 2709 | template <typename Case> |
| 2710 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2711 | Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2712 | Case::DispSync::setupBeginResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2713 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE); |
| 2714 | } |
| 2715 | }; |
| 2716 | |
| 2717 | struct TransitionDozeToOnVariant |
| 2718 | : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> { |
| 2719 | template <typename Case> |
| 2720 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2721 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2722 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON); |
| 2723 | } |
| 2724 | }; |
| 2725 | |
| 2726 | struct TransitionDozeSuspendToOnVariant |
| 2727 | : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> { |
| 2728 | template <typename Case> |
| 2729 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2730 | Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2731 | Case::DispSync::setupBeginResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2732 | Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON); |
| 2733 | } |
| 2734 | }; |
| 2735 | |
| 2736 | struct TransitionOnToDozeSuspendVariant |
| 2737 | : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> { |
| 2738 | template <typename Case> |
| 2739 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2740 | Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2741 | Case::DispSync::setupEndResyncCallExpectations(test); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2742 | Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND); |
| 2743 | } |
| 2744 | }; |
| 2745 | |
| 2746 | struct TransitionOnToUnknownVariant |
| 2747 | : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> { |
| 2748 | template <typename Case> |
| 2749 | static void setupCallExpectations(DisplayTransactionTest* test) { |
| 2750 | Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test); |
| 2751 | Case::setupNoComposerPowerModeCallExpectations(test); |
| 2752 | } |
| 2753 | }; |
| 2754 | |
| 2755 | // -------------------------------------------------------------------- |
| 2756 | // Note: |
| 2757 | // |
| 2758 | // Rather than testing the cartesian product of of |
| 2759 | // DozeIsSupported/DozeNotSupported with all other options, we use one for one |
| 2760 | // display type, and the other for another display type. |
| 2761 | // -------------------------------------------------------------------- |
| 2762 | |
| 2763 | template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant, |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2764 | typename DispSyncVariant, typename TransitionVariant> |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2765 | struct DisplayPowerCase { |
| 2766 | using Display = DisplayVariant; |
| 2767 | using Doze = DozeVariant; |
| 2768 | using EventThread = EventThreadVariant; |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2769 | using DispSync = DispSyncVariant; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2770 | using Transition = TransitionVariant; |
| 2771 | |
| 2772 | static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) { |
| 2773 | Display::injectHwcDisplay(test); |
| 2774 | auto display = Display::makeFakeExistingDisplayInjector(test); |
| 2775 | display.inject(); |
| 2776 | display.mutableDisplayDevice()->setPowerMode(mode); |
| 2777 | return display; |
| 2778 | } |
| 2779 | |
| 2780 | static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) { |
| 2781 | test->mFlinger.mutablePrimaryHWVsyncEnabled() = enabled; |
| 2782 | } |
| 2783 | |
| 2784 | static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) { |
| 2785 | EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1); |
| 2786 | } |
| 2787 | |
| 2788 | static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) { |
| 2789 | EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true)); |
| 2790 | EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1); |
| 2791 | } |
| 2792 | |
| 2793 | static void setupComposerCallExpectations(DisplayTransactionTest* test, |
| 2794 | IComposerClient::PowerMode mode) { |
| 2795 | // Any calls to get the active config will return a default value. |
| 2796 | EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _)) |
| 2797 | .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID), |
| 2798 | Return(Error::NONE))); |
| 2799 | |
| 2800 | // Any calls to get whether the display supports dozing will return the value set by the |
| 2801 | // policy variant. |
| 2802 | EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _)) |
| 2803 | .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE))); |
| 2804 | |
| 2805 | EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1); |
| 2806 | } |
| 2807 | |
| 2808 | static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) { |
| 2809 | EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0); |
| 2810 | } |
| 2811 | }; |
| 2812 | |
| 2813 | // A sample configuration for the primary display. |
| 2814 | // In addition to having event thread support, we emulate doze support. |
| 2815 | template <typename TransitionVariant> |
| 2816 | using PrimaryDisplayPowerCase = DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant, |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2817 | EventThreadIsSupportedVariant, |
| 2818 | DispSyncIsSupportedVariant, TransitionVariant>; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2819 | |
| 2820 | // A sample configuration for the external display. |
| 2821 | // In addition to not having event thread support, we emulate not having doze |
| 2822 | // support. |
| 2823 | template <typename TransitionVariant> |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 2824 | using ExternalDisplayPowerCase = DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant, |
| 2825 | EventThreadNotSupportedVariant, |
| 2826 | DispSyncNotSupportedVariant, TransitionVariant>; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2827 | |
| 2828 | class SetPowerModeInternalTest : public DisplayTransactionTest { |
| 2829 | public: |
| 2830 | template <typename Case> |
| 2831 | void transitionDisplayCommon(); |
| 2832 | }; |
| 2833 | |
| 2834 | template <int PowerMode> |
| 2835 | struct PowerModeInitialVSyncEnabled : public std::false_type {}; |
| 2836 | |
| 2837 | template <> |
| 2838 | struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {}; |
| 2839 | |
| 2840 | template <> |
| 2841 | struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {}; |
| 2842 | |
| 2843 | template <typename Case> |
| 2844 | void SetPowerModeInternalTest::transitionDisplayCommon() { |
| 2845 | // -------------------------------------------------------------------- |
| 2846 | // Preconditions |
| 2847 | |
| 2848 | auto display = |
| 2849 | Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE); |
| 2850 | Case::setInitialPrimaryHWVsyncEnabled(this, |
| 2851 | PowerModeInitialVSyncEnabled< |
| 2852 | Case::Transition::INITIAL_POWER_MODE>::value); |
| 2853 | |
| 2854 | // -------------------------------------------------------------------- |
| 2855 | // Call Expectations |
| 2856 | |
| 2857 | Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE); |
| 2858 | Case::Transition::template setupCallExpectations<Case>(this); |
| 2859 | |
| 2860 | // -------------------------------------------------------------------- |
| 2861 | // Invocation |
| 2862 | |
| 2863 | mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), |
| 2864 | Case::Transition::TARGET_POWER_MODE); |
| 2865 | |
| 2866 | // -------------------------------------------------------------------- |
| 2867 | // Postconditions |
| 2868 | |
| 2869 | Case::Transition::verifyPostconditions(this); |
| 2870 | } |
| 2871 | |
| 2872 | TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) { |
| 2873 | using Case = SimplePrimaryDisplayCase; |
| 2874 | |
| 2875 | // -------------------------------------------------------------------- |
| 2876 | // Preconditions |
| 2877 | |
| 2878 | // A primary display device is set up |
| 2879 | Case::Display::injectHwcDisplay(this); |
| 2880 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2881 | display.inject(); |
| 2882 | |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 2883 | // The display is already set to HWC_POWER_MODE_NORMAL |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2884 | display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL); |
| 2885 | |
| 2886 | // -------------------------------------------------------------------- |
| 2887 | // Invocation |
| 2888 | |
| 2889 | mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL); |
| 2890 | |
| 2891 | // -------------------------------------------------------------------- |
| 2892 | // Postconditions |
| 2893 | |
| 2894 | EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode()); |
| 2895 | } |
| 2896 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2897 | TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) { |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2898 | using Case = HwcVirtualDisplayCase; |
| 2899 | |
| 2900 | // -------------------------------------------------------------------- |
| 2901 | // Preconditions |
| 2902 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame^] | 2903 | // Insert display data so that the HWC thinks it created the virtual display. |
| 2904 | const auto displayId = Case::Display::DISPLAY_ID::get(); |
| 2905 | ASSERT_TRUE(displayId); |
| 2906 | mFlinger.mutableHwcDisplayData()[*displayId] = {}; |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2907 | |
| 2908 | // A virtual display device is set up |
| 2909 | Case::Display::injectHwcDisplay(this); |
| 2910 | auto display = Case::Display::makeFakeExistingDisplayInjector(this); |
| 2911 | display.inject(); |
| 2912 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2913 | // The display is set to HWC_POWER_MODE_NORMAL |
| 2914 | getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2915 | |
| 2916 | // -------------------------------------------------------------------- |
| 2917 | // Invocation |
| 2918 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 2919 | mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF); |
Lloyd Pique | 7d4aa6c | 2018-03-01 16:36:35 -0800 | [diff] [blame] | 2920 | |
| 2921 | // -------------------------------------------------------------------- |
| 2922 | // Postconditions |
| 2923 | |
| 2924 | EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode()); |
| 2925 | } |
| 2926 | |
| 2927 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) { |
| 2928 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>(); |
| 2929 | } |
| 2930 | |
| 2931 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) { |
| 2932 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>(); |
| 2933 | } |
| 2934 | |
| 2935 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) { |
| 2936 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>(); |
| 2937 | } |
| 2938 | |
| 2939 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) { |
| 2940 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>(); |
| 2941 | } |
| 2942 | |
| 2943 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) { |
| 2944 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>(); |
| 2945 | } |
| 2946 | |
| 2947 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) { |
| 2948 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>(); |
| 2949 | } |
| 2950 | |
| 2951 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) { |
| 2952 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>(); |
| 2953 | } |
| 2954 | |
| 2955 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) { |
| 2956 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>(); |
| 2957 | } |
| 2958 | |
| 2959 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) { |
| 2960 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>(); |
| 2961 | } |
| 2962 | |
| 2963 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) { |
| 2964 | transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>(); |
| 2965 | } |
| 2966 | |
| 2967 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) { |
| 2968 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>(); |
| 2969 | } |
| 2970 | |
| 2971 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) { |
| 2972 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>(); |
| 2973 | } |
| 2974 | |
| 2975 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) { |
| 2976 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>(); |
| 2977 | } |
| 2978 | |
| 2979 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) { |
| 2980 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>(); |
| 2981 | } |
| 2982 | |
| 2983 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) { |
| 2984 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>(); |
| 2985 | } |
| 2986 | |
| 2987 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) { |
| 2988 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>(); |
| 2989 | } |
| 2990 | |
| 2991 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) { |
| 2992 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>(); |
| 2993 | } |
| 2994 | |
| 2995 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) { |
| 2996 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>(); |
| 2997 | } |
| 2998 | |
| 2999 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) { |
| 3000 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>(); |
| 3001 | } |
| 3002 | |
| 3003 | TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) { |
| 3004 | transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>(); |
| 3005 | } |
| 3006 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 3007 | } // namespace |
| 3008 | } // namespace android |