blob: f90e2db29339d532dc7e1db31688ad9df804f7e9 [file] [log] [blame]
Lloyd Piquef58625d2017-12-19 13:22:33 -08001/*
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 Piquecbe00012018-02-02 15:40:42 -080026#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 Piquef58625d2017-12-19 13:22:33 -080037
38namespace android {
39namespace {
40
Lloyd Piquee39cad22017-12-20 17:01:29 -080041using testing::_;
42using testing::ByMove;
43using testing::DoAll;
44using testing::Mock;
45using testing::Return;
46using testing::SetArgPointee;
47
48using android::hardware::graphics::common::V1_0::Hdr;
Peiyong Lin0e7a7912018-04-05 14:36:36 -070049using android::hardware::graphics::common::V1_1::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080050using android::Hwc2::Error;
51using android::Hwc2::IComposer;
52using android::Hwc2::IComposerClient;
Lloyd Piquefc12f562018-01-22 18:44:59 -080053using android::Hwc2::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080054
Lloyd Piquefc12f562018-01-22 18:44:59 -080055using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
56using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080057using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquefc12f562018-01-22 18:44:59 -080058using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080059
Lloyd Piquefc12f562018-01-22 18:44:59 -080060constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080061constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquefc12f562018-01-22 18:44:59 -080062constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080063
Lloyd Piquefc12f562018-01-22 18:44:59 -080064/* ------------------------------------------------------------------------
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
73BOOL_SUBSTITUTE(Critical);
74BOOL_SUBSTITUTE(Async);
75BOOL_SUBSTITUTE(Secure);
76
77/* ------------------------------------------------------------------------
78 *
79 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080080
Lloyd Piquef58625d2017-12-19 13:22:33 -080081class DisplayTransactionTest : public testing::Test {
Lloyd Piquefc12f562018-01-22 18:44:59 -080082public:
Lloyd Piquef58625d2017-12-19 13:22:33 -080083 DisplayTransactionTest();
84 ~DisplayTransactionTest() override;
85
Lloyd Pique1fa4d462018-01-22 18:03:16 -080086 // --------------------------------------------------------------------
Lloyd Piquefc12f562018-01-22 18:44:59 -080087 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -080088
Lloyd Piquefc12f562018-01-22 18:44:59 -080089 void injectMockComposer(int virtualDisplayCount);
90 void injectFakeBufferQueueFactory();
91 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -080092
93 // --------------------------------------------------------------------
94 // Postcondition helpers
95
Lloyd Piquefc12f562018-01-22 18:44:59 -080096 bool hasHwcDisplay(hwc2_display_t displayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -080097 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 Pique5b36f3f2018-01-17 11:57:07 -0800107
Lloyd Piquef58625d2017-12-19 13:22:33 -0800108 TestableSurfaceFlinger mFlinger;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800109 mock::EventThread* mEventThread = new mock::EventThread();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800110 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800111
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 Piquefc12f562018-01-22 18:44:59 -0800116 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800117 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
118 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800119
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 Pique1fa4d462018-01-22 18:03:16 -0800123 mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
124 sp<mock::NativeWindow> mNativeWindow;
125 RE::mock::Surface* mRenderSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800126};
127
128DisplayTransactionTest::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 Piquee39cad22017-12-20 17:01:29 -0800132
Lloyd Piquefc12f562018-01-22 18:44:59 -0800133 // 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 Pique5b36f3f2018-01-17 11:57:07 -0800140 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
141 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
142 });
143
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800144 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 Piquee39cad22017-12-20 17:01:29 -0800150 mFlinger.mutableEventThread().reset(mEventThread);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800151 mFlinger.mutableEventQueue().reset(mMessageQueue);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800152 mFlinger.setupRenderEngine(std::unique_ptr<RE::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800153 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800154
Lloyd Piquefc12f562018-01-22 18:44:59 -0800155 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800156}
157
158DisplayTransactionTest::~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 Piquefc12f562018-01-22 18:44:59 -0800164void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
165 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800166 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 Piquef58625d2017-12-19 13:22:33 -0800170
Lloyd Piquee39cad22017-12-20 17:01:29 -0800171 Mock::VerifyAndClear(mComposer);
172}
173
Lloyd Piquefc12f562018-01-22 18:44:59 -0800174void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800175 // This setup is only expected once per test.
176 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
177
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800178 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 Pique1fa4d462018-01-22 18:03:16 -0800185}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800186
Lloyd Piquefc12f562018-01-22 18:44:59 -0800187void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800188 // 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 Pique1fa4d462018-01-22 18:03:16 -0800196}
197
Lloyd Piquefc12f562018-01-22 18:44:59 -0800198bool DisplayTransactionTest::hasHwcDisplay(hwc2_display_t displayId) {
199 return mFlinger.mutableHwcDisplaySlots().count(displayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800200}
201
202bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
203 return mFlinger.mutableTransactionFlags() & flag;
204}
205
206bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
207 return mFlinger.mutableDisplays().indexOfKey(displayToken) >= 0;
208}
209
210sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
211 return mFlinger.mutableDisplays().valueFor(displayToken);
212}
213
214bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
215 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
216}
217
218const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
219 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
220}
221
222bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
223 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
224}
225
226const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
227 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
228}
229
230/* ------------------------------------------------------------------------
Lloyd Piquefc12f562018-01-22 18:44:59 -0800231 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800232 */
233
Lloyd Piquefc12f562018-01-22 18:44:59 -0800234template <DisplayDevice::DisplayType type, DisplayDevice::DisplayType hwcId, int width, int height,
235 Critical critical, Async async, Secure secure, int grallocUsage>
236struct 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
297template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant>
298struct 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)));
357 }
358
359 // Called by tests to set up HWC call expectations
360 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
361 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
362 .WillOnce(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
363 }
364};
365
366struct NonHwcDisplayVariant {
367 static constexpr int HWC_ACTIVE_CONFIG_ID = 0;
368
369 static void injectHwcDisplay(DisplayTransactionTest*) {}
370
371 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
372 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
373 }
374};
375
376// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
377constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
378 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
379
380template <hwc2_display_t hwcDisplayId, DisplayDevice::DisplayType type, int width, int height,
381 Critical critical>
382struct PhysicalDisplayVariant
383 : public DisplayVariant<type, type, width, height, critical, Async::FALSE, Secure::TRUE,
384 GRALLOC_USAGE_PHYSICAL_DISPLAY>,
385 public HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
386 DisplayVariant<type, type, width, height, critical, Async::FALSE,
387 Secure::TRUE, GRALLOC_USAGE_PHYSICAL_DISPLAY>> {};
388
389// A primary display is a physical display that is critical
390using PrimaryDisplayVariant =
391 PhysicalDisplayVariant<1001, DisplayDevice::DISPLAY_PRIMARY, 3840, 2160, Critical::TRUE>;
392
393// An external display is physical display that is not critical.
394using ExternalDisplayVariant =
395 PhysicalDisplayVariant<1002, DisplayDevice::DISPLAY_EXTERNAL, 1920, 1280, Critical::FALSE>;
396
397using TertiaryDisplayVariant =
398 PhysicalDisplayVariant<1003, DisplayDevice::DISPLAY_EXTERNAL, 1600, 1200, Critical::FALSE>;
399
400// A virtual display not supported by the HWC.
401constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
402
403template <int width, int height, Secure secure>
404struct NonHwcVirtualDisplayVariant
405 : public DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_ID_INVALID,
406 width, height, Critical::FALSE, Async::TRUE, secure,
407 GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>,
408 public NonHwcDisplayVariant {
409 using Base = DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_ID_INVALID,
410 width, height, Critical::FALSE, Async::TRUE, secure,
411 GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
412
413 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
414 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
415 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
416 }
417};
418
419// A virtual display supported by the HWC.
420constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
421
422template <int width, int height, Secure secure>
423struct HwcVirtualDisplayVariant
424 : public DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_VIRTUAL, width,
425 height, Critical::FALSE, Async::TRUE, secure,
426 GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
427 public HwcDisplayVariant<1010, HWC2::DisplayType::Virtual,
428 NonHwcVirtualDisplayVariant<width, height, secure>> {
429 using Base =
430 DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_VIRTUAL, width,
431 height, Critical::FALSE, Async::TRUE, secure, GRALLOC_USAGE_HW_COMPOSER>;
432 using Self = HwcVirtualDisplayVariant<width, height, secure>;
433
434 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
435 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
436 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
437 }
438
439 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
440 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
441 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
442 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
443 }
444};
445
446// For this variant, SurfaceFlinger should not configure itself with wide
447// display support, so the display should not be configured for wide-color
448// support.
449struct WideColorSupportNotConfiguredVariant {
450 static constexpr bool WIDE_COLOR_SUPPORTED = false;
451
452 static void injectConfigChange(DisplayTransactionTest* test) {
453 test->mFlinger.mutableHasWideColorDisplay() = false;
454 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
455 }
456
457 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
458 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
459 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
460 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
461 }
462};
463
464// For this variant, SurfaceFlinger should configure itself with wide display
465// support, and the display should respond with an non-empty list of supported
466// color modes. Wide-color support should be configured.
467template <typename Display>
468struct WideColorP3ColorimetricSupportedVariant {
469 static constexpr bool WIDE_COLOR_SUPPORTED = true;
470
471 static void injectConfigChange(DisplayTransactionTest* test) {
472 test->mFlinger.mutableHasWideColorDisplay() = true;
473 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
474 }
475
476 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
477 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
478 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
479 Return(Error::NONE)));
480 EXPECT_CALL(*test->mComposer,
481 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
482 .WillOnce(DoAll(SetArgPointee<2>(
483 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
484 Return(Error::NONE)));
485 EXPECT_CALL(*test->mComposer,
486 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
487 RenderIntent::COLORIMETRIC))
488 .WillOnce(Return(Error::NONE));
489 }
490};
491
492// For this variant, SurfaceFlinger should configure itself with wide color
493// display support, and the display should respond with an non-empty list of
494// supported color modes.
495template <typename Display>
496struct WideColorP3EnhanceSupportedVariant {
497 static constexpr bool WIDE_COLOR_SUPPORTED = true;
498
499 static void injectConfigChange(DisplayTransactionTest* test) {
500 test->mFlinger.mutableHasWideColorDisplay() = true;
501 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::ENHANCED;
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>({ColorMode::DISPLAY_P3})),
507 Return(Error::NONE)));
508 EXPECT_CALL(*test->mComposer,
509 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
510 .WillOnce(
511 DoAll(SetArgPointee<2>(std::vector<RenderIntent>({RenderIntent::ENHANCE})),
512 Return(Error::NONE)));
513 EXPECT_CALL(*test->mComposer,
514 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB, RenderIntent::ENHANCE))
515 .WillOnce(Return(Error::NONE));
516 }
517};
518
519// For this variant, SurfaceFlinger should configure itself with wide display
520// support, but the display should respond with an empty list of supported color
521// modes. Wide-color support for the display should not be configured.
522template <typename Display>
523struct WideColorNotSupportedVariant {
524 static constexpr bool WIDE_COLOR_SUPPORTED = false;
525
526 static void injectConfigChange(DisplayTransactionTest* test) {
527 test->mFlinger.mutableHasWideColorDisplay() = true;
528 }
529
530 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
531 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
532 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
533 EXPECT_CALL(*test->mComposer,
534 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::NATIVE,
535 RenderIntent::COLORIMETRIC))
536 .WillOnce(Return(Error::NONE));
537 }
538};
539
540// For this variant, the display is not a HWC display, so no HDR support should
541// be configured.
542struct NonHwcDisplayHdrSupportVariant {
543 static constexpr bool HDR10_SUPPORTED = false;
544 static constexpr bool HDR_HLG_SUPPORTED = false;
545 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
546 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
547 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
548 }
549};
550
551// For this variant, the composer should respond with a non-empty list of HDR
552// modes containing HDR10, so HDR10 support should be configured.
553template <typename Display>
554struct Hdr10SupportedVariant {
555 static constexpr bool HDR10_SUPPORTED = true;
556 static constexpr bool HDR_HLG_SUPPORTED = false;
557 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
558 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
559 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
560 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
561 Return(Error::NONE)));
562 }
563};
564
565// For this variant, the composer should respond with a non-empty list of HDR
566// modes containing HLG, so HLG support should be configured.
567template <typename Display>
568struct HdrHlgSupportedVariant {
569 static constexpr bool HDR10_SUPPORTED = false;
570 static constexpr bool HDR_HLG_SUPPORTED = true;
571 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
572 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
573 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
574 .WillOnce(
575 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
576 }
577};
578
579// For this variant, the composer should respond with a non-empty list of HDR
580// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
581template <typename Display>
582struct HdrDolbyVisionSupportedVariant {
583 static constexpr bool HDR10_SUPPORTED = false;
584 static constexpr bool HDR_HLG_SUPPORTED = false;
585 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
586 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
587 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
588 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
589 Return(Error::NONE)));
590 }
591};
592
593// For this variant, the composer should respond with am empty list of HDR
594// modes, so no HDR support should be configured.
595template <typename Display>
596struct HdrNotSupportedVariant {
597 static constexpr bool HDR10_SUPPORTED = false;
598 static constexpr bool HDR_HLG_SUPPORTED = false;
599 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
600 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
601 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
602 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
603 }
604};
605
606/* ------------------------------------------------------------------------
607 * Typical display configurations to test
608 */
609
610template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy>
611struct Case {
612 using Display = DisplayPolicy;
613 using WideColorSupport = WideColorSupportPolicy;
614 using HdrSupport = HdrSupportPolicy;
615};
616
617using SimplePrimaryDisplayCase =
618 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
619 HdrNotSupportedVariant<PrimaryDisplayVariant>>;
620using SimpleExternalDisplayCase =
621 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
622 HdrNotSupportedVariant<ExternalDisplayVariant>>;
623using SimpleTertiaryDisplayCase =
624 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
625 HdrNotSupportedVariant<TertiaryDisplayVariant>>;
626using NonHwcVirtualDisplayCase =
627 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
628 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant>;
629using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
630using HwcVirtualDisplayCase =
631 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
632 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>>;
633using WideColorP3ColorimetricDisplayCase =
634 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
635 HdrNotSupportedVariant<PrimaryDisplayVariant>>;
636using WideColorP3EnhanceDisplayCase =
637 Case<PrimaryDisplayVariant, WideColorP3EnhanceSupportedVariant<PrimaryDisplayVariant>,
638 HdrNotSupportedVariant<PrimaryDisplayVariant>>;
639using Hdr10DisplayCase =
640 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
641 Hdr10SupportedVariant<PrimaryDisplayVariant>>;
642using HdrHlgDisplayCase =
643 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
644 HdrHlgSupportedVariant<PrimaryDisplayVariant>>;
645using HdrDolbyVisionDisplayCase =
646 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
647 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>>;
648
649/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800650 *
651 * SurfaceFlinger::onHotplugReceived
652 */
653
654TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
655 constexpr int currentSequenceId = 123;
656 constexpr hwc2_display_t displayId1 = 456;
657 constexpr hwc2_display_t displayId2 = 654;
658
659 // --------------------------------------------------------------------
660 // Preconditions
661
662 // Set the current sequence id for accepted events
663 mFlinger.mutableComposerSequenceId() = currentSequenceId;
664
665 // Set the main thread id so that the current thread does not appear to be
666 // the main thread.
667 mFlinger.mutableMainThreadId() = std::thread::id();
668
669 // --------------------------------------------------------------------
670 // Call Expectations
671
672 // We expect invalidate() to be invoked once to trigger display transaction
673 // processing.
674 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
675
676 // --------------------------------------------------------------------
677 // Invocation
678
679 // Simulate two hotplug events (a connect and a disconnect)
680 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Connected);
681 mFlinger.onHotplugReceived(currentSequenceId, displayId2, HWC2::Connection::Disconnected);
682
683 // --------------------------------------------------------------------
684 // Postconditions
685
686 // The display transaction needed flag should be set.
687 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
688
689 // All events should be in the pending event queue.
690 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
691 ASSERT_EQ(2u, pendingEvents.size());
692 EXPECT_EQ(displayId1, pendingEvents[0].display);
693 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
694 EXPECT_EQ(displayId2, pendingEvents[1].display);
695 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
696}
697
698TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
699 constexpr int currentSequenceId = 123;
700 constexpr int otherSequenceId = 321;
701 constexpr hwc2_display_t displayId = 456;
702
703 // --------------------------------------------------------------------
704 // Preconditions
705
706 // Set the current sequence id for accepted events
707 mFlinger.mutableComposerSequenceId() = currentSequenceId;
708
709 // Set the main thread id so that the current thread does not appear to be
710 // the main thread.
711 mFlinger.mutableMainThreadId() = std::thread::id();
712
713 // --------------------------------------------------------------------
714 // Call Expectations
715
716 // We do not expect any calls to invalidate().
717 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
718
719 // --------------------------------------------------------------------
720 // Invocation
721
722 // Call with an unexpected sequence id
723 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
724
725 // --------------------------------------------------------------------
726 // Postconditions
727
728 // The display transaction needed flag should not be set
729 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
730
731 // There should be no pending events
732 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
733}
734
735TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
736 constexpr int currentSequenceId = 123;
737 constexpr hwc2_display_t displayId1 = 456;
738
739 // --------------------------------------------------------------------
740 // Note:
741 // --------------------------------------------------------------------
742 // This test case is a bit tricky. We want to verify that
743 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
744 // don't really want to provide coverage for everything the later function
745 // does as there are specific tests for it.
746 // --------------------------------------------------------------------
747
748 // --------------------------------------------------------------------
749 // Preconditions
750
751 // Set the current sequence id for accepted events
752 mFlinger.mutableComposerSequenceId() = currentSequenceId;
753
754 // Set the main thread id so that the current thread does appear to be the
755 // main thread.
756 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
757
758 // --------------------------------------------------------------------
759 // Call Expectations
760
761 // We expect invalidate() to be invoked once to trigger display transaction
762 // processing.
763 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
764
765 // --------------------------------------------------------------------
766 // Invocation
767
768 // Simulate a disconnect on a display id that is not connected. This should
769 // be enqueued by onHotplugReceived(), and dequeued by
770 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
771 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
772
773 // --------------------------------------------------------------------
774 // Postconditions
775
776 // The display transaction needed flag should be set.
777 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
778
779 // There should be no event queued on return, as it should have been
780 // processed.
781 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
782}
783
784/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -0800785 * SurfaceFlinger::createDisplay
786 */
787
788TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
789 const String8 name("virtual.test");
790
791 // --------------------------------------------------------------------
792 // Call Expectations
793
794 // The call should notify the interceptor that a display was created.
795 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
796
797 // --------------------------------------------------------------------
798 // Invocation
799
800 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
801
802 // --------------------------------------------------------------------
803 // Postconditions
804
805 // The display should have been added to the current state
806 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
807 const auto& display = getCurrentDisplayState(displayToken);
808 EXPECT_EQ(DisplayDevice::DISPLAY_VIRTUAL, display.type);
809 EXPECT_EQ(false, display.isSecure);
810 EXPECT_EQ(name.string(), display.displayName);
811
812 // --------------------------------------------------------------------
813 // Cleanup conditions
814
815 // Destroying the display invalidates the display state.
816 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
817}
818
819TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
820 const String8 name("virtual.test");
821
822 // --------------------------------------------------------------------
823 // Call Expectations
824
825 // The call should notify the interceptor that a display was created.
826 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
827
828 // --------------------------------------------------------------------
829 // Invocation
830
831 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
832
833 // --------------------------------------------------------------------
834 // Postconditions
835
836 // The display should have been added to the current state
837 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
838 const auto& display = getCurrentDisplayState(displayToken);
839 EXPECT_EQ(DisplayDevice::DISPLAY_VIRTUAL, display.type);
840 EXPECT_EQ(true, display.isSecure);
841 EXPECT_EQ(name.string(), display.displayName);
842
843 // --------------------------------------------------------------------
844 // Cleanup conditions
845
846 // Destroying the display invalidates the display state.
847 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
848}
849
850/* ------------------------------------------------------------------------
851 * SurfaceFlinger::destroyDisplay
852 */
853
854TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
855 using Case = NonHwcVirtualDisplayCase;
856
857 // --------------------------------------------------------------------
858 // Preconditions
859
860 // A virtual display exists
861 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
862 existing.inject();
863
864 // --------------------------------------------------------------------
865 // Call Expectations
866
867 // The call should notify the interceptor that a display was created.
868 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
869
870 // Destroying the display invalidates the display state.
871 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
872
873 // --------------------------------------------------------------------
874 // Invocation
875
876 mFlinger.destroyDisplay(existing.token());
877
878 // --------------------------------------------------------------------
879 // Postconditions
880
881 // The display should have been removed from the current state
882 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
883
884 // Ths display should still exist in the drawing state
885 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
886
887 // The display transaction needed flasg should be set
888 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
889}
890
891TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
892 // --------------------------------------------------------------------
893 // Preconditions
894
895 sp<BBinder> displayToken = new BBinder();
896
897 // --------------------------------------------------------------------
898 // Invocation
899
900 mFlinger.destroyDisplay(displayToken);
901}
902
903/* ------------------------------------------------------------------------
Lloyd Piquefc12f562018-01-22 18:44:59 -0800904 * SurfaceFlinger::setupNewDisplayDeviceInternal
905 */
906
907class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
908public:
909 template <typename T>
910 void setupNewDisplayDeviceInternalTest();
911};
912
913template <typename Case>
914void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
915 const sp<BBinder> displayToken = new BBinder();
916 const sp<mock::DisplaySurface> displaySurface = new mock::DisplaySurface();
917 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800918
919 // --------------------------------------------------------------------
920 // Preconditions
921
Lloyd Piquefc12f562018-01-22 18:44:59 -0800922 // Wide color displays support is configured appropriately
923 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800924
Lloyd Piquefc12f562018-01-22 18:44:59 -0800925 // The display is setup with the HWC.
926 Case::Display::injectHwcDisplay(this);
927
928 // SurfaceFlinger will use a test-controlled factory for native window
929 // surfaces.
930 injectFakeNativeWindowSurfaceFactory();
931
932 // --------------------------------------------------------------------
933 // Call Expectations
934
935 // Various native window calls will be made.
936 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
937
938 // TODO(b/69807179): SurfaceFlinger does not correctly get the active config.
939 // Case::Display::setupHwcGetActiveConfigCallExpectations(this)
940
941 Case::WideColorSupport::setupComposerCallExpectations(this);
942 Case::HdrSupport::setupComposerCallExpectations(this);
943
944 // --------------------------------------------------------------------
945 // Invocation
946
947 auto state = DisplayDeviceState(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE));
948 auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::TYPE, state,
949 displaySurface, producer);
950
951 // --------------------------------------------------------------------
952 // Postconditions
953
954 ASSERT_TRUE(device != nullptr);
955 EXPECT_EQ(Case::Display::TYPE, device->getDisplayType());
956 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
957 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
958 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
959 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
960 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
961 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
962 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
963 EXPECT_EQ(Case::Display::HWC_ACTIVE_CONFIG_ID, device->getActiveConfig());
964}
965
966TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
967 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
968}
969
970TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
971 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
972}
973
974TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
975 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
976}
977
978TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
979 // We need to resize this so that the HWC thinks the virtual display
980 // is something it created.
981 mFlinger.mutableHwcDisplayData().resize(3);
982
983 setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>();
984}
985
986TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
987 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
988}
989
990TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3EnhanceDisplay) {
991 setupNewDisplayDeviceInternalTest<WideColorP3EnhanceDisplayCase>();
992}
993
994TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
995 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
996}
997
998TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
999 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1000}
1001
1002TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1003 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1004}
1005
1006/* ------------------------------------------------------------------------
1007 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1008 */
1009
1010class HandleTransactionLockedTest : public DisplayTransactionTest {
1011public:
1012 template <typename Case>
1013 void setupCommonPreconditions();
1014
1015 template <typename Case>
1016 void setupCommonCallExpectationsForConnectProcessing();
1017
1018 template <typename Case>
1019 void setupCommonCallExpectationsForDisconnectProcessing();
1020
1021 template <typename Case>
1022 void processesHotplugConnectCommon();
1023
1024 template <typename Case>
1025 void ignoresHotplugConnectCommon();
1026
1027 template <typename Case>
1028 void processesHotplugDisconnectCommon();
1029
1030 template <typename Case>
1031 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1032
1033 template <typename Case>
1034 void verifyPhysicalDisplayIsConnected();
1035
1036 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1037};
1038
1039template <typename Case>
1040void HandleTransactionLockedTest::setupCommonPreconditions() {
1041 // Wide color displays support is configured appropriately
1042 Case::WideColorSupport::injectConfigChange(this);
1043
1044 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1045 injectFakeBufferQueueFactory();
1046
1047 // SurfaceFlinger will use a test-controlled factory for native window
1048 // surfaces.
1049 injectFakeNativeWindowSurfaceFactory();
1050}
1051
1052template <typename Case>
1053void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1054 Case::Display::setupHwcHotplugCallExpectations(this);
1055
1056 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1057 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1058 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1059 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1060
1061 Case::WideColorSupport::setupComposerCallExpectations(this);
1062 Case::HdrSupport::setupComposerCallExpectations(this);
1063
1064 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1065 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, true)).Times(1);
1066}
1067
1068template <typename Case>
1069void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1070 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1071 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, false)).Times(1);
1072}
1073
1074template <typename Case>
1075void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1076 // The display device should have been set up in the list of displays.
1077 ASSERT_TRUE(hasDisplayDevice(displayToken));
1078 const auto& device = getDisplayDevice(displayToken);
1079 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
1080 EXPECT_EQ(Case::Display::TYPE == DisplayDevice::DISPLAY_PRIMARY, device->isPrimary());
1081
1082 // The display should have been set up in the current display state
1083 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1084 const auto& current = getCurrentDisplayState(displayToken);
1085 EXPECT_EQ(Case::Display::TYPE, current.type);
1086
1087 // The display should have been set up in the drawing display state
1088 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1089 const auto& draw = getDrawingDisplayState(displayToken);
1090 EXPECT_EQ(Case::Display::TYPE, draw.type);
1091}
1092
1093template <typename Case>
1094void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1095 // HWComposer should have an entry for the display
1096 EXPECT_TRUE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1097
1098 // The display should be set up as a built-in display.
1099 static_assert(0 <= Case::Display::TYPE &&
1100 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
1101 "Must use a valid physical display type index for the fixed-size array");
1102 auto& displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE];
1103 ASSERT_TRUE(displayToken != nullptr);
1104
1105 verifyDisplayIsConnected<Case>(displayToken);
1106}
1107
1108void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1109 EXPECT_FALSE(hasDisplayDevice(displayToken));
1110 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1111 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1112}
1113
1114template <typename Case>
1115void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1116 // --------------------------------------------------------------------
1117 // Preconditions
1118
1119 setupCommonPreconditions<Case>();
1120
1121 // A hotplug connect event is enqueued for a display
1122 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001123
1124 // --------------------------------------------------------------------
1125 // Call Expectations
1126
1127 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001128
Lloyd Piquefc12f562018-01-22 18:44:59 -08001129 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001130
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001131 // --------------------------------------------------------------------
1132 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001133
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001134 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001135
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001136 // --------------------------------------------------------------------
1137 // Postconditions
1138
Lloyd Piquefc12f562018-01-22 18:44:59 -08001139 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001140
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001141 // --------------------------------------------------------------------
1142 // Cleanup conditions
1143
Lloyd Piquefc12f562018-01-22 18:44:59 -08001144 EXPECT_CALL(*mComposer,
1145 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001146 .WillOnce(Return(Error::NONE));
1147 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001148}
1149
Lloyd Piquefc12f562018-01-22 18:44:59 -08001150template <typename Case>
1151void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1152 // --------------------------------------------------------------------
1153 // Preconditions
1154
1155 setupCommonPreconditions<Case>();
1156
1157 // A hotplug connect event is enqueued for a display
1158 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1159
1160 // --------------------------------------------------------------------
1161 // Invocation
1162
1163 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1164
1165 // --------------------------------------------------------------------
1166 // Postconditions
1167
1168 // HWComposer should not have an entry for the display
1169 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1170}
1171
1172template <typename Case>
1173void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1174 // --------------------------------------------------------------------
1175 // Preconditions
1176
1177 setupCommonPreconditions<Case>();
1178
1179 // A hotplug disconnect event is enqueued for a display
1180 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1181
1182 // The display is already completely set up.
1183 Case::Display::injectHwcDisplay(this);
1184 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1185 existing.inject();
1186
1187 // --------------------------------------------------------------------
1188 // Call Expectations
1189
1190 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1191
1192 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1193
1194 // --------------------------------------------------------------------
1195 // Invocation
1196
1197 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1198
1199 // --------------------------------------------------------------------
1200 // Postconditions
1201
1202 // HWComposer should not have an entry for the display
1203 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1204
1205 // The display should not be set up as a built-in display.
1206 ASSERT_TRUE(0 <= Case::Display::TYPE &&
1207 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES);
1208 auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE];
1209 EXPECT_TRUE(displayToken == nullptr);
1210
1211 // The existing token should have been removed
1212 verifyDisplayIsNotConnected(existing.token());
1213}
1214
1215TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1216 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1217}
1218
1219TEST_F(HandleTransactionLockedTest,
1220 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1221 // Inject an external display.
1222 ExternalDisplayVariant::injectHwcDisplay(this);
1223
1224 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1225}
1226
1227TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1228 // Inject a primary display.
1229 PrimaryDisplayVariant::injectHwcDisplay(this);
1230
1231 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1232}
1233
1234TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1235 // Inject both a primary and external display.
1236 PrimaryDisplayVariant::injectHwcDisplay(this);
1237 ExternalDisplayVariant::injectHwcDisplay(this);
1238
1239 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1240
1241 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1242}
1243
1244TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1245 // Inject a primary display.
1246 PrimaryDisplayVariant::injectHwcDisplay(this);
1247
1248 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1249
1250 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1251}
1252
1253TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1254 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1255}
1256
1257TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1258 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1259}
1260
1261TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1262 using Case = SimplePrimaryDisplayCase;
1263
1264 // --------------------------------------------------------------------
1265 // Preconditions
1266
1267 setupCommonPreconditions<Case>();
1268
1269 // A hotplug connect event is enqueued for a display
1270 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1271 // A hotplug disconnect event is also enqueued for the same display
1272 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1273
1274 // --------------------------------------------------------------------
1275 // Call Expectations
1276
1277 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1278
1279 setupCommonCallExpectationsForConnectProcessing<Case>();
1280 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1281
1282 EXPECT_CALL(*mComposer,
1283 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1284 .WillOnce(Return(Error::NONE));
1285 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1286
1287 // --------------------------------------------------------------------
1288 // Invocation
1289
1290 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1291
1292 // --------------------------------------------------------------------
1293 // Postconditions
1294
1295 // HWComposer should not have an entry for the display
1296 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1297
1298 // The display should not be set up as a primary built-in display.
1299 ASSERT_TRUE(0 <= Case::Display::TYPE &&
1300 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES);
1301 auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE];
1302 EXPECT_TRUE(displayToken == nullptr);
1303}
1304
1305TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1306 using Case = SimplePrimaryDisplayCase;
1307
1308 // --------------------------------------------------------------------
1309 // Preconditions
1310
1311 setupCommonPreconditions<Case>();
1312
1313 // The display is already completely set up.
1314 Case::Display::injectHwcDisplay(this);
1315 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1316 existing.inject();
1317
1318 // A hotplug disconnect event is enqueued for a display
1319 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1320 // A hotplug connect event is also enqueued for the same display
1321 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1322
1323 // --------------------------------------------------------------------
1324 // Call Expectations
1325
1326 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1327
1328 setupCommonCallExpectationsForConnectProcessing<Case>();
1329 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1330
1331 // --------------------------------------------------------------------
1332 // Invocation
1333
1334 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1335
1336 // --------------------------------------------------------------------
1337 // Postconditions
1338
1339 // The existing token should have been removed
1340 verifyDisplayIsNotConnected(existing.token());
1341 static_assert(0 <= Case::Display::TYPE &&
1342 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
1343 "Display type must be a built-in display");
1344 EXPECT_NE(existing.token(), mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]);
1345
1346 // A new display should be connected in its place
1347
1348 verifyPhysicalDisplayIsConnected<Case>();
1349
1350 // --------------------------------------------------------------------
1351 // Cleanup conditions
1352
1353 EXPECT_CALL(*mComposer,
1354 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1355 .WillOnce(Return(Error::NONE));
1356 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1357}
1358
1359TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1360 using Case = HwcVirtualDisplayCase;
1361
1362 // --------------------------------------------------------------------
1363 // Preconditions
1364
1365 // The HWC supports at least one virtual display
1366 injectMockComposer(1);
1367
1368 setupCommonPreconditions<Case>();
1369
1370 // A virtual display was added to the current state, and it has a
1371 // surface(producer)
1372 sp<BBinder> displayToken = new BBinder();
1373 DisplayDeviceState info(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE));
1374 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
1375 info.surface = surface;
1376 mFlinger.mutableCurrentState().displays.add(displayToken, info);
1377
1378 // --------------------------------------------------------------------
1379 // Call Expectations
1380
1381 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1382 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1383
1384 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1385 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1386 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1387 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1388 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1389 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1390 Return(NO_ERROR)));
1391 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1392 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1393
1394 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1395
1396 EXPECT_CALL(*mProducer, connect(_, _, _, _)).Times(1);
1397 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1398
1399 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1400 Case::WideColorSupport::setupComposerCallExpectations(this);
1401 Case::HdrSupport::setupComposerCallExpectations(this);
1402
1403 // --------------------------------------------------------------------
1404 // Invocation
1405
1406 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1407
1408 // --------------------------------------------------------------------
1409 // Postconditions
1410
1411 // The display device should have been set up in the list of displays.
1412 verifyDisplayIsConnected<Case>(displayToken);
1413
1414 // --------------------------------------------------------------------
1415 // Cleanup conditions
1416
1417 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1418 .WillOnce(Return(Error::NONE));
1419 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1420}
1421
1422TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1423 using Case = HwcVirtualDisplayCase;
1424
1425 // --------------------------------------------------------------------
1426 // Preconditions
1427
1428 // The HWC supports at least one virtual display
1429 injectMockComposer(1);
1430
1431 setupCommonPreconditions<Case>();
1432
1433 // A virtual display was added to the current state, but it does not have a
1434 // surface.
1435 sp<BBinder> displayToken = new BBinder();
1436 DisplayDeviceState info(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE));
1437 mFlinger.mutableCurrentState().displays.add(displayToken, info);
1438
1439 // --------------------------------------------------------------------
1440 // Call Expectations
1441
1442 // --------------------------------------------------------------------
1443 // Invocation
1444
1445 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1446
1447 // --------------------------------------------------------------------
1448 // Postconditions
1449
1450 // There will not be a display device set up.
1451 EXPECT_FALSE(hasDisplayDevice(displayToken));
1452
1453 // The drawing display state will be set from the current display state.
1454 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1455 const auto& draw = getDrawingDisplayState(displayToken);
1456 EXPECT_EQ(Case::Display::TYPE, draw.type);
1457}
1458
1459TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1460 using Case = HwcVirtualDisplayCase;
1461
1462 // --------------------------------------------------------------------
1463 // Preconditions
1464
1465 // A virtual display is set up but is removed from the current state.
1466 mFlinger.mutableHwcDisplayData().resize(3);
1467 Case::Display::injectHwcDisplay(this);
1468 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1469 existing.inject();
1470 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1471
1472 // --------------------------------------------------------------------
1473 // Call Expectations
1474
1475 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1476
1477 // --------------------------------------------------------------------
1478 // Invocation
1479
1480 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1481
1482 // --------------------------------------------------------------------
1483 // Postconditions
1484
1485 // The existing token should have been removed
1486 verifyDisplayIsNotConnected(existing.token());
1487}
1488
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001489TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
1490 using Case = NonHwcVirtualDisplayCase;
1491
1492 constexpr uint32_t oldLayerStack = 0u;
1493 constexpr uint32_t newLayerStack = 123u;
1494
1495 // --------------------------------------------------------------------
1496 // Preconditions
1497
1498 // A display is set up
1499 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1500 display.inject();
1501
1502 // There is a change to the layerStack state
1503 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
1504 display.mutableCurrentDisplayState().layerStack = newLayerStack;
1505
1506 // --------------------------------------------------------------------
1507 // Invocation
1508
1509 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1510
1511 // --------------------------------------------------------------------
1512 // Postconditions
1513
1514 EXPECT_EQ(newLayerStack, getDisplayDevice(display.token())->getLayerStack());
1515}
1516
1517TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
1518 using Case = NonHwcVirtualDisplayCase;
1519
1520 constexpr int oldTransform = 0;
1521 constexpr int newTransform = 2;
1522
1523 // --------------------------------------------------------------------
1524 // Preconditions
1525
1526 // A display is set up
1527 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1528 display.inject();
1529
1530 // There is a change to the orientation state
1531 display.mutableDrawingDisplayState().orientation = oldTransform;
1532 display.mutableCurrentDisplayState().orientation = newTransform;
1533
1534 // --------------------------------------------------------------------
1535 // Invocation
1536
1537 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1538
1539 // --------------------------------------------------------------------
1540 // Postconditions
1541
1542 EXPECT_EQ(newTransform, getDisplayDevice(display.token())->getOrientation());
1543}
1544
1545TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
1546 using Case = NonHwcVirtualDisplayCase;
1547
1548 const Rect oldViewport(0, 0, 0, 0);
1549 const Rect newViewport(0, 0, 123, 456);
1550
1551 // --------------------------------------------------------------------
1552 // Preconditions
1553
1554 // A display is set up
1555 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1556 display.inject();
1557
1558 // There is a change to the viewport state
1559 display.mutableDrawingDisplayState().viewport = oldViewport;
1560 display.mutableCurrentDisplayState().viewport = newViewport;
1561
1562 // --------------------------------------------------------------------
1563 // Invocation
1564
1565 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1566
1567 // --------------------------------------------------------------------
1568 // Postconditions
1569
1570 EXPECT_EQ(newViewport, getDisplayDevice(display.token())->getViewport());
1571}
1572
1573TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
1574 using Case = NonHwcVirtualDisplayCase;
1575
1576 const Rect oldFrame(0, 0, 0, 0);
1577 const Rect newFrame(0, 0, 123, 456);
1578
1579 // --------------------------------------------------------------------
1580 // Preconditions
1581
1582 // A display is set up
1583 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1584 display.inject();
1585
1586 // There is a change to the viewport state
1587 display.mutableDrawingDisplayState().frame = oldFrame;
1588 display.mutableCurrentDisplayState().frame = newFrame;
1589
1590 // --------------------------------------------------------------------
1591 // Invocation
1592
1593 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1594
1595 // --------------------------------------------------------------------
1596 // Postconditions
1597
1598 EXPECT_EQ(newFrame, getDisplayDevice(display.token())->getFrame());
1599}
1600
1601TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
1602 using Case = NonHwcVirtualDisplayCase;
1603
1604 constexpr int oldWidth = 0;
1605 constexpr int oldHeight = 10;
1606 constexpr int newWidth = 123;
1607
1608 // --------------------------------------------------------------------
1609 // Preconditions
1610
1611 // A display is set up
1612 auto nativeWindow = new mock::NativeWindow();
1613 auto displaySurface = new mock::DisplaySurface();
1614 auto renderSurface = new RE::mock::Surface();
1615 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1616 display.setNativeWindow(nativeWindow);
1617 display.setDisplaySurface(displaySurface);
1618 display.setRenderSurface(std::unique_ptr<RE::Surface>(renderSurface));
1619 display.inject();
1620
1621 // There is a change to the viewport state
1622 display.mutableDrawingDisplayState().width = oldWidth;
1623 display.mutableDrawingDisplayState().height = oldHeight;
1624 display.mutableCurrentDisplayState().width = newWidth;
1625 display.mutableCurrentDisplayState().height = oldHeight;
1626
1627 // --------------------------------------------------------------------
1628 // Call Expectations
1629
1630 EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
1631 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
1632 EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
1633 EXPECT_CALL(*renderSurface, queryWidth()).WillOnce(Return(newWidth));
1634 EXPECT_CALL(*renderSurface, queryHeight()).WillOnce(Return(oldHeight));
1635
1636 // --------------------------------------------------------------------
1637 // Invocation
1638
1639 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1640}
1641
1642TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
1643 using Case = NonHwcVirtualDisplayCase;
1644
1645 constexpr int oldWidth = 0;
1646 constexpr int oldHeight = 10;
1647 constexpr int newHeight = 123;
1648
1649 // --------------------------------------------------------------------
1650 // Preconditions
1651
1652 // A display is set up
1653 auto nativeWindow = new mock::NativeWindow();
1654 auto displaySurface = new mock::DisplaySurface();
1655 auto renderSurface = new RE::mock::Surface();
1656 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1657 display.setNativeWindow(nativeWindow);
1658 display.setDisplaySurface(displaySurface);
1659 display.setRenderSurface(std::unique_ptr<RE::Surface>(renderSurface));
1660 display.inject();
1661
1662 // There is a change to the viewport state
1663 display.mutableDrawingDisplayState().width = oldWidth;
1664 display.mutableDrawingDisplayState().height = oldHeight;
1665 display.mutableCurrentDisplayState().width = oldWidth;
1666 display.mutableCurrentDisplayState().height = newHeight;
1667
1668 // --------------------------------------------------------------------
1669 // Call Expectations
1670
1671 EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
1672 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
1673 EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
1674 EXPECT_CALL(*renderSurface, queryWidth()).WillOnce(Return(oldWidth));
1675 EXPECT_CALL(*renderSurface, queryHeight()).WillOnce(Return(newHeight));
1676
1677 // --------------------------------------------------------------------
1678 // Invocation
1679
1680 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1681}
1682
Lloyd Piquef58625d2017-12-19 13:22:33 -08001683} // namespace
1684} // namespace android