blob: d3a9128ea97def071f1eba4d9ad8748f4c531d6a [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 Piquefc12f562018-01-22 18:44:59 -0800785 * SurfaceFlinger::setupNewDisplayDeviceInternal
786 */
787
788class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
789public:
790 template <typename T>
791 void setupNewDisplayDeviceInternalTest();
792};
793
794template <typename Case>
795void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
796 const sp<BBinder> displayToken = new BBinder();
797 const sp<mock::DisplaySurface> displaySurface = new mock::DisplaySurface();
798 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800799
800 // --------------------------------------------------------------------
801 // Preconditions
802
Lloyd Piquefc12f562018-01-22 18:44:59 -0800803 // Wide color displays support is configured appropriately
804 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800805
Lloyd Piquefc12f562018-01-22 18:44:59 -0800806 // The display is setup with the HWC.
807 Case::Display::injectHwcDisplay(this);
808
809 // SurfaceFlinger will use a test-controlled factory for native window
810 // surfaces.
811 injectFakeNativeWindowSurfaceFactory();
812
813 // --------------------------------------------------------------------
814 // Call Expectations
815
816 // Various native window calls will be made.
817 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
818
819 // TODO(b/69807179): SurfaceFlinger does not correctly get the active config.
820 // Case::Display::setupHwcGetActiveConfigCallExpectations(this)
821
822 Case::WideColorSupport::setupComposerCallExpectations(this);
823 Case::HdrSupport::setupComposerCallExpectations(this);
824
825 // --------------------------------------------------------------------
826 // Invocation
827
828 auto state = DisplayDeviceState(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE));
829 auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::TYPE, state,
830 displaySurface, producer);
831
832 // --------------------------------------------------------------------
833 // Postconditions
834
835 ASSERT_TRUE(device != nullptr);
836 EXPECT_EQ(Case::Display::TYPE, device->getDisplayType());
837 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
838 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
839 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
840 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
841 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
842 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
843 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
844 EXPECT_EQ(Case::Display::HWC_ACTIVE_CONFIG_ID, device->getActiveConfig());
845}
846
847TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
848 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
849}
850
851TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
852 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
853}
854
855TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
856 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
857}
858
859TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
860 // We need to resize this so that the HWC thinks the virtual display
861 // is something it created.
862 mFlinger.mutableHwcDisplayData().resize(3);
863
864 setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>();
865}
866
867TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
868 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
869}
870
871TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3EnhanceDisplay) {
872 setupNewDisplayDeviceInternalTest<WideColorP3EnhanceDisplayCase>();
873}
874
875TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
876 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
877}
878
879TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
880 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
881}
882
883TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
884 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
885}
886
887/* ------------------------------------------------------------------------
888 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
889 */
890
891class HandleTransactionLockedTest : public DisplayTransactionTest {
892public:
893 template <typename Case>
894 void setupCommonPreconditions();
895
896 template <typename Case>
897 void setupCommonCallExpectationsForConnectProcessing();
898
899 template <typename Case>
900 void setupCommonCallExpectationsForDisconnectProcessing();
901
902 template <typename Case>
903 void processesHotplugConnectCommon();
904
905 template <typename Case>
906 void ignoresHotplugConnectCommon();
907
908 template <typename Case>
909 void processesHotplugDisconnectCommon();
910
911 template <typename Case>
912 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
913
914 template <typename Case>
915 void verifyPhysicalDisplayIsConnected();
916
917 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
918};
919
920template <typename Case>
921void HandleTransactionLockedTest::setupCommonPreconditions() {
922 // Wide color displays support is configured appropriately
923 Case::WideColorSupport::injectConfigChange(this);
924
925 // SurfaceFlinger will use a test-controlled factory for BufferQueues
926 injectFakeBufferQueueFactory();
927
928 // SurfaceFlinger will use a test-controlled factory for native window
929 // surfaces.
930 injectFakeNativeWindowSurfaceFactory();
931}
932
933template <typename Case>
934void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
935 Case::Display::setupHwcHotplugCallExpectations(this);
936
937 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
938 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
939 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
940 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
941
942 Case::WideColorSupport::setupComposerCallExpectations(this);
943 Case::HdrSupport::setupComposerCallExpectations(this);
944
945 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
946 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, true)).Times(1);
947}
948
949template <typename Case>
950void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
951 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
952 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::TYPE, false)).Times(1);
953}
954
955template <typename Case>
956void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
957 // The display device should have been set up in the list of displays.
958 ASSERT_TRUE(hasDisplayDevice(displayToken));
959 const auto& device = getDisplayDevice(displayToken);
960 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
961 EXPECT_EQ(Case::Display::TYPE == DisplayDevice::DISPLAY_PRIMARY, device->isPrimary());
962
963 // The display should have been set up in the current display state
964 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
965 const auto& current = getCurrentDisplayState(displayToken);
966 EXPECT_EQ(Case::Display::TYPE, current.type);
967
968 // The display should have been set up in the drawing display state
969 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
970 const auto& draw = getDrawingDisplayState(displayToken);
971 EXPECT_EQ(Case::Display::TYPE, draw.type);
972}
973
974template <typename Case>
975void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
976 // HWComposer should have an entry for the display
977 EXPECT_TRUE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
978
979 // The display should be set up as a built-in display.
980 static_assert(0 <= Case::Display::TYPE &&
981 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
982 "Must use a valid physical display type index for the fixed-size array");
983 auto& displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE];
984 ASSERT_TRUE(displayToken != nullptr);
985
986 verifyDisplayIsConnected<Case>(displayToken);
987}
988
989void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
990 EXPECT_FALSE(hasDisplayDevice(displayToken));
991 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
992 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
993}
994
995template <typename Case>
996void HandleTransactionLockedTest::processesHotplugConnectCommon() {
997 // --------------------------------------------------------------------
998 // Preconditions
999
1000 setupCommonPreconditions<Case>();
1001
1002 // A hotplug connect event is enqueued for a display
1003 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001004
1005 // --------------------------------------------------------------------
1006 // Call Expectations
1007
1008 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001009
Lloyd Piquefc12f562018-01-22 18:44:59 -08001010 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001011
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001012 // --------------------------------------------------------------------
1013 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001014
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001015 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001016
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001017 // --------------------------------------------------------------------
1018 // Postconditions
1019
Lloyd Piquefc12f562018-01-22 18:44:59 -08001020 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001021
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001022 // --------------------------------------------------------------------
1023 // Cleanup conditions
1024
Lloyd Piquefc12f562018-01-22 18:44:59 -08001025 EXPECT_CALL(*mComposer,
1026 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001027 .WillOnce(Return(Error::NONE));
1028 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001029}
1030
Lloyd Piquefc12f562018-01-22 18:44:59 -08001031template <typename Case>
1032void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1033 // --------------------------------------------------------------------
1034 // Preconditions
1035
1036 setupCommonPreconditions<Case>();
1037
1038 // A hotplug connect event is enqueued for a display
1039 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1040
1041 // --------------------------------------------------------------------
1042 // Invocation
1043
1044 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1045
1046 // --------------------------------------------------------------------
1047 // Postconditions
1048
1049 // HWComposer should not have an entry for the display
1050 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1051}
1052
1053template <typename Case>
1054void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1055 // --------------------------------------------------------------------
1056 // Preconditions
1057
1058 setupCommonPreconditions<Case>();
1059
1060 // A hotplug disconnect event is enqueued for a display
1061 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1062
1063 // The display is already completely set up.
1064 Case::Display::injectHwcDisplay(this);
1065 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1066 existing.inject();
1067
1068 // --------------------------------------------------------------------
1069 // Call Expectations
1070
1071 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1072
1073 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1074
1075 // --------------------------------------------------------------------
1076 // Invocation
1077
1078 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1079
1080 // --------------------------------------------------------------------
1081 // Postconditions
1082
1083 // HWComposer should not have an entry for the display
1084 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1085
1086 // The display should not be set up as a built-in display.
1087 ASSERT_TRUE(0 <= Case::Display::TYPE &&
1088 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES);
1089 auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE];
1090 EXPECT_TRUE(displayToken == nullptr);
1091
1092 // The existing token should have been removed
1093 verifyDisplayIsNotConnected(existing.token());
1094}
1095
1096TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1097 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1098}
1099
1100TEST_F(HandleTransactionLockedTest,
1101 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1102 // Inject an external display.
1103 ExternalDisplayVariant::injectHwcDisplay(this);
1104
1105 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1106}
1107
1108TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1109 // Inject a primary display.
1110 PrimaryDisplayVariant::injectHwcDisplay(this);
1111
1112 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1113}
1114
1115TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1116 // Inject both a primary and external display.
1117 PrimaryDisplayVariant::injectHwcDisplay(this);
1118 ExternalDisplayVariant::injectHwcDisplay(this);
1119
1120 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1121
1122 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1123}
1124
1125TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1126 // Inject a primary display.
1127 PrimaryDisplayVariant::injectHwcDisplay(this);
1128
1129 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1130
1131 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1132}
1133
1134TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1135 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1136}
1137
1138TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1139 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1140}
1141
1142TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1143 using Case = SimplePrimaryDisplayCase;
1144
1145 // --------------------------------------------------------------------
1146 // Preconditions
1147
1148 setupCommonPreconditions<Case>();
1149
1150 // A hotplug connect event is enqueued for a display
1151 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1152 // A hotplug disconnect event is also enqueued for the same display
1153 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1154
1155 // --------------------------------------------------------------------
1156 // Call Expectations
1157
1158 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1159
1160 setupCommonCallExpectationsForConnectProcessing<Case>();
1161 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1162
1163 EXPECT_CALL(*mComposer,
1164 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1165 .WillOnce(Return(Error::NONE));
1166 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1167
1168 // --------------------------------------------------------------------
1169 // Invocation
1170
1171 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1172
1173 // --------------------------------------------------------------------
1174 // Postconditions
1175
1176 // HWComposer should not have an entry for the display
1177 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1178
1179 // The display should not be set up as a primary built-in display.
1180 ASSERT_TRUE(0 <= Case::Display::TYPE &&
1181 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES);
1182 auto displayToken = mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE];
1183 EXPECT_TRUE(displayToken == nullptr);
1184}
1185
1186TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1187 using Case = SimplePrimaryDisplayCase;
1188
1189 // --------------------------------------------------------------------
1190 // Preconditions
1191
1192 setupCommonPreconditions<Case>();
1193
1194 // The display is already completely set up.
1195 Case::Display::injectHwcDisplay(this);
1196 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1197 existing.inject();
1198
1199 // A hotplug disconnect event is enqueued for a display
1200 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1201 // A hotplug connect event is also enqueued for the same display
1202 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1203
1204 // --------------------------------------------------------------------
1205 // Call Expectations
1206
1207 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1208
1209 setupCommonCallExpectationsForConnectProcessing<Case>();
1210 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1211
1212 // --------------------------------------------------------------------
1213 // Invocation
1214
1215 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1216
1217 // --------------------------------------------------------------------
1218 // Postconditions
1219
1220 // The existing token should have been removed
1221 verifyDisplayIsNotConnected(existing.token());
1222 static_assert(0 <= Case::Display::TYPE &&
1223 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
1224 "Display type must be a built-in display");
1225 EXPECT_NE(existing.token(), mFlinger.mutableBuiltinDisplays()[Case::Display::TYPE]);
1226
1227 // A new display should be connected in its place
1228
1229 verifyPhysicalDisplayIsConnected<Case>();
1230
1231 // --------------------------------------------------------------------
1232 // Cleanup conditions
1233
1234 EXPECT_CALL(*mComposer,
1235 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1236 .WillOnce(Return(Error::NONE));
1237 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1238}
1239
1240TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1241 using Case = HwcVirtualDisplayCase;
1242
1243 // --------------------------------------------------------------------
1244 // Preconditions
1245
1246 // The HWC supports at least one virtual display
1247 injectMockComposer(1);
1248
1249 setupCommonPreconditions<Case>();
1250
1251 // A virtual display was added to the current state, and it has a
1252 // surface(producer)
1253 sp<BBinder> displayToken = new BBinder();
1254 DisplayDeviceState info(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE));
1255 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
1256 info.surface = surface;
1257 mFlinger.mutableCurrentState().displays.add(displayToken, info);
1258
1259 // --------------------------------------------------------------------
1260 // Call Expectations
1261
1262 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1263 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1264
1265 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1266 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1267 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1268 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1269 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1270 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1271 Return(NO_ERROR)));
1272 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1273 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1274
1275 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1276
1277 EXPECT_CALL(*mProducer, connect(_, _, _, _)).Times(1);
1278 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1279
1280 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1281 Case::WideColorSupport::setupComposerCallExpectations(this);
1282 Case::HdrSupport::setupComposerCallExpectations(this);
1283
1284 // --------------------------------------------------------------------
1285 // Invocation
1286
1287 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1288
1289 // --------------------------------------------------------------------
1290 // Postconditions
1291
1292 // The display device should have been set up in the list of displays.
1293 verifyDisplayIsConnected<Case>(displayToken);
1294
1295 // --------------------------------------------------------------------
1296 // Cleanup conditions
1297
1298 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1299 .WillOnce(Return(Error::NONE));
1300 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1301}
1302
1303TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1304 using Case = HwcVirtualDisplayCase;
1305
1306 // --------------------------------------------------------------------
1307 // Preconditions
1308
1309 // The HWC supports at least one virtual display
1310 injectMockComposer(1);
1311
1312 setupCommonPreconditions<Case>();
1313
1314 // A virtual display was added to the current state, but it does not have a
1315 // surface.
1316 sp<BBinder> displayToken = new BBinder();
1317 DisplayDeviceState info(Case::Display::TYPE, static_cast<bool>(Case::Display::SECURE));
1318 mFlinger.mutableCurrentState().displays.add(displayToken, info);
1319
1320 // --------------------------------------------------------------------
1321 // Call Expectations
1322
1323 // --------------------------------------------------------------------
1324 // Invocation
1325
1326 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1327
1328 // --------------------------------------------------------------------
1329 // Postconditions
1330
1331 // There will not be a display device set up.
1332 EXPECT_FALSE(hasDisplayDevice(displayToken));
1333
1334 // The drawing display state will be set from the current display state.
1335 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1336 const auto& draw = getDrawingDisplayState(displayToken);
1337 EXPECT_EQ(Case::Display::TYPE, draw.type);
1338}
1339
1340TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1341 using Case = HwcVirtualDisplayCase;
1342
1343 // --------------------------------------------------------------------
1344 // Preconditions
1345
1346 // A virtual display is set up but is removed from the current state.
1347 mFlinger.mutableHwcDisplayData().resize(3);
1348 Case::Display::injectHwcDisplay(this);
1349 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1350 existing.inject();
1351 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1352
1353 // --------------------------------------------------------------------
1354 // Call Expectations
1355
1356 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1357
1358 // --------------------------------------------------------------------
1359 // Invocation
1360
1361 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1362
1363 // --------------------------------------------------------------------
1364 // Postconditions
1365
1366 // The existing token should have been removed
1367 verifyDisplayIsNotConnected(existing.token());
1368}
1369
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001370TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
1371 using Case = NonHwcVirtualDisplayCase;
1372
1373 constexpr uint32_t oldLayerStack = 0u;
1374 constexpr uint32_t newLayerStack = 123u;
1375
1376 // --------------------------------------------------------------------
1377 // Preconditions
1378
1379 // A display is set up
1380 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1381 display.inject();
1382
1383 // There is a change to the layerStack state
1384 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
1385 display.mutableCurrentDisplayState().layerStack = newLayerStack;
1386
1387 // --------------------------------------------------------------------
1388 // Invocation
1389
1390 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1391
1392 // --------------------------------------------------------------------
1393 // Postconditions
1394
1395 EXPECT_EQ(newLayerStack, getDisplayDevice(display.token())->getLayerStack());
1396}
1397
1398TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
1399 using Case = NonHwcVirtualDisplayCase;
1400
1401 constexpr int oldTransform = 0;
1402 constexpr int newTransform = 2;
1403
1404 // --------------------------------------------------------------------
1405 // Preconditions
1406
1407 // A display is set up
1408 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1409 display.inject();
1410
1411 // There is a change to the orientation state
1412 display.mutableDrawingDisplayState().orientation = oldTransform;
1413 display.mutableCurrentDisplayState().orientation = newTransform;
1414
1415 // --------------------------------------------------------------------
1416 // Invocation
1417
1418 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1419
1420 // --------------------------------------------------------------------
1421 // Postconditions
1422
1423 EXPECT_EQ(newTransform, getDisplayDevice(display.token())->getOrientation());
1424}
1425
1426TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
1427 using Case = NonHwcVirtualDisplayCase;
1428
1429 const Rect oldViewport(0, 0, 0, 0);
1430 const Rect newViewport(0, 0, 123, 456);
1431
1432 // --------------------------------------------------------------------
1433 // Preconditions
1434
1435 // A display is set up
1436 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1437 display.inject();
1438
1439 // There is a change to the viewport state
1440 display.mutableDrawingDisplayState().viewport = oldViewport;
1441 display.mutableCurrentDisplayState().viewport = newViewport;
1442
1443 // --------------------------------------------------------------------
1444 // Invocation
1445
1446 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1447
1448 // --------------------------------------------------------------------
1449 // Postconditions
1450
1451 EXPECT_EQ(newViewport, getDisplayDevice(display.token())->getViewport());
1452}
1453
1454TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
1455 using Case = NonHwcVirtualDisplayCase;
1456
1457 const Rect oldFrame(0, 0, 0, 0);
1458 const Rect newFrame(0, 0, 123, 456);
1459
1460 // --------------------------------------------------------------------
1461 // Preconditions
1462
1463 // A display is set up
1464 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1465 display.inject();
1466
1467 // There is a change to the viewport state
1468 display.mutableDrawingDisplayState().frame = oldFrame;
1469 display.mutableCurrentDisplayState().frame = newFrame;
1470
1471 // --------------------------------------------------------------------
1472 // Invocation
1473
1474 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1475
1476 // --------------------------------------------------------------------
1477 // Postconditions
1478
1479 EXPECT_EQ(newFrame, getDisplayDevice(display.token())->getFrame());
1480}
1481
1482TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
1483 using Case = NonHwcVirtualDisplayCase;
1484
1485 constexpr int oldWidth = 0;
1486 constexpr int oldHeight = 10;
1487 constexpr int newWidth = 123;
1488
1489 // --------------------------------------------------------------------
1490 // Preconditions
1491
1492 // A display is set up
1493 auto nativeWindow = new mock::NativeWindow();
1494 auto displaySurface = new mock::DisplaySurface();
1495 auto renderSurface = new RE::mock::Surface();
1496 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1497 display.setNativeWindow(nativeWindow);
1498 display.setDisplaySurface(displaySurface);
1499 display.setRenderSurface(std::unique_ptr<RE::Surface>(renderSurface));
1500 display.inject();
1501
1502 // There is a change to the viewport state
1503 display.mutableDrawingDisplayState().width = oldWidth;
1504 display.mutableDrawingDisplayState().height = oldHeight;
1505 display.mutableCurrentDisplayState().width = newWidth;
1506 display.mutableCurrentDisplayState().height = oldHeight;
1507
1508 // --------------------------------------------------------------------
1509 // Call Expectations
1510
1511 EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
1512 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
1513 EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
1514 EXPECT_CALL(*renderSurface, queryWidth()).WillOnce(Return(newWidth));
1515 EXPECT_CALL(*renderSurface, queryHeight()).WillOnce(Return(oldHeight));
1516
1517 // --------------------------------------------------------------------
1518 // Invocation
1519
1520 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1521}
1522
1523TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
1524 using Case = NonHwcVirtualDisplayCase;
1525
1526 constexpr int oldWidth = 0;
1527 constexpr int oldHeight = 10;
1528 constexpr int newHeight = 123;
1529
1530 // --------------------------------------------------------------------
1531 // Preconditions
1532
1533 // A display is set up
1534 auto nativeWindow = new mock::NativeWindow();
1535 auto displaySurface = new mock::DisplaySurface();
1536 auto renderSurface = new RE::mock::Surface();
1537 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1538 display.setNativeWindow(nativeWindow);
1539 display.setDisplaySurface(displaySurface);
1540 display.setRenderSurface(std::unique_ptr<RE::Surface>(renderSurface));
1541 display.inject();
1542
1543 // There is a change to the viewport state
1544 display.mutableDrawingDisplayState().width = oldWidth;
1545 display.mutableDrawingDisplayState().height = oldHeight;
1546 display.mutableCurrentDisplayState().width = oldWidth;
1547 display.mutableCurrentDisplayState().height = newHeight;
1548
1549 // --------------------------------------------------------------------
1550 // Call Expectations
1551
1552 EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
1553 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
1554 EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
1555 EXPECT_CALL(*renderSurface, queryWidth()).WillOnce(Return(oldWidth));
1556 EXPECT_CALL(*renderSurface, queryHeight()).WillOnce(Return(newHeight));
1557
1558 // --------------------------------------------------------------------
1559 // Invocation
1560
1561 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1562}
1563
Lloyd Piquef58625d2017-12-19 13:22:33 -08001564} // namespace
1565} // namespace android