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