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