blob: 2b8a22c122a6e6ae96a839a589f565f00a7c95cd [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 Piqued6fbb8a2018-01-22 19:08:36 -0800904 * SurfaceFlinger::resetDisplayState
905 */
906
907TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
908 using Case = NonHwcVirtualDisplayCase;
909
910 // --------------------------------------------------------------------
911 // Preconditions
912
913 // vsync is enabled and available
914 mFlinger.mutablePrimaryHWVsyncEnabled() = true;
915 mFlinger.mutableHWVsyncAvailable() = true;
916
917 // A display exists
918 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
919 existing.inject();
920
921 // --------------------------------------------------------------------
922 // Call Expectations
923
924 // The call disable vsyncs
925 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
926
927 // The call clears the current render engine surface
928 EXPECT_CALL(*mRenderEngine, resetCurrentSurface());
929
930 // --------------------------------------------------------------------
931 // Invocation
932
933 mFlinger.resetDisplayState();
934
935 // --------------------------------------------------------------------
936 // Postconditions
937
938 // vsyncs should be off and not available.
939 EXPECT_FALSE(mFlinger.mutablePrimaryHWVsyncEnabled());
940 EXPECT_FALSE(mFlinger.mutableHWVsyncAvailable());
941
942 // The display should have been removed from the display map.
943 EXPECT_FALSE(hasDisplayDevice(existing.token()));
944
945 // The display should still exist in the current state
946 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
947
948 // The display should have been removed from the drawing state
949 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
950}
951
952/* ------------------------------------------------------------------------
Lloyd Piquefc12f562018-01-22 18:44:59 -0800953 * SurfaceFlinger::setupNewDisplayDeviceInternal
954 */
955
956class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
957public:
958 template <typename T>
959 void setupNewDisplayDeviceInternalTest();
960};
961
962template <typename Case>
963void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
964 const sp<BBinder> displayToken = new BBinder();
965 const sp<mock::DisplaySurface> displaySurface = new mock::DisplaySurface();
966 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800967
968 // --------------------------------------------------------------------
969 // Preconditions
970
Lloyd Piquefc12f562018-01-22 18:44:59 -0800971 // Wide color displays support is configured appropriately
972 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800973
Lloyd Piquefc12f562018-01-22 18:44:59 -0800974 // The display is setup with the HWC.
975 Case::Display::injectHwcDisplay(this);
976
977 // SurfaceFlinger will use a test-controlled factory for native window
978 // surfaces.
979 injectFakeNativeWindowSurfaceFactory();
980
981 // --------------------------------------------------------------------
982 // Call Expectations
983
984 // Various native window calls will be made.
985 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
986
987 // TODO(b/69807179): SurfaceFlinger does not correctly get the active config.
988 // Case::Display::setupHwcGetActiveConfigCallExpectations(this)
989
990 Case::WideColorSupport::setupComposerCallExpectations(this);
991 Case::HdrSupport::setupComposerCallExpectations(this);
992
993 // --------------------------------------------------------------------
994 // Invocation
995
996 auto state = DisplayDeviceState(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE));
997 auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::TYPE, state,
998 displaySurface, producer);
999
1000 // --------------------------------------------------------------------
1001 // Postconditions
1002
1003 ASSERT_TRUE(device != nullptr);
1004 EXPECT_EQ(Case::Display::TYPE, device->getDisplayType());
1005 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
1006 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1007 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1008 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
1009 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1010 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1011 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
1012 EXPECT_EQ(Case::Display::HWC_ACTIVE_CONFIG_ID, device->getActiveConfig());
1013}
1014
1015TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1016 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1017}
1018
1019TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1020 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1021}
1022
1023TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1024 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1025}
1026
1027TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
1028 // We need to resize this so that the HWC thinks the virtual display
1029 // is something it created.
1030 mFlinger.mutableHwcDisplayData().resize(3);
1031
1032 setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>();
1033}
1034
1035TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1036 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1037}
1038
1039TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3EnhanceDisplay) {
1040 setupNewDisplayDeviceInternalTest<WideColorP3EnhanceDisplayCase>();
1041}
1042
1043TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1044 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1045}
1046
1047TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1048 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1049}
1050
1051TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1052 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1053}
1054
1055/* ------------------------------------------------------------------------
1056 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1057 */
1058
1059class HandleTransactionLockedTest : public DisplayTransactionTest {
1060public:
1061 template <typename Case>
1062 void setupCommonPreconditions();
1063
1064 template <typename Case>
1065 void setupCommonCallExpectationsForConnectProcessing();
1066
1067 template <typename Case>
1068 void setupCommonCallExpectationsForDisconnectProcessing();
1069
1070 template <typename Case>
1071 void processesHotplugConnectCommon();
1072
1073 template <typename Case>
1074 void ignoresHotplugConnectCommon();
1075
1076 template <typename Case>
1077 void processesHotplugDisconnectCommon();
1078
1079 template <typename Case>
1080 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1081
1082 template <typename Case>
1083 void verifyPhysicalDisplayIsConnected();
1084
1085 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1086};
1087
1088template <typename Case>
1089void HandleTransactionLockedTest::setupCommonPreconditions() {
1090 // Wide color displays support is configured appropriately
1091 Case::WideColorSupport::injectConfigChange(this);
1092
1093 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1094 injectFakeBufferQueueFactory();
1095
1096 // SurfaceFlinger will use a test-controlled factory for native window
1097 // surfaces.
1098 injectFakeNativeWindowSurfaceFactory();
1099}
1100
1101template <typename Case>
1102void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1103 Case::Display::setupHwcHotplugCallExpectations(this);
1104
1105 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1106 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1107 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1108 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1109
1110 Case::WideColorSupport::setupComposerCallExpectations(this);
1111 Case::HdrSupport::setupComposerCallExpectations(this);
1112
1113 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1114 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, true)).Times(1);
1115}
1116
1117template <typename Case>
1118void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1119 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1120 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, false)).Times(1);
1121}
1122
1123template <typename Case>
1124void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1125 // The display device should have been set up in the list of displays.
1126 ASSERT_TRUE(hasDisplayDevice(displayToken));
1127 const auto& device = getDisplayDevice(displayToken);
1128 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
1129 EXPECT_EQ(Case::Display::TYPE == DisplayDevice::DISPLAY_PRIMARY, device->isPrimary());
1130
1131 // The display should have been set up in the current display state
1132 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1133 const auto& current = getCurrentDisplayState(displayToken);
1134 EXPECT_EQ(Case::Display::TYPE, current.type);
1135
1136 // The display should have been set up in the drawing display state
1137 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1138 const auto& draw = getDrawingDisplayState(displayToken);
1139 EXPECT_EQ(Case::Display::TYPE, draw.type);
1140}
1141
1142template <typename Case>
1143void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1144 // HWComposer should have an entry for the display
1145 EXPECT_TRUE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1146
1147 // The display should be set up as a built-in display.
1148 static_assert(0 <= Case::Display::TYPE &&
1149 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
1150 "Must use a valid physical display type index for the fixed-size array");
1151 auto& displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE];
1152 ASSERT_TRUE(displayToken != nullptr);
1153
1154 verifyDisplayIsConnected<Case>(displayToken);
1155}
1156
1157void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1158 EXPECT_FALSE(hasDisplayDevice(displayToken));
1159 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1160 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1161}
1162
1163template <typename Case>
1164void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1165 // --------------------------------------------------------------------
1166 // Preconditions
1167
1168 setupCommonPreconditions<Case>();
1169
1170 // A hotplug connect event is enqueued for a display
1171 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001172
1173 // --------------------------------------------------------------------
1174 // Call Expectations
1175
1176 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001177
Lloyd Piquefc12f562018-01-22 18:44:59 -08001178 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001179
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001180 // --------------------------------------------------------------------
1181 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001182
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001183 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001184
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001185 // --------------------------------------------------------------------
1186 // Postconditions
1187
Lloyd Piquefc12f562018-01-22 18:44:59 -08001188 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001189
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001190 // --------------------------------------------------------------------
1191 // Cleanup conditions
1192
Lloyd Piquefc12f562018-01-22 18:44:59 -08001193 EXPECT_CALL(*mComposer,
1194 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001195 .WillOnce(Return(Error::NONE));
1196 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001197}
1198
Lloyd Piquefc12f562018-01-22 18:44:59 -08001199template <typename Case>
1200void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1201 // --------------------------------------------------------------------
1202 // Preconditions
1203
1204 setupCommonPreconditions<Case>();
1205
1206 // A hotplug connect event is enqueued for a display
1207 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1208
1209 // --------------------------------------------------------------------
1210 // Invocation
1211
1212 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1213
1214 // --------------------------------------------------------------------
1215 // Postconditions
1216
1217 // HWComposer should not have an entry for the display
1218 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1219}
1220
1221template <typename Case>
1222void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1223 // --------------------------------------------------------------------
1224 // Preconditions
1225
1226 setupCommonPreconditions<Case>();
1227
1228 // A hotplug disconnect event is enqueued for a display
1229 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1230
1231 // The display is already completely set up.
1232 Case::Display::injectHwcDisplay(this);
1233 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1234 existing.inject();
1235
1236 // --------------------------------------------------------------------
1237 // Call Expectations
1238
1239 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1240
1241 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1242
1243 // --------------------------------------------------------------------
1244 // Invocation
1245
1246 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1247
1248 // --------------------------------------------------------------------
1249 // Postconditions
1250
1251 // HWComposer should not have an entry for the display
1252 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1253
1254 // The display should not be set up as a built-in display.
1255 ASSERT_TRUE(0 <= Case::Display::TYPE &&
1256 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES);
1257 auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE];
1258 EXPECT_TRUE(displayToken == nullptr);
1259
1260 // The existing token should have been removed
1261 verifyDisplayIsNotConnected(existing.token());
1262}
1263
1264TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1265 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1266}
1267
1268TEST_F(HandleTransactionLockedTest,
1269 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1270 // Inject an external display.
1271 ExternalDisplayVariant::injectHwcDisplay(this);
1272
1273 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1274}
1275
1276TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1277 // Inject a primary display.
1278 PrimaryDisplayVariant::injectHwcDisplay(this);
1279
1280 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1281}
1282
1283TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1284 // Inject both a primary and external display.
1285 PrimaryDisplayVariant::injectHwcDisplay(this);
1286 ExternalDisplayVariant::injectHwcDisplay(this);
1287
1288 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1289
1290 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1291}
1292
1293TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1294 // Inject a primary display.
1295 PrimaryDisplayVariant::injectHwcDisplay(this);
1296
1297 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1298
1299 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1300}
1301
1302TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1303 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1304}
1305
1306TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1307 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1308}
1309
1310TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1311 using Case = SimplePrimaryDisplayCase;
1312
1313 // --------------------------------------------------------------------
1314 // Preconditions
1315
1316 setupCommonPreconditions<Case>();
1317
1318 // A hotplug connect event is enqueued for a display
1319 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1320 // A hotplug disconnect event is also enqueued for the same display
1321 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1322
1323 // --------------------------------------------------------------------
1324 // Call Expectations
1325
1326 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1327
1328 setupCommonCallExpectationsForConnectProcessing<Case>();
1329 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1330
1331 EXPECT_CALL(*mComposer,
1332 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1333 .WillOnce(Return(Error::NONE));
1334 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1335
1336 // --------------------------------------------------------------------
1337 // Invocation
1338
1339 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1340
1341 // --------------------------------------------------------------------
1342 // Postconditions
1343
1344 // HWComposer should not have an entry for the display
1345 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1346
1347 // The display should not be set up as a primary built-in display.
1348 ASSERT_TRUE(0 <= Case::Display::TYPE &&
1349 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES);
1350 auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE];
1351 EXPECT_TRUE(displayToken == nullptr);
1352}
1353
1354TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1355 using Case = SimplePrimaryDisplayCase;
1356
1357 // --------------------------------------------------------------------
1358 // Preconditions
1359
1360 setupCommonPreconditions<Case>();
1361
1362 // The display is already completely set up.
1363 Case::Display::injectHwcDisplay(this);
1364 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1365 existing.inject();
1366
1367 // A hotplug disconnect event is enqueued for a display
1368 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1369 // A hotplug connect event is also enqueued for the same display
1370 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1371
1372 // --------------------------------------------------------------------
1373 // Call Expectations
1374
1375 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1376
1377 setupCommonCallExpectationsForConnectProcessing<Case>();
1378 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1379
1380 // --------------------------------------------------------------------
1381 // Invocation
1382
1383 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1384
1385 // --------------------------------------------------------------------
1386 // Postconditions
1387
1388 // The existing token should have been removed
1389 verifyDisplayIsNotConnected(existing.token());
1390 static_assert(0 <= Case::Display::TYPE &&
1391 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
1392 "Display type must be a built-in display");
1393 EXPECT_NE(existing.token(), mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]);
1394
1395 // A new display should be connected in its place
1396
1397 verifyPhysicalDisplayIsConnected<Case>();
1398
1399 // --------------------------------------------------------------------
1400 // Cleanup conditions
1401
1402 EXPECT_CALL(*mComposer,
1403 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1404 .WillOnce(Return(Error::NONE));
1405 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1406}
1407
1408TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1409 using Case = HwcVirtualDisplayCase;
1410
1411 // --------------------------------------------------------------------
1412 // Preconditions
1413
1414 // The HWC supports at least one virtual display
1415 injectMockComposer(1);
1416
1417 setupCommonPreconditions<Case>();
1418
1419 // A virtual display was added to the current state, and it has a
1420 // surface(producer)
1421 sp<BBinder> displayToken = new BBinder();
1422 DisplayDeviceState info(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE));
1423 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
1424 info.surface = surface;
1425 mFlinger.mutableCurrentState().displays.add(displayToken, info);
1426
1427 // --------------------------------------------------------------------
1428 // Call Expectations
1429
1430 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1431 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1432
1433 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1434 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1435 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1436 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1437 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1438 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1439 Return(NO_ERROR)));
1440 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1441 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1442
1443 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1444
1445 EXPECT_CALL(*mProducer, connect(_, _, _, _)).Times(1);
1446 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1447
1448 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1449 Case::WideColorSupport::setupComposerCallExpectations(this);
1450 Case::HdrSupport::setupComposerCallExpectations(this);
1451
1452 // --------------------------------------------------------------------
1453 // Invocation
1454
1455 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1456
1457 // --------------------------------------------------------------------
1458 // Postconditions
1459
1460 // The display device should have been set up in the list of displays.
1461 verifyDisplayIsConnected<Case>(displayToken);
1462
1463 // --------------------------------------------------------------------
1464 // Cleanup conditions
1465
1466 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1467 .WillOnce(Return(Error::NONE));
1468 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1469}
1470
1471TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1472 using Case = HwcVirtualDisplayCase;
1473
1474 // --------------------------------------------------------------------
1475 // Preconditions
1476
1477 // The HWC supports at least one virtual display
1478 injectMockComposer(1);
1479
1480 setupCommonPreconditions<Case>();
1481
1482 // A virtual display was added to the current state, but it does not have a
1483 // surface.
1484 sp<BBinder> displayToken = new BBinder();
1485 DisplayDeviceState info(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE));
1486 mFlinger.mutableCurrentState().displays.add(displayToken, info);
1487
1488 // --------------------------------------------------------------------
1489 // Call Expectations
1490
1491 // --------------------------------------------------------------------
1492 // Invocation
1493
1494 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1495
1496 // --------------------------------------------------------------------
1497 // Postconditions
1498
1499 // There will not be a display device set up.
1500 EXPECT_FALSE(hasDisplayDevice(displayToken));
1501
1502 // The drawing display state will be set from the current display state.
1503 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1504 const auto& draw = getDrawingDisplayState(displayToken);
1505 EXPECT_EQ(Case::Display::TYPE, draw.type);
1506}
1507
1508TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1509 using Case = HwcVirtualDisplayCase;
1510
1511 // --------------------------------------------------------------------
1512 // Preconditions
1513
1514 // A virtual display is set up but is removed from the current state.
1515 mFlinger.mutableHwcDisplayData().resize(3);
1516 Case::Display::injectHwcDisplay(this);
1517 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1518 existing.inject();
1519 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1520
1521 // --------------------------------------------------------------------
1522 // Call Expectations
1523
1524 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1525
1526 // --------------------------------------------------------------------
1527 // Invocation
1528
1529 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1530
1531 // --------------------------------------------------------------------
1532 // Postconditions
1533
1534 // The existing token should have been removed
1535 verifyDisplayIsNotConnected(existing.token());
1536}
1537
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001538TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
1539 using Case = NonHwcVirtualDisplayCase;
1540
1541 constexpr uint32_t oldLayerStack = 0u;
1542 constexpr uint32_t newLayerStack = 123u;
1543
1544 // --------------------------------------------------------------------
1545 // Preconditions
1546
1547 // A display is set up
1548 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1549 display.inject();
1550
1551 // There is a change to the layerStack state
1552 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
1553 display.mutableCurrentDisplayState().layerStack = newLayerStack;
1554
1555 // --------------------------------------------------------------------
1556 // Invocation
1557
1558 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1559
1560 // --------------------------------------------------------------------
1561 // Postconditions
1562
1563 EXPECT_EQ(newLayerStack, getDisplayDevice(display.token())->getLayerStack());
1564}
1565
1566TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
1567 using Case = NonHwcVirtualDisplayCase;
1568
1569 constexpr int oldTransform = 0;
1570 constexpr int newTransform = 2;
1571
1572 // --------------------------------------------------------------------
1573 // Preconditions
1574
1575 // A display is set up
1576 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1577 display.inject();
1578
1579 // There is a change to the orientation state
1580 display.mutableDrawingDisplayState().orientation = oldTransform;
1581 display.mutableCurrentDisplayState().orientation = newTransform;
1582
1583 // --------------------------------------------------------------------
1584 // Invocation
1585
1586 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1587
1588 // --------------------------------------------------------------------
1589 // Postconditions
1590
1591 EXPECT_EQ(newTransform, getDisplayDevice(display.token())->getOrientation());
1592}
1593
1594TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
1595 using Case = NonHwcVirtualDisplayCase;
1596
1597 const Rect oldViewport(0, 0, 0, 0);
1598 const Rect newViewport(0, 0, 123, 456);
1599
1600 // --------------------------------------------------------------------
1601 // Preconditions
1602
1603 // A display is set up
1604 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1605 display.inject();
1606
1607 // There is a change to the viewport state
1608 display.mutableDrawingDisplayState().viewport = oldViewport;
1609 display.mutableCurrentDisplayState().viewport = newViewport;
1610
1611 // --------------------------------------------------------------------
1612 // Invocation
1613
1614 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1615
1616 // --------------------------------------------------------------------
1617 // Postconditions
1618
1619 EXPECT_EQ(newViewport, getDisplayDevice(display.token())->getViewport());
1620}
1621
1622TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
1623 using Case = NonHwcVirtualDisplayCase;
1624
1625 const Rect oldFrame(0, 0, 0, 0);
1626 const Rect newFrame(0, 0, 123, 456);
1627
1628 // --------------------------------------------------------------------
1629 // Preconditions
1630
1631 // A display is set up
1632 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1633 display.inject();
1634
1635 // There is a change to the viewport state
1636 display.mutableDrawingDisplayState().frame = oldFrame;
1637 display.mutableCurrentDisplayState().frame = newFrame;
1638
1639 // --------------------------------------------------------------------
1640 // Invocation
1641
1642 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1643
1644 // --------------------------------------------------------------------
1645 // Postconditions
1646
1647 EXPECT_EQ(newFrame, getDisplayDevice(display.token())->getFrame());
1648}
1649
1650TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
1651 using Case = NonHwcVirtualDisplayCase;
1652
1653 constexpr int oldWidth = 0;
1654 constexpr int oldHeight = 10;
1655 constexpr int newWidth = 123;
1656
1657 // --------------------------------------------------------------------
1658 // Preconditions
1659
1660 // A display is set up
1661 auto nativeWindow = new mock::NativeWindow();
1662 auto displaySurface = new mock::DisplaySurface();
1663 auto renderSurface = new RE::mock::Surface();
1664 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1665 display.setNativeWindow(nativeWindow);
1666 display.setDisplaySurface(displaySurface);
1667 display.setRenderSurface(std::unique_ptr<RE::Surface>(renderSurface));
1668 display.inject();
1669
1670 // There is a change to the viewport state
1671 display.mutableDrawingDisplayState().width = oldWidth;
1672 display.mutableDrawingDisplayState().height = oldHeight;
1673 display.mutableCurrentDisplayState().width = newWidth;
1674 display.mutableCurrentDisplayState().height = oldHeight;
1675
1676 // --------------------------------------------------------------------
1677 // Call Expectations
1678
1679 EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
1680 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
1681 EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
1682 EXPECT_CALL(*renderSurface, queryWidth()).WillOnce(Return(newWidth));
1683 EXPECT_CALL(*renderSurface, queryHeight()).WillOnce(Return(oldHeight));
1684
1685 // --------------------------------------------------------------------
1686 // Invocation
1687
1688 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1689}
1690
1691TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
1692 using Case = NonHwcVirtualDisplayCase;
1693
1694 constexpr int oldWidth = 0;
1695 constexpr int oldHeight = 10;
1696 constexpr int newHeight = 123;
1697
1698 // --------------------------------------------------------------------
1699 // Preconditions
1700
1701 // A display is set up
1702 auto nativeWindow = new mock::NativeWindow();
1703 auto displaySurface = new mock::DisplaySurface();
1704 auto renderSurface = new RE::mock::Surface();
1705 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1706 display.setNativeWindow(nativeWindow);
1707 display.setDisplaySurface(displaySurface);
1708 display.setRenderSurface(std::unique_ptr<RE::Surface>(renderSurface));
1709 display.inject();
1710
1711 // There is a change to the viewport state
1712 display.mutableDrawingDisplayState().width = oldWidth;
1713 display.mutableDrawingDisplayState().height = oldHeight;
1714 display.mutableCurrentDisplayState().width = oldWidth;
1715 display.mutableCurrentDisplayState().height = newHeight;
1716
1717 // --------------------------------------------------------------------
1718 // Call Expectations
1719
1720 EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
1721 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
1722 EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
1723 EXPECT_CALL(*renderSurface, queryWidth()).WillOnce(Return(oldWidth));
1724 EXPECT_CALL(*renderSurface, queryHeight()).WillOnce(Return(newHeight));
1725
1726 // --------------------------------------------------------------------
1727 // Invocation
1728
1729 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1730}
1731
Lloyd Piquef58625d2017-12-19 13:22:33 -08001732} // namespace
1733} // namespace android