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 | |
| 48 | using android::hardware::graphics::common::V1_0::Hdr; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 49 | using android::hardware::graphics::common::V1_1::ColorMode; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 50 | using android::Hwc2::Error; |
| 51 | using android::Hwc2::IComposer; |
| 52 | using android::Hwc2::IComposerClient; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 53 | using android::Hwc2::RenderIntent; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 54 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 55 | using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector; |
| 56 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 57 | using HotplugEvent = TestableSurfaceFlinger::HotplugEvent; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 58 | using HWC2Display = TestableSurfaceFlinger::HWC2Display; |
Lloyd Pique | bc79209 | 2018-01-17 11:52:30 -0800 | [diff] [blame] | 59 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 60 | constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 61 | constexpr int32_t DEFAULT_DPI = 320; |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 62 | constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 63 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 64 | /* ------------------------------------------------------------------------ |
| 65 | * Boolean avoidance |
| 66 | * |
| 67 | * To make calls and template instantiations more readable, we define some |
| 68 | * local enums along with an implicit bool conversion. |
| 69 | */ |
| 70 | |
| 71 | #define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true }; |
| 72 | |
| 73 | BOOL_SUBSTITUTE(Critical); |
| 74 | BOOL_SUBSTITUTE(Async); |
| 75 | BOOL_SUBSTITUTE(Secure); |
| 76 | |
| 77 | /* ------------------------------------------------------------------------ |
| 78 | * |
| 79 | */ |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 80 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 81 | class DisplayTransactionTest : public testing::Test { |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 82 | public: |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 83 | DisplayTransactionTest(); |
| 84 | ~DisplayTransactionTest() override; |
| 85 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 86 | // -------------------------------------------------------------------- |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 87 | // Mock/Fake injection |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 88 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 89 | void injectMockComposer(int virtualDisplayCount); |
| 90 | void injectFakeBufferQueueFactory(); |
| 91 | void injectFakeNativeWindowSurfaceFactory(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 92 | |
| 93 | // -------------------------------------------------------------------- |
| 94 | // Postcondition helpers |
| 95 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 96 | bool hasHwcDisplay(hwc2_display_t displayId); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 97 | bool hasTransactionFlagSet(int flag); |
| 98 | bool hasDisplayDevice(sp<IBinder> displayToken); |
| 99 | sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken); |
| 100 | bool hasCurrentDisplayState(sp<IBinder> displayToken); |
| 101 | const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken); |
| 102 | bool hasDrawingDisplayState(sp<IBinder> displayToken); |
| 103 | const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken); |
| 104 | |
| 105 | // -------------------------------------------------------------------- |
| 106 | // Test instances |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 107 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 108 | TestableSurfaceFlinger mFlinger; |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 109 | mock::EventThread* mEventThread = new mock::EventThread(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 110 | mock::EventControlThread* mEventControlThread = new mock::EventControlThread(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 111 | |
| 112 | // These mocks are created by the test, but are destroyed by SurfaceFlinger |
| 113 | // by virtue of being stored into a std::unique_ptr. However we still need |
| 114 | // to keep a reference to them for use in setting up call expectations. |
| 115 | RE::mock::RenderEngine* mRenderEngine = new RE::mock::RenderEngine(); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 116 | Hwc2::mock::Composer* mComposer = nullptr; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 117 | mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); |
| 118 | mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor(); |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 119 | |
| 120 | // These mocks are created only when expected to be created via a factory. |
| 121 | sp<mock::GraphicBufferConsumer> mConsumer; |
| 122 | sp<mock::GraphicBufferProducer> mProducer; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 123 | mock::NativeWindowSurface* mNativeWindowSurface = nullptr; |
| 124 | sp<mock::NativeWindow> mNativeWindow; |
| 125 | RE::mock::Surface* mRenderSurface = nullptr; |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | DisplayTransactionTest::DisplayTransactionTest() { |
| 129 | const ::testing::TestInfo* const test_info = |
| 130 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 131 | 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] | 132 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 133 | // Default to no wide color display support configured |
| 134 | mFlinger.mutableHasWideColorDisplay() = false; |
| 135 | mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; |
| 136 | |
| 137 | // Default to using HWC virtual displays |
| 138 | mFlinger.mutableUseHwcVirtualDisplays() = true; |
| 139 | |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 140 | mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) { |
| 141 | ADD_FAILURE() << "Unexpected request to create a buffer queue."; |
| 142 | }); |
| 143 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 144 | mFlinger.setCreateNativeWindowSurface([](auto) { |
| 145 | ADD_FAILURE() << "Unexpected request to create a native window surface."; |
| 146 | return nullptr; |
| 147 | }); |
| 148 | |
| 149 | mFlinger.mutableEventControlThread().reset(mEventControlThread); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 150 | mFlinger.mutableEventThread().reset(mEventThread); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 151 | mFlinger.mutableEventQueue().reset(mMessageQueue); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 152 | mFlinger.setupRenderEngine(std::unique_ptr<RE::RenderEngine>(mRenderEngine)); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 153 | mFlinger.mutableInterceptor().reset(mSurfaceInterceptor); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 154 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 155 | injectMockComposer(0); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | DisplayTransactionTest::~DisplayTransactionTest() { |
| 159 | const ::testing::TestInfo* const test_info = |
| 160 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 161 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 162 | } |
| 163 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 164 | void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) { |
| 165 | mComposer = new Hwc2::mock::Composer(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 166 | EXPECT_CALL(*mComposer, getCapabilities()) |
| 167 | .WillOnce(Return(std::vector<IComposer::Capability>())); |
| 168 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); |
| 169 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 170 | |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 171 | Mock::VerifyAndClear(mComposer); |
| 172 | } |
| 173 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 174 | void DisplayTransactionTest::injectFakeBufferQueueFactory() { |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 175 | // This setup is only expected once per test. |
| 176 | ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr); |
| 177 | |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 178 | mConsumer = new mock::GraphicBufferConsumer(); |
| 179 | mProducer = new mock::GraphicBufferProducer(); |
| 180 | |
| 181 | mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) { |
| 182 | *outProducer = mProducer; |
| 183 | *outConsumer = mConsumer; |
| 184 | }); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 185 | } |
Lloyd Pique | 5b36f3f | 2018-01-17 11:57:07 -0800 | [diff] [blame] | 186 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 187 | void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() { |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 188 | // This setup is only expected once per test. |
| 189 | ASSERT_TRUE(mNativeWindowSurface == nullptr); |
| 190 | |
| 191 | mNativeWindowSurface = new mock::NativeWindowSurface(); |
| 192 | mNativeWindow = new mock::NativeWindow(); |
| 193 | |
| 194 | mFlinger.setCreateNativeWindowSurface( |
| 195 | [this](auto) { return std::unique_ptr<NativeWindowSurface>(mNativeWindowSurface); }); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 198 | bool DisplayTransactionTest::hasHwcDisplay(hwc2_display_t displayId) { |
| 199 | return mFlinger.mutableHwcDisplaySlots().count(displayId) == 1; |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | bool DisplayTransactionTest::hasTransactionFlagSet(int flag) { |
| 203 | return mFlinger.mutableTransactionFlags() & flag; |
| 204 | } |
| 205 | |
| 206 | bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) { |
| 207 | return mFlinger.mutableDisplays().indexOfKey(displayToken) >= 0; |
| 208 | } |
| 209 | |
| 210 | sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) { |
| 211 | return mFlinger.mutableDisplays().valueFor(displayToken); |
| 212 | } |
| 213 | |
| 214 | bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) { |
| 215 | return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0; |
| 216 | } |
| 217 | |
| 218 | const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) { |
| 219 | return mFlinger.mutableCurrentState().displays.valueFor(displayToken); |
| 220 | } |
| 221 | |
| 222 | bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) { |
| 223 | return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0; |
| 224 | } |
| 225 | |
| 226 | const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) { |
| 227 | return mFlinger.mutableDrawingState().displays.valueFor(displayToken); |
| 228 | } |
| 229 | |
| 230 | /* ------------------------------------------------------------------------ |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 231 | * |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 232 | */ |
| 233 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 234 | template <DisplayDevice::DisplayType type, DisplayDevice::DisplayType hwcId, int width, int height, |
| 235 | Critical critical, Async async, Secure secure, int grallocUsage> |
| 236 | struct DisplayVariant { |
| 237 | // The display width and height |
| 238 | static constexpr int WIDTH = width; |
| 239 | static constexpr int HEIGHT = height; |
| 240 | |
| 241 | static constexpr int GRALLOC_USAGE = grallocUsage; |
| 242 | |
| 243 | // The type for this display |
| 244 | static constexpr DisplayDevice::DisplayType TYPE = type; |
| 245 | static constexpr DisplayDevice::DisplayType HWCOMPOSER_ID = hwcId; |
| 246 | |
| 247 | // When creating native window surfaces for the framebuffer, whether those should be critical |
| 248 | static constexpr Critical CRITICAL = critical; |
| 249 | |
| 250 | // When creating native window surfaces for the framebuffer, whether those should be async |
| 251 | static constexpr Async ASYNC = async; |
| 252 | |
| 253 | // Whether the display should be treated as secure |
| 254 | static constexpr Secure SECURE = secure; |
| 255 | |
| 256 | static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) { |
| 257 | auto injector = FakeDisplayDeviceInjector(test->mFlinger, TYPE, HWCOMPOSER_ID); |
| 258 | injector.setSecure(static_cast<bool>(SECURE)); |
| 259 | return injector; |
| 260 | } |
| 261 | |
| 262 | // Called by tests to set up any native window creation call expectations. |
| 263 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 264 | EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow()) |
| 265 | .WillOnce(Return(test->mNativeWindow)); |
| 266 | EXPECT_CALL(*test->mNativeWindow, perform(19)).WillRepeatedly(Return(NO_ERROR)); |
| 267 | |
| 268 | // For simplicity, we only expect to create a single render surface for |
| 269 | // each test. |
| 270 | ASSERT_TRUE(test->mRenderSurface == nullptr); |
| 271 | test->mRenderSurface = new RE::mock::Surface(); |
| 272 | EXPECT_CALL(*test->mRenderEngine, createSurface()) |
| 273 | .WillOnce(Return(ByMove(std::unique_ptr<RE::Surface>(test->mRenderSurface)))); |
| 274 | EXPECT_CALL(*test->mRenderSurface, setAsync(static_cast<bool>(ASYNC))).Times(1); |
| 275 | EXPECT_CALL(*test->mRenderSurface, setCritical(static_cast<bool>(CRITICAL))).Times(1); |
| 276 | EXPECT_CALL(*test->mRenderSurface, setNativeWindow(test->mNativeWindow.get())).Times(1); |
| 277 | EXPECT_CALL(*test->mRenderSurface, queryWidth()).WillOnce(Return(WIDTH)); |
| 278 | EXPECT_CALL(*test->mRenderSurface, queryHeight()).WillOnce(Return(HEIGHT)); |
| 279 | } |
| 280 | |
| 281 | static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) { |
| 282 | EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR)); |
| 283 | EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR)); |
| 284 | EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE)) |
| 285 | .WillRepeatedly(Return(NO_ERROR)); |
| 286 | EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT)) |
| 287 | .WillRepeatedly(Return(NO_ERROR)); |
| 288 | EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_)) |
| 289 | .WillRepeatedly(Return(NO_ERROR)); |
| 290 | } |
| 291 | |
| 292 | static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) { |
| 293 | EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return()); |
| 294 | } |
| 295 | }; |
| 296 | |
| 297 | template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant> |
| 298 | struct HwcDisplayVariant { |
| 299 | // The display id supplied by the HWC |
| 300 | static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId; |
| 301 | |
| 302 | // The HWC display type |
| 303 | static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType; |
| 304 | |
| 305 | // The HWC active configuration id |
| 306 | // TODO(b/69807179): SurfaceFlinger does not correctly get the active |
| 307 | // config. Once it does, change this to non-zero so that it is properly |
| 308 | // covered. |
| 309 | // static constexpr int HWC_ACTIVE_CONFIG_ID = 2001; |
| 310 | static constexpr int HWC_ACTIVE_CONFIG_ID = 0; |
| 311 | |
| 312 | static void injectPendingHotplugEvent(DisplayTransactionTest* test, |
| 313 | HWC2::Connection connection) { |
| 314 | test->mFlinger.mutablePendingHotplugEvents().emplace_back( |
| 315 | HotplugEvent{HWC_DISPLAY_ID, connection}); |
| 316 | } |
| 317 | |
| 318 | // Called by tests to inject a HWC display setup |
| 319 | static void injectHwcDisplay(DisplayTransactionTest* test) { |
| 320 | FakeHwcDisplayInjector(DisplayVariant::TYPE, HWC_DISPLAY_TYPE) |
| 321 | .setHwcDisplayId(HWC_DISPLAY_ID) |
| 322 | .setWidth(DisplayVariant::WIDTH) |
| 323 | .setHeight(DisplayVariant::HEIGHT) |
| 324 | .setActiveConfig(HWC_ACTIVE_CONFIG_ID) |
| 325 | .inject(&test->mFlinger, test->mComposer); |
| 326 | } |
| 327 | |
| 328 | static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) { |
| 329 | EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _)) |
| 330 | .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>( |
| 331 | HWC_DISPLAY_TYPE)), |
| 332 | Return(Error::NONE))); |
| 333 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); |
| 334 | EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _)) |
| 335 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}), |
| 336 | Return(Error::NONE))); |
| 337 | EXPECT_CALL(*test->mComposer, |
| 338 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 339 | IComposerClient::Attribute::WIDTH, _)) |
| 340 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE))); |
| 341 | EXPECT_CALL(*test->mComposer, |
| 342 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 343 | IComposerClient::Attribute::HEIGHT, _)) |
| 344 | .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE))); |
| 345 | EXPECT_CALL(*test->mComposer, |
| 346 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 347 | IComposerClient::Attribute::VSYNC_PERIOD, _)) |
| 348 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE))); |
| 349 | EXPECT_CALL(*test->mComposer, |
| 350 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 351 | IComposerClient::Attribute::DPI_X, _)) |
| 352 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); |
| 353 | EXPECT_CALL(*test->mComposer, |
| 354 | getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID, |
| 355 | IComposerClient::Attribute::DPI_Y, _)) |
| 356 | .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE))); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame^] | 357 | EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _)) |
| 358 | .WillRepeatedly(Return(Error::UNSUPPORTED)); |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | // Called by tests to set up HWC call expectations |
| 362 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { |
| 363 | EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _)) |
| 364 | .WillOnce(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE))); |
| 365 | } |
| 366 | }; |
| 367 | |
| 368 | struct NonHwcDisplayVariant { |
| 369 | static constexpr int HWC_ACTIVE_CONFIG_ID = 0; |
| 370 | |
| 371 | static void injectHwcDisplay(DisplayTransactionTest*) {} |
| 372 | |
| 373 | static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) { |
| 374 | EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0); |
| 375 | } |
| 376 | }; |
| 377 | |
| 378 | // Physical displays are expected to be synchronous, secure, and have a HWC display for output. |
| 379 | constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY = |
| 380 | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB; |
| 381 | |
| 382 | template <hwc2_display_t hwcDisplayId, DisplayDevice::DisplayType type, int width, int height, |
| 383 | Critical critical> |
| 384 | struct PhysicalDisplayVariant |
| 385 | : public DisplayVariant<type, type, width, height, critical, Async::FALSE, Secure::TRUE, |
| 386 | GRALLOC_USAGE_PHYSICAL_DISPLAY>, |
| 387 | public HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical, |
| 388 | DisplayVariant<type, type, width, height, critical, Async::FALSE, |
| 389 | Secure::TRUE, GRALLOC_USAGE_PHYSICAL_DISPLAY>> {}; |
| 390 | |
| 391 | // A primary display is a physical display that is critical |
| 392 | using PrimaryDisplayVariant = |
| 393 | PhysicalDisplayVariant<1001, DisplayDevice::DISPLAY_PRIMARY, 3840, 2160, Critical::TRUE>; |
| 394 | |
| 395 | // An external display is physical display that is not critical. |
| 396 | using ExternalDisplayVariant = |
| 397 | PhysicalDisplayVariant<1002, DisplayDevice::DISPLAY_EXTERNAL, 1920, 1280, Critical::FALSE>; |
| 398 | |
| 399 | using TertiaryDisplayVariant = |
| 400 | PhysicalDisplayVariant<1003, DisplayDevice::DISPLAY_EXTERNAL, 1600, 1200, Critical::FALSE>; |
| 401 | |
| 402 | // A virtual display not supported by the HWC. |
| 403 | constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0; |
| 404 | |
| 405 | template <int width, int height, Secure secure> |
| 406 | struct NonHwcVirtualDisplayVariant |
| 407 | : public DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_ID_INVALID, |
| 408 | width, height, Critical::FALSE, Async::TRUE, secure, |
| 409 | GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>, |
| 410 | public NonHwcDisplayVariant { |
| 411 | using Base = DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_ID_INVALID, |
| 412 | width, height, Critical::FALSE, Async::TRUE, secure, |
| 413 | GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>; |
| 414 | |
| 415 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 416 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); |
| 417 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); |
| 418 | } |
| 419 | }; |
| 420 | |
| 421 | // A virtual display supported by the HWC. |
| 422 | constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER; |
| 423 | |
| 424 | template <int width, int height, Secure secure> |
| 425 | struct HwcVirtualDisplayVariant |
| 426 | : public DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_VIRTUAL, width, |
| 427 | height, Critical::FALSE, Async::TRUE, secure, |
| 428 | GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>, |
| 429 | public HwcDisplayVariant<1010, HWC2::DisplayType::Virtual, |
| 430 | NonHwcVirtualDisplayVariant<width, height, secure>> { |
| 431 | using Base = |
| 432 | DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_VIRTUAL, width, |
| 433 | height, Critical::FALSE, Async::TRUE, secure, GRALLOC_USAGE_HW_COMPOSER>; |
| 434 | using Self = HwcVirtualDisplayVariant<width, height, secure>; |
| 435 | |
| 436 | static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) { |
| 437 | Base::setupNativeWindowSurfaceCreationCallExpectations(test); |
| 438 | EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1); |
| 439 | } |
| 440 | |
| 441 | static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) { |
| 442 | EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _)) |
| 443 | .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE))); |
| 444 | EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); |
| 445 | } |
| 446 | }; |
| 447 | |
| 448 | // For this variant, SurfaceFlinger should not configure itself with wide |
| 449 | // display support, so the display should not be configured for wide-color |
| 450 | // support. |
| 451 | struct WideColorSupportNotConfiguredVariant { |
| 452 | static constexpr bool WIDE_COLOR_SUPPORTED = false; |
| 453 | |
| 454 | static void injectConfigChange(DisplayTransactionTest* test) { |
| 455 | test->mFlinger.mutableHasWideColorDisplay() = false; |
| 456 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; |
| 457 | } |
| 458 | |
| 459 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 460 | EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0); |
| 461 | EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0); |
| 462 | EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0); |
| 463 | } |
| 464 | }; |
| 465 | |
| 466 | // For this variant, SurfaceFlinger should configure itself with wide display |
| 467 | // support, and the display should respond with an non-empty list of supported |
| 468 | // color modes. Wide-color support should be configured. |
| 469 | template <typename Display> |
| 470 | struct WideColorP3ColorimetricSupportedVariant { |
| 471 | static constexpr bool WIDE_COLOR_SUPPORTED = true; |
| 472 | |
| 473 | static void injectConfigChange(DisplayTransactionTest* test) { |
| 474 | test->mFlinger.mutableHasWideColorDisplay() = true; |
| 475 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED; |
| 476 | } |
| 477 | |
| 478 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 479 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) |
| 480 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})), |
| 481 | Return(Error::NONE))); |
| 482 | EXPECT_CALL(*test->mComposer, |
| 483 | getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _)) |
| 484 | .WillOnce(DoAll(SetArgPointee<2>( |
| 485 | std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})), |
| 486 | Return(Error::NONE))); |
| 487 | EXPECT_CALL(*test->mComposer, |
| 488 | setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB, |
| 489 | RenderIntent::COLORIMETRIC)) |
| 490 | .WillOnce(Return(Error::NONE)); |
| 491 | } |
| 492 | }; |
| 493 | |
| 494 | // For this variant, SurfaceFlinger should configure itself with wide color |
| 495 | // display support, and the display should respond with an non-empty list of |
| 496 | // supported color modes. |
| 497 | template <typename Display> |
| 498 | struct WideColorP3EnhanceSupportedVariant { |
| 499 | static constexpr bool WIDE_COLOR_SUPPORTED = true; |
| 500 | |
| 501 | static void injectConfigChange(DisplayTransactionTest* test) { |
| 502 | test->mFlinger.mutableHasWideColorDisplay() = true; |
| 503 | test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::ENHANCED; |
| 504 | } |
| 505 | |
| 506 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 507 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) |
| 508 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})), |
| 509 | Return(Error::NONE))); |
| 510 | EXPECT_CALL(*test->mComposer, |
| 511 | getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _)) |
| 512 | .WillOnce( |
| 513 | DoAll(SetArgPointee<2>(std::vector<RenderIntent>({RenderIntent::ENHANCE})), |
| 514 | Return(Error::NONE))); |
| 515 | EXPECT_CALL(*test->mComposer, |
| 516 | setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB, RenderIntent::ENHANCE)) |
| 517 | .WillOnce(Return(Error::NONE)); |
| 518 | } |
| 519 | }; |
| 520 | |
| 521 | // For this variant, SurfaceFlinger should configure itself with wide display |
| 522 | // support, but the display should respond with an empty list of supported color |
| 523 | // modes. Wide-color support for the display should not be configured. |
| 524 | template <typename Display> |
| 525 | struct WideColorNotSupportedVariant { |
| 526 | static constexpr bool WIDE_COLOR_SUPPORTED = false; |
| 527 | |
| 528 | static void injectConfigChange(DisplayTransactionTest* test) { |
| 529 | test->mFlinger.mutableHasWideColorDisplay() = true; |
| 530 | } |
| 531 | |
| 532 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 533 | EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _)) |
| 534 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE))); |
| 535 | EXPECT_CALL(*test->mComposer, |
| 536 | setColorMode(Display::HWC_DISPLAY_ID, ColorMode::NATIVE, |
| 537 | RenderIntent::COLORIMETRIC)) |
| 538 | .WillOnce(Return(Error::NONE)); |
| 539 | } |
| 540 | }; |
| 541 | |
| 542 | // For this variant, the display is not a HWC display, so no HDR support should |
| 543 | // be configured. |
| 544 | struct NonHwcDisplayHdrSupportVariant { |
| 545 | static constexpr bool HDR10_SUPPORTED = false; |
| 546 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 547 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 548 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 549 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0); |
| 550 | } |
| 551 | }; |
| 552 | |
| 553 | // For this variant, the composer should respond with a non-empty list of HDR |
| 554 | // modes containing HDR10, so HDR10 support should be configured. |
| 555 | template <typename Display> |
| 556 | struct Hdr10SupportedVariant { |
| 557 | static constexpr bool HDR10_SUPPORTED = true; |
| 558 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 559 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 560 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 561 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 562 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})), |
| 563 | Return(Error::NONE))); |
| 564 | } |
| 565 | }; |
| 566 | |
| 567 | // For this variant, the composer should respond with a non-empty list of HDR |
| 568 | // modes containing HLG, so HLG support should be configured. |
| 569 | template <typename Display> |
| 570 | struct HdrHlgSupportedVariant { |
| 571 | static constexpr bool HDR10_SUPPORTED = false; |
| 572 | static constexpr bool HDR_HLG_SUPPORTED = true; |
| 573 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 574 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 575 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 576 | .WillOnce( |
| 577 | DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE))); |
| 578 | } |
| 579 | }; |
| 580 | |
| 581 | // For this variant, the composer should respond with a non-empty list of HDR |
| 582 | // modes containing DOLBY_VISION, so DOLBY_VISION support should be configured. |
| 583 | template <typename Display> |
| 584 | struct HdrDolbyVisionSupportedVariant { |
| 585 | static constexpr bool HDR10_SUPPORTED = false; |
| 586 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 587 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true; |
| 588 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 589 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 590 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})), |
| 591 | Return(Error::NONE))); |
| 592 | } |
| 593 | }; |
| 594 | |
| 595 | // For this variant, the composer should respond with am empty list of HDR |
| 596 | // modes, so no HDR support should be configured. |
| 597 | template <typename Display> |
| 598 | struct HdrNotSupportedVariant { |
| 599 | static constexpr bool HDR10_SUPPORTED = false; |
| 600 | static constexpr bool HDR_HLG_SUPPORTED = false; |
| 601 | static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false; |
| 602 | static void setupComposerCallExpectations(DisplayTransactionTest* test) { |
| 603 | EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _)) |
| 604 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE))); |
| 605 | } |
| 606 | }; |
| 607 | |
| 608 | /* ------------------------------------------------------------------------ |
| 609 | * Typical display configurations to test |
| 610 | */ |
| 611 | |
| 612 | template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy> |
| 613 | struct Case { |
| 614 | using Display = DisplayPolicy; |
| 615 | using WideColorSupport = WideColorSupportPolicy; |
| 616 | using HdrSupport = HdrSupportPolicy; |
| 617 | }; |
| 618 | |
| 619 | using SimplePrimaryDisplayCase = |
| 620 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 621 | HdrNotSupportedVariant<PrimaryDisplayVariant>>; |
| 622 | using SimpleExternalDisplayCase = |
| 623 | Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>, |
| 624 | HdrNotSupportedVariant<ExternalDisplayVariant>>; |
| 625 | using SimpleTertiaryDisplayCase = |
| 626 | Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>, |
| 627 | HdrNotSupportedVariant<TertiaryDisplayVariant>>; |
| 628 | using NonHwcVirtualDisplayCase = |
| 629 | Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>, |
| 630 | WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant>; |
| 631 | using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>; |
| 632 | using HwcVirtualDisplayCase = |
| 633 | Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant, |
| 634 | HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>>; |
| 635 | using WideColorP3ColorimetricDisplayCase = |
| 636 | Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>, |
| 637 | HdrNotSupportedVariant<PrimaryDisplayVariant>>; |
| 638 | using WideColorP3EnhanceDisplayCase = |
| 639 | Case<PrimaryDisplayVariant, WideColorP3EnhanceSupportedVariant<PrimaryDisplayVariant>, |
| 640 | HdrNotSupportedVariant<PrimaryDisplayVariant>>; |
| 641 | using Hdr10DisplayCase = |
| 642 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 643 | Hdr10SupportedVariant<PrimaryDisplayVariant>>; |
| 644 | using HdrHlgDisplayCase = |
| 645 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 646 | HdrHlgSupportedVariant<PrimaryDisplayVariant>>; |
| 647 | using HdrDolbyVisionDisplayCase = |
| 648 | Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>, |
| 649 | HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>>; |
| 650 | |
| 651 | /* ------------------------------------------------------------------------ |
| 652 | * SurfaceFlinger::setupNewDisplayDeviceInternal |
| 653 | */ |
| 654 | |
| 655 | class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest { |
| 656 | public: |
| 657 | template <typename T> |
| 658 | void setupNewDisplayDeviceInternalTest(); |
| 659 | }; |
| 660 | |
| 661 | template <typename Case> |
| 662 | void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() { |
| 663 | const sp<BBinder> displayToken = new BBinder(); |
| 664 | const sp<mock::DisplaySurface> displaySurface = new mock::DisplaySurface(); |
| 665 | const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer(); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 666 | |
| 667 | // -------------------------------------------------------------------- |
| 668 | // Preconditions |
| 669 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 670 | // Wide color displays support is configured appropriately |
| 671 | Case::WideColorSupport::injectConfigChange(this); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 672 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 673 | // The display is setup with the HWC. |
| 674 | Case::Display::injectHwcDisplay(this); |
| 675 | |
| 676 | // SurfaceFlinger will use a test-controlled factory for native window |
| 677 | // surfaces. |
| 678 | injectFakeNativeWindowSurfaceFactory(); |
| 679 | |
| 680 | // -------------------------------------------------------------------- |
| 681 | // Call Expectations |
| 682 | |
| 683 | // Various native window calls will be made. |
| 684 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
| 685 | |
| 686 | // TODO(b/69807179): SurfaceFlinger does not correctly get the active config. |
| 687 | // Case::Display::setupHwcGetActiveConfigCallExpectations(this) |
| 688 | |
| 689 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 690 | Case::HdrSupport::setupComposerCallExpectations(this); |
| 691 | |
| 692 | // -------------------------------------------------------------------- |
| 693 | // Invocation |
| 694 | |
| 695 | DisplayDeviceState state; |
| 696 | state.type = Case::Display::TYPE; |
| 697 | state.isSecure = static_cast<bool>(Case::Display::SECURE); |
| 698 | |
| 699 | auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::TYPE, state, |
| 700 | displaySurface, producer); |
| 701 | |
| 702 | // -------------------------------------------------------------------- |
| 703 | // Postconditions |
| 704 | |
| 705 | ASSERT_TRUE(device != nullptr); |
| 706 | EXPECT_EQ(Case::Display::TYPE, device->getDisplayType()); |
| 707 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); |
| 708 | EXPECT_EQ(Case::Display::WIDTH, device->getWidth()); |
| 709 | EXPECT_EQ(Case::Display::HEIGHT, device->getHeight()); |
| 710 | EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut()); |
| 711 | EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support()); |
| 712 | EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport()); |
| 713 | EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport()); |
| 714 | EXPECT_EQ(Case::Display::HWC_ACTIVE_CONFIG_ID, device->getActiveConfig()); |
| 715 | } |
| 716 | |
| 717 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) { |
| 718 | setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>(); |
| 719 | } |
| 720 | |
| 721 | TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) { |
| 722 | setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>(); |
| 723 | } |
| 724 | |
| 725 | TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) { |
| 726 | setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>(); |
| 727 | } |
| 728 | |
| 729 | TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) { |
| 730 | // We need to resize this so that the HWC thinks the virtual display |
| 731 | // is something it created. |
| 732 | mFlinger.mutableHwcDisplayData().resize(3); |
| 733 | |
| 734 | setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>(); |
| 735 | } |
| 736 | |
| 737 | TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) { |
| 738 | setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>(); |
| 739 | } |
| 740 | |
| 741 | TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3EnhanceDisplay) { |
| 742 | setupNewDisplayDeviceInternalTest<WideColorP3EnhanceDisplayCase>(); |
| 743 | } |
| 744 | |
| 745 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) { |
| 746 | setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>(); |
| 747 | } |
| 748 | |
| 749 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) { |
| 750 | setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>(); |
| 751 | } |
| 752 | |
| 753 | TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) { |
| 754 | setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>(); |
| 755 | } |
| 756 | |
| 757 | /* ------------------------------------------------------------------------ |
| 758 | * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded) |
| 759 | */ |
| 760 | |
| 761 | class HandleTransactionLockedTest : public DisplayTransactionTest { |
| 762 | public: |
| 763 | template <typename Case> |
| 764 | void setupCommonPreconditions(); |
| 765 | |
| 766 | template <typename Case> |
| 767 | void setupCommonCallExpectationsForConnectProcessing(); |
| 768 | |
| 769 | template <typename Case> |
| 770 | void setupCommonCallExpectationsForDisconnectProcessing(); |
| 771 | |
| 772 | template <typename Case> |
| 773 | void processesHotplugConnectCommon(); |
| 774 | |
| 775 | template <typename Case> |
| 776 | void ignoresHotplugConnectCommon(); |
| 777 | |
| 778 | template <typename Case> |
| 779 | void processesHotplugDisconnectCommon(); |
| 780 | |
| 781 | template <typename Case> |
| 782 | void verifyDisplayIsConnected(const sp<IBinder>& displayToken); |
| 783 | |
| 784 | template <typename Case> |
| 785 | void verifyPhysicalDisplayIsConnected(); |
| 786 | |
| 787 | void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken); |
| 788 | }; |
| 789 | |
| 790 | template <typename Case> |
| 791 | void HandleTransactionLockedTest::setupCommonPreconditions() { |
| 792 | // Wide color displays support is configured appropriately |
| 793 | Case::WideColorSupport::injectConfigChange(this); |
| 794 | |
| 795 | // SurfaceFlinger will use a test-controlled factory for BufferQueues |
| 796 | injectFakeBufferQueueFactory(); |
| 797 | |
| 798 | // SurfaceFlinger will use a test-controlled factory for native window |
| 799 | // surfaces. |
| 800 | injectFakeNativeWindowSurfaceFactory(); |
| 801 | } |
| 802 | |
| 803 | template <typename Case> |
| 804 | void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() { |
| 805 | Case::Display::setupHwcHotplugCallExpectations(this); |
| 806 | |
| 807 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); |
| 808 | Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this); |
| 809 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
| 810 | Case::Display::setupHwcGetActiveConfigCallExpectations(this); |
| 811 | |
| 812 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 813 | Case::HdrSupport::setupComposerCallExpectations(this); |
| 814 | |
| 815 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1); |
| 816 | EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, true)).Times(1); |
| 817 | } |
| 818 | |
| 819 | template <typename Case> |
| 820 | void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() { |
| 821 | EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1); |
| 822 | EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, false)).Times(1); |
| 823 | } |
| 824 | |
| 825 | template <typename Case> |
| 826 | void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) { |
| 827 | // The display device should have been set up in the list of displays. |
| 828 | ASSERT_TRUE(hasDisplayDevice(displayToken)); |
| 829 | const auto& device = getDisplayDevice(displayToken); |
| 830 | EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure()); |
| 831 | EXPECT_EQ(Case::Display::TYPE == DisplayDevice::DISPLAY_PRIMARY, device->isPrimary()); |
| 832 | |
| 833 | // The display should have been set up in the current display state |
| 834 | ASSERT_TRUE(hasCurrentDisplayState(displayToken)); |
| 835 | const auto& current = getCurrentDisplayState(displayToken); |
| 836 | EXPECT_EQ(Case::Display::TYPE, current.type); |
| 837 | |
| 838 | // The display should have been set up in the drawing display state |
| 839 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); |
| 840 | const auto& draw = getDrawingDisplayState(displayToken); |
| 841 | EXPECT_EQ(Case::Display::TYPE, draw.type); |
| 842 | } |
| 843 | |
| 844 | template <typename Case> |
| 845 | void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() { |
| 846 | // HWComposer should have an entry for the display |
| 847 | EXPECT_TRUE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
| 848 | |
| 849 | // The display should be set up as a built-in display. |
| 850 | static_assert(0 <= Case::Display::TYPE && |
| 851 | Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES, |
| 852 | "Must use a valid physical display type index for the fixed-size array"); |
| 853 | auto& displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]; |
| 854 | ASSERT_TRUE(displayToken != nullptr); |
| 855 | |
| 856 | verifyDisplayIsConnected<Case>(displayToken); |
| 857 | } |
| 858 | |
| 859 | void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) { |
| 860 | EXPECT_FALSE(hasDisplayDevice(displayToken)); |
| 861 | EXPECT_FALSE(hasCurrentDisplayState(displayToken)); |
| 862 | EXPECT_FALSE(hasDrawingDisplayState(displayToken)); |
| 863 | } |
| 864 | |
| 865 | template <typename Case> |
| 866 | void HandleTransactionLockedTest::processesHotplugConnectCommon() { |
| 867 | // -------------------------------------------------------------------- |
| 868 | // Preconditions |
| 869 | |
| 870 | setupCommonPreconditions<Case>(); |
| 871 | |
| 872 | // A hotplug connect event is enqueued for a display |
| 873 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 874 | |
| 875 | // -------------------------------------------------------------------- |
| 876 | // Call Expectations |
| 877 | |
| 878 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false)); |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 879 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 880 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 881 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 882 | // -------------------------------------------------------------------- |
| 883 | // Invocation |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 884 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 885 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 886 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 887 | // -------------------------------------------------------------------- |
| 888 | // Postconditions |
| 889 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 890 | verifyPhysicalDisplayIsConnected<Case>(); |
Lloyd Pique | e39cad2 | 2017-12-20 17:01:29 -0800 | [diff] [blame] | 891 | |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 892 | // -------------------------------------------------------------------- |
| 893 | // Cleanup conditions |
| 894 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 895 | EXPECT_CALL(*mComposer, |
| 896 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
Lloyd Pique | 1fa4d46 | 2018-01-22 18:03:16 -0800 | [diff] [blame] | 897 | .WillOnce(Return(Error::NONE)); |
| 898 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 899 | } |
| 900 | |
Lloyd Pique | c11e0d3 | 2018-01-22 18:44:59 -0800 | [diff] [blame] | 901 | template <typename Case> |
| 902 | void HandleTransactionLockedTest::ignoresHotplugConnectCommon() { |
| 903 | // -------------------------------------------------------------------- |
| 904 | // Preconditions |
| 905 | |
| 906 | setupCommonPreconditions<Case>(); |
| 907 | |
| 908 | // A hotplug connect event is enqueued for a display |
| 909 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
| 910 | |
| 911 | // -------------------------------------------------------------------- |
| 912 | // Invocation |
| 913 | |
| 914 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 915 | |
| 916 | // -------------------------------------------------------------------- |
| 917 | // Postconditions |
| 918 | |
| 919 | // HWComposer should not have an entry for the display |
| 920 | EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
| 921 | } |
| 922 | |
| 923 | template <typename Case> |
| 924 | void HandleTransactionLockedTest::processesHotplugDisconnectCommon() { |
| 925 | // -------------------------------------------------------------------- |
| 926 | // Preconditions |
| 927 | |
| 928 | setupCommonPreconditions<Case>(); |
| 929 | |
| 930 | // A hotplug disconnect event is enqueued for a display |
| 931 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); |
| 932 | |
| 933 | // The display is already completely set up. |
| 934 | Case::Display::injectHwcDisplay(this); |
| 935 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 936 | existing.inject(); |
| 937 | |
| 938 | // -------------------------------------------------------------------- |
| 939 | // Call Expectations |
| 940 | |
| 941 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 942 | |
| 943 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 944 | |
| 945 | // -------------------------------------------------------------------- |
| 946 | // Invocation |
| 947 | |
| 948 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 949 | |
| 950 | // -------------------------------------------------------------------- |
| 951 | // Postconditions |
| 952 | |
| 953 | // HWComposer should not have an entry for the display |
| 954 | EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
| 955 | |
| 956 | // The display should not be set up as a built-in display. |
| 957 | ASSERT_TRUE(0 <= Case::Display::TYPE && |
| 958 | Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES); |
| 959 | auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]; |
| 960 | EXPECT_TRUE(displayToken == nullptr); |
| 961 | |
| 962 | // The existing token should have been removed |
| 963 | verifyDisplayIsNotConnected(existing.token()); |
| 964 | } |
| 965 | |
| 966 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) { |
| 967 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); |
| 968 | } |
| 969 | |
| 970 | TEST_F(HandleTransactionLockedTest, |
| 971 | processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) { |
| 972 | // Inject an external display. |
| 973 | ExternalDisplayVariant::injectHwcDisplay(this); |
| 974 | |
| 975 | processesHotplugConnectCommon<SimplePrimaryDisplayCase>(); |
| 976 | } |
| 977 | |
| 978 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) { |
| 979 | // Inject a primary display. |
| 980 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 981 | |
| 982 | processesHotplugConnectCommon<SimpleExternalDisplayCase>(); |
| 983 | } |
| 984 | |
| 985 | TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) { |
| 986 | // Inject both a primary and external display. |
| 987 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 988 | ExternalDisplayVariant::injectHwcDisplay(this); |
| 989 | |
| 990 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 991 | |
| 992 | ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>(); |
| 993 | } |
| 994 | |
| 995 | TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) { |
| 996 | // Inject a primary display. |
| 997 | PrimaryDisplayVariant::injectHwcDisplay(this); |
| 998 | |
| 999 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true)); |
| 1000 | |
| 1001 | ignoresHotplugConnectCommon<SimpleExternalDisplayCase>(); |
| 1002 | } |
| 1003 | |
| 1004 | TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) { |
| 1005 | processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>(); |
| 1006 | } |
| 1007 | |
| 1008 | TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) { |
| 1009 | processesHotplugDisconnectCommon<SimpleExternalDisplayCase>(); |
| 1010 | } |
| 1011 | |
| 1012 | TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) { |
| 1013 | using Case = SimplePrimaryDisplayCase; |
| 1014 | |
| 1015 | // -------------------------------------------------------------------- |
| 1016 | // Preconditions |
| 1017 | |
| 1018 | setupCommonPreconditions<Case>(); |
| 1019 | |
| 1020 | // A hotplug connect event is enqueued for a display |
| 1021 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
| 1022 | // A hotplug disconnect event is also enqueued for the same display |
| 1023 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); |
| 1024 | |
| 1025 | // -------------------------------------------------------------------- |
| 1026 | // Call Expectations |
| 1027 | |
| 1028 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1029 | |
| 1030 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
| 1031 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 1032 | |
| 1033 | EXPECT_CALL(*mComposer, |
| 1034 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
| 1035 | .WillOnce(Return(Error::NONE)); |
| 1036 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 1037 | |
| 1038 | // -------------------------------------------------------------------- |
| 1039 | // Invocation |
| 1040 | |
| 1041 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1042 | |
| 1043 | // -------------------------------------------------------------------- |
| 1044 | // Postconditions |
| 1045 | |
| 1046 | // HWComposer should not have an entry for the display |
| 1047 | EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID)); |
| 1048 | |
| 1049 | // The display should not be set up as a primary built-in display. |
| 1050 | ASSERT_TRUE(0 <= Case::Display::TYPE && |
| 1051 | Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES); |
| 1052 | auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]; |
| 1053 | EXPECT_TRUE(displayToken == nullptr); |
| 1054 | } |
| 1055 | |
| 1056 | TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) { |
| 1057 | using Case = SimplePrimaryDisplayCase; |
| 1058 | |
| 1059 | // -------------------------------------------------------------------- |
| 1060 | // Preconditions |
| 1061 | |
| 1062 | setupCommonPreconditions<Case>(); |
| 1063 | |
| 1064 | // The display is already completely set up. |
| 1065 | Case::Display::injectHwcDisplay(this); |
| 1066 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1067 | existing.inject(); |
| 1068 | |
| 1069 | // A hotplug disconnect event is enqueued for a display |
| 1070 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected); |
| 1071 | // A hotplug connect event is also enqueued for the same display |
| 1072 | Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected); |
| 1073 | |
| 1074 | // -------------------------------------------------------------------- |
| 1075 | // Call Expectations |
| 1076 | |
| 1077 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1078 | |
| 1079 | setupCommonCallExpectationsForConnectProcessing<Case>(); |
| 1080 | setupCommonCallExpectationsForDisconnectProcessing<Case>(); |
| 1081 | |
| 1082 | // -------------------------------------------------------------------- |
| 1083 | // Invocation |
| 1084 | |
| 1085 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1086 | |
| 1087 | // -------------------------------------------------------------------- |
| 1088 | // Postconditions |
| 1089 | |
| 1090 | // The existing token should have been removed |
| 1091 | verifyDisplayIsNotConnected(existing.token()); |
| 1092 | static_assert(0 <= Case::Display::TYPE && |
| 1093 | Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES, |
| 1094 | "Display type must be a built-in display"); |
| 1095 | EXPECT_NE(existing.token(), mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]); |
| 1096 | |
| 1097 | // A new display should be connected in its place |
| 1098 | |
| 1099 | verifyPhysicalDisplayIsConnected<Case>(); |
| 1100 | |
| 1101 | // -------------------------------------------------------------------- |
| 1102 | // Cleanup conditions |
| 1103 | |
| 1104 | EXPECT_CALL(*mComposer, |
| 1105 | setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE)) |
| 1106 | .WillOnce(Return(Error::NONE)); |
| 1107 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 1108 | } |
| 1109 | |
| 1110 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) { |
| 1111 | using Case = HwcVirtualDisplayCase; |
| 1112 | |
| 1113 | // -------------------------------------------------------------------- |
| 1114 | // Preconditions |
| 1115 | |
| 1116 | // The HWC supports at least one virtual display |
| 1117 | injectMockComposer(1); |
| 1118 | |
| 1119 | setupCommonPreconditions<Case>(); |
| 1120 | |
| 1121 | // A virtual display was added to the current state, and it has a |
| 1122 | // surface(producer) |
| 1123 | sp<BBinder> displayToken = new BBinder(); |
| 1124 | DisplayDeviceState info; |
| 1125 | info.type = Case::Display::TYPE; |
| 1126 | info.isSecure = static_cast<bool>(Case::Display::SECURE); |
| 1127 | |
| 1128 | sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()}; |
| 1129 | info.surface = surface; |
| 1130 | mFlinger.mutableCurrentState().displays.add(displayToken, info); |
| 1131 | |
| 1132 | // -------------------------------------------------------------------- |
| 1133 | // Call Expectations |
| 1134 | |
| 1135 | Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this); |
| 1136 | Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this); |
| 1137 | |
| 1138 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _)) |
| 1139 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR))); |
| 1140 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _)) |
| 1141 | .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR))); |
| 1142 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _)) |
| 1143 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT), |
| 1144 | Return(NO_ERROR))); |
| 1145 | EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _)) |
| 1146 | .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR))); |
| 1147 | |
| 1148 | EXPECT_CALL(*surface, setAsyncMode(true)).Times(1); |
| 1149 | |
| 1150 | EXPECT_CALL(*mProducer, connect(_, _, _, _)).Times(1); |
| 1151 | EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1); |
| 1152 | |
| 1153 | Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this); |
| 1154 | Case::WideColorSupport::setupComposerCallExpectations(this); |
| 1155 | Case::HdrSupport::setupComposerCallExpectations(this); |
| 1156 | |
| 1157 | // -------------------------------------------------------------------- |
| 1158 | // Invocation |
| 1159 | |
| 1160 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1161 | |
| 1162 | // -------------------------------------------------------------------- |
| 1163 | // Postconditions |
| 1164 | |
| 1165 | // The display device should have been set up in the list of displays. |
| 1166 | verifyDisplayIsConnected<Case>(displayToken); |
| 1167 | |
| 1168 | // -------------------------------------------------------------------- |
| 1169 | // Cleanup conditions |
| 1170 | |
| 1171 | EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID)) |
| 1172 | .WillOnce(Return(Error::NONE)); |
| 1173 | EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR)); |
| 1174 | } |
| 1175 | |
| 1176 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) { |
| 1177 | using Case = HwcVirtualDisplayCase; |
| 1178 | |
| 1179 | // -------------------------------------------------------------------- |
| 1180 | // Preconditions |
| 1181 | |
| 1182 | // The HWC supports at least one virtual display |
| 1183 | injectMockComposer(1); |
| 1184 | |
| 1185 | setupCommonPreconditions<Case>(); |
| 1186 | |
| 1187 | // A virtual display was added to the current state, but it does not have a |
| 1188 | // surface. |
| 1189 | sp<BBinder> displayToken = new BBinder(); |
| 1190 | |
| 1191 | DisplayDeviceState info; |
| 1192 | info.type = Case::Display::TYPE; |
| 1193 | info.isSecure = static_cast<bool>(Case::Display::SECURE); |
| 1194 | |
| 1195 | mFlinger.mutableCurrentState().displays.add(displayToken, info); |
| 1196 | |
| 1197 | // -------------------------------------------------------------------- |
| 1198 | // Call Expectations |
| 1199 | |
| 1200 | // -------------------------------------------------------------------- |
| 1201 | // Invocation |
| 1202 | |
| 1203 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1204 | |
| 1205 | // -------------------------------------------------------------------- |
| 1206 | // Postconditions |
| 1207 | |
| 1208 | // There will not be a display device set up. |
| 1209 | EXPECT_FALSE(hasDisplayDevice(displayToken)); |
| 1210 | |
| 1211 | // The drawing display state will be set from the current display state. |
| 1212 | ASSERT_TRUE(hasDrawingDisplayState(displayToken)); |
| 1213 | const auto& draw = getDrawingDisplayState(displayToken); |
| 1214 | EXPECT_EQ(Case::Display::TYPE, draw.type); |
| 1215 | } |
| 1216 | |
| 1217 | TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) { |
| 1218 | using Case = HwcVirtualDisplayCase; |
| 1219 | |
| 1220 | // -------------------------------------------------------------------- |
| 1221 | // Preconditions |
| 1222 | |
| 1223 | // A virtual display is set up but is removed from the current state. |
| 1224 | mFlinger.mutableHwcDisplayData().resize(3); |
| 1225 | Case::Display::injectHwcDisplay(this); |
| 1226 | auto existing = Case::Display::makeFakeExistingDisplayInjector(this); |
| 1227 | existing.inject(); |
| 1228 | mFlinger.mutableCurrentState().displays.removeItem(existing.token()); |
| 1229 | |
| 1230 | // -------------------------------------------------------------------- |
| 1231 | // Call Expectations |
| 1232 | |
| 1233 | EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false)); |
| 1234 | |
| 1235 | // -------------------------------------------------------------------- |
| 1236 | // Invocation |
| 1237 | |
| 1238 | mFlinger.handleTransactionLocked(eDisplayTransactionNeeded); |
| 1239 | |
| 1240 | // -------------------------------------------------------------------- |
| 1241 | // Postconditions |
| 1242 | |
| 1243 | // The existing token should have been removed |
| 1244 | verifyDisplayIsNotConnected(existing.token()); |
| 1245 | } |
| 1246 | |
Lloyd Pique | f58625d | 2017-12-19 13:22:33 -0800 | [diff] [blame] | 1247 | } // namespace |
| 1248 | } // namespace android |