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