blob: d32627a7d3511f5752ce6bcb83b0bfff6e09e4f2 [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
Valerie Hau9758ae02018-10-09 16:05:09 -070025#include <ui/DebugUtils.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080026#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080027#include "mock/DisplayHardware/MockComposer.h"
28#include "mock/DisplayHardware/MockDisplaySurface.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070029#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080030#include "mock/MockEventControlThread.h"
31#include "mock/MockEventThread.h"
32#include "mock/MockMessageQueue.h"
33#include "mock/MockNativeWindowSurface.h"
34#include "mock/MockSurfaceInterceptor.h"
35#include "mock/RenderEngine/MockRenderEngine.h"
36#include "mock/gui/MockGraphicBufferConsumer.h"
37#include "mock/gui/MockGraphicBufferProducer.h"
38#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080039
40namespace android {
41namespace {
42
Lloyd Piquee39cad22017-12-20 17:01:29 -080043using testing::_;
44using testing::ByMove;
45using testing::DoAll;
46using testing::Mock;
47using testing::Return;
48using testing::SetArgPointee;
49
Lloyd Piqued883d5a2018-04-27 19:32:30 -070050using android::Hwc2::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080051using android::Hwc2::Error;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070052using android::Hwc2::Hdr;
Lloyd Piquee39cad22017-12-20 17:01:29 -080053using android::Hwc2::IComposer;
54using android::Hwc2::IComposerClient;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070055using android::Hwc2::PerFrameMetadataKey;
56using android::Hwc2::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080057
Lloyd Piquec11e0d32018-01-22 18:44:59 -080058using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
59using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080060using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080061using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080062
Lloyd Piquec11e0d32018-01-22 18:44:59 -080063constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080064constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080065constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080066
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080067constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value
68
Lloyd Piquec11e0d32018-01-22 18:44:59 -080069/* ------------------------------------------------------------------------
70 * Boolean avoidance
71 *
72 * To make calls and template instantiations more readable, we define some
73 * local enums along with an implicit bool conversion.
74 */
75
76#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
77
78BOOL_SUBSTITUTE(Critical);
79BOOL_SUBSTITUTE(Async);
80BOOL_SUBSTITUTE(Secure);
81
82/* ------------------------------------------------------------------------
83 *
84 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080085
Lloyd Piquef58625d2017-12-19 13:22:33 -080086class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -080087public:
Lloyd Piquef58625d2017-12-19 13:22:33 -080088 DisplayTransactionTest();
89 ~DisplayTransactionTest() override;
90
Lloyd Pique1fa4d462018-01-22 18:03:16 -080091 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -080092 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -080093
Lloyd Piquec11e0d32018-01-22 18:44:59 -080094 void injectMockComposer(int virtualDisplayCount);
95 void injectFakeBufferQueueFactory();
96 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -080097
98 // --------------------------------------------------------------------
99 // Postcondition helpers
100
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800101 bool hasHwcDisplay(hwc2_display_t displayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800102 bool hasTransactionFlagSet(int flag);
103 bool hasDisplayDevice(sp<IBinder> displayToken);
104 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
105 bool hasCurrentDisplayState(sp<IBinder> displayToken);
106 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
107 bool hasDrawingDisplayState(sp<IBinder> displayToken);
108 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
109
110 // --------------------------------------------------------------------
111 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800112
Lloyd Piquef58625d2017-12-19 13:22:33 -0800113 TestableSurfaceFlinger mFlinger;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800114 mock::EventThread* mEventThread = new mock::EventThread();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800115 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800116
117 // These mocks are created by the test, but are destroyed by SurfaceFlinger
118 // by virtue of being stored into a std::unique_ptr. However we still need
119 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700120 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800121 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800122 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
123 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Lloyd Pique41be5d22018-06-21 13:11:48 -0700124 mock::DispSync* mPrimaryDispSync = new mock::DispSync();
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800125
126 // These mocks are created only when expected to be created via a factory.
127 sp<mock::GraphicBufferConsumer> mConsumer;
128 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700129 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800130 sp<mock::NativeWindow> mNativeWindow;
Peiyong Lin833074a2018-08-28 11:53:54 -0700131 renderengine::mock::Surface* mRenderSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800132};
133
134DisplayTransactionTest::DisplayTransactionTest() {
135 const ::testing::TestInfo* const test_info =
136 ::testing::UnitTest::GetInstance()->current_test_info();
137 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800138
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800139 // Default to no wide color display support configured
140 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700141 mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800142 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
143
144 // Default to using HWC virtual displays
145 mFlinger.mutableUseHwcVirtualDisplays() = true;
146
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800147 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
148 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
149 });
150
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800151 mFlinger.setCreateNativeWindowSurface([](auto) {
152 ADD_FAILURE() << "Unexpected request to create a native window surface.";
153 return nullptr;
154 });
155
156 mFlinger.mutableEventControlThread().reset(mEventControlThread);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800157 mFlinger.mutableEventThread().reset(mEventThread);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800158 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700159 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800160 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Pique41be5d22018-06-21 13:11:48 -0700161 mFlinger.mutablePrimaryDispSync().reset(mPrimaryDispSync);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800162
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800163 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800164}
165
166DisplayTransactionTest::~DisplayTransactionTest() {
167 const ::testing::TestInfo* const test_info =
168 ::testing::UnitTest::GetInstance()->current_test_info();
169 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
170}
171
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800172void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
173 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800174 EXPECT_CALL(*mComposer, getCapabilities())
175 .WillOnce(Return(std::vector<IComposer::Capability>()));
176 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
177 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800178
Lloyd Piquee39cad22017-12-20 17:01:29 -0800179 Mock::VerifyAndClear(mComposer);
180}
181
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800182void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800183 // This setup is only expected once per test.
184 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
185
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800186 mConsumer = new mock::GraphicBufferConsumer();
187 mProducer = new mock::GraphicBufferProducer();
188
189 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
190 *outProducer = mProducer;
191 *outConsumer = mConsumer;
192 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800193}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800194
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800195void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800196 // This setup is only expected once per test.
197 ASSERT_TRUE(mNativeWindowSurface == nullptr);
198
Lloyd Pique22098362018-09-13 11:46:49 -0700199 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800200 mNativeWindow = new mock::NativeWindow();
201
Lloyd Pique22098362018-09-13 11:46:49 -0700202 mFlinger.setCreateNativeWindowSurface([this](auto) {
203 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
204 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800205}
206
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800207bool DisplayTransactionTest::hasHwcDisplay(hwc2_display_t displayId) {
208 return mFlinger.mutableHwcDisplaySlots().count(displayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800209}
210
211bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
212 return mFlinger.mutableTransactionFlags() & flag;
213}
214
215bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700216 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800217}
218
219sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700220 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800221}
222
223bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
224 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
225}
226
227const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
228 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
229}
230
231bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
232 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
233}
234
235const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
236 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
237}
238
239/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800240 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800241 */
242
Dominik Laskowski7e045462018-05-30 13:02:02 -0700243template <DisplayDevice::DisplayType type, DisplayDevice::DisplayType displayId, int width,
244 int height, Critical critical, Async async, Secure secure, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800245struct DisplayVariant {
246 // The display width and height
247 static constexpr int WIDTH = width;
248 static constexpr int HEIGHT = height;
249
250 static constexpr int GRALLOC_USAGE = grallocUsage;
251
252 // The type for this display
253 static constexpr DisplayDevice::DisplayType TYPE = type;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700254 static_assert(TYPE != DisplayDevice::DISPLAY_ID_INVALID);
255
Dominik Laskowski7e045462018-05-30 13:02:02 -0700256 static constexpr DisplayDevice::DisplayType DISPLAY_ID = displayId;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800257
258 // When creating native window surfaces for the framebuffer, whether those should be critical
259 static constexpr Critical CRITICAL = critical;
260
261 // When creating native window surfaces for the framebuffer, whether those should be async
262 static constexpr Async ASYNC = async;
263
264 // Whether the display should be treated as secure
265 static constexpr Secure SECURE = secure;
266
267 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700268 auto injector = FakeDisplayDeviceInjector(test->mFlinger, TYPE, DISPLAY_ID);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800269 injector.setSecure(static_cast<bool>(SECURE));
270 return injector;
271 }
272
273 // Called by tests to set up any native window creation call expectations.
274 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
275 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
276 .WillOnce(Return(test->mNativeWindow));
277 EXPECT_CALL(*test->mNativeWindow, perform(19)).WillRepeatedly(Return(NO_ERROR));
278
279 // For simplicity, we only expect to create a single render surface for
280 // each test.
281 ASSERT_TRUE(test->mRenderSurface == nullptr);
Peiyong Lin833074a2018-08-28 11:53:54 -0700282 test->mRenderSurface = new renderengine::mock::Surface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800283 EXPECT_CALL(*test->mRenderEngine, createSurface())
Peiyong Lin833074a2018-08-28 11:53:54 -0700284 .WillOnce(Return(ByMove(
285 std::unique_ptr<renderengine::Surface>(test->mRenderSurface))));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800286 EXPECT_CALL(*test->mRenderSurface, setAsync(static_cast<bool>(ASYNC))).Times(1);
287 EXPECT_CALL(*test->mRenderSurface, setCritical(static_cast<bool>(CRITICAL))).Times(1);
288 EXPECT_CALL(*test->mRenderSurface, setNativeWindow(test->mNativeWindow.get())).Times(1);
Alec Mouri05483a02018-09-10 21:03:42 +0000289 EXPECT_CALL(*test->mRenderSurface, getWidth()).WillOnce(Return(WIDTH));
290 EXPECT_CALL(*test->mRenderSurface, getHeight()).WillOnce(Return(HEIGHT));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800291 }
292
293 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
294 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
295 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
296 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
297 .WillRepeatedly(Return(NO_ERROR));
298 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
299 .WillRepeatedly(Return(NO_ERROR));
300 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
301 .WillRepeatedly(Return(NO_ERROR));
302 }
303
304 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
305 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
306 }
307};
308
309template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant>
310struct HwcDisplayVariant {
311 // The display id supplied by the HWC
312 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
313
314 // The HWC display type
315 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
316
317 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700318 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800319
320 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
321 HWC2::Connection connection) {
322 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
323 HotplugEvent{HWC_DISPLAY_ID, connection});
324 }
325
326 // Called by tests to inject a HWC display setup
327 static void injectHwcDisplay(DisplayTransactionTest* test) {
328 FakeHwcDisplayInjector(DisplayVariant::TYPE, HWC_DISPLAY_TYPE)
329 .setHwcDisplayId(HWC_DISPLAY_ID)
330 .setWidth(DisplayVariant::WIDTH)
331 .setHeight(DisplayVariant::HEIGHT)
332 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
333 .inject(&test->mFlinger, test->mComposer);
334 }
335
336 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
337 EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _))
338 .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>(
339 HWC_DISPLAY_TYPE)),
340 Return(Error::NONE)));
341 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
342 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
343 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
344 Return(Error::NONE)));
345 EXPECT_CALL(*test->mComposer,
346 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
347 IComposerClient::Attribute::WIDTH, _))
348 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
349 EXPECT_CALL(*test->mComposer,
350 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
351 IComposerClient::Attribute::HEIGHT, _))
352 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
353 EXPECT_CALL(*test->mComposer,
354 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
355 IComposerClient::Attribute::VSYNC_PERIOD, _))
356 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
357 EXPECT_CALL(*test->mComposer,
358 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
359 IComposerClient::Attribute::DPI_X, _))
360 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
361 EXPECT_CALL(*test->mComposer,
362 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
363 IComposerClient::Attribute::DPI_Y, _))
364 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700365 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
366 .WillRepeatedly(Return(Error::UNSUPPORTED));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800367 }
368
369 // Called by tests to set up HWC call expectations
370 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
371 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700372 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800373 }
374};
375
376struct NonHwcDisplayVariant {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800377 static void injectHwcDisplay(DisplayTransactionTest*) {}
378
379 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
380 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
381 }
382};
383
384// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
385constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
386 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
387
388template <hwc2_display_t hwcDisplayId, DisplayDevice::DisplayType type, int width, int height,
389 Critical critical>
390struct PhysicalDisplayVariant
391 : public DisplayVariant<type, type, width, height, critical, Async::FALSE, Secure::TRUE,
392 GRALLOC_USAGE_PHYSICAL_DISPLAY>,
393 public HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
394 DisplayVariant<type, type, width, height, critical, Async::FALSE,
395 Secure::TRUE, GRALLOC_USAGE_PHYSICAL_DISPLAY>> {};
396
397// A primary display is a physical display that is critical
398using PrimaryDisplayVariant =
399 PhysicalDisplayVariant<1001, DisplayDevice::DISPLAY_PRIMARY, 3840, 2160, Critical::TRUE>;
400
401// An external display is physical display that is not critical.
402using ExternalDisplayVariant =
403 PhysicalDisplayVariant<1002, DisplayDevice::DISPLAY_EXTERNAL, 1920, 1280, Critical::FALSE>;
404
405using TertiaryDisplayVariant =
406 PhysicalDisplayVariant<1003, DisplayDevice::DISPLAY_EXTERNAL, 1600, 1200, Critical::FALSE>;
407
408// A virtual display not supported by the HWC.
409constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
410
411template <int width, int height, Secure secure>
412struct NonHwcVirtualDisplayVariant
413 : public DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_ID_INVALID,
414 width, height, Critical::FALSE, Async::TRUE, secure,
415 GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>,
416 public NonHwcDisplayVariant {
417 using Base = DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_ID_INVALID,
418 width, height, Critical::FALSE, Async::TRUE, secure,
419 GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
420
421 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
422 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
423 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
424 }
425};
426
427// A virtual display supported by the HWC.
428constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
429
430template <int width, int height, Secure secure>
431struct HwcVirtualDisplayVariant
432 : public DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_VIRTUAL, width,
433 height, Critical::FALSE, Async::TRUE, secure,
434 GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
435 public HwcDisplayVariant<1010, HWC2::DisplayType::Virtual,
436 NonHwcVirtualDisplayVariant<width, height, secure>> {
437 using Base =
438 DisplayVariant<DisplayDevice::DISPLAY_VIRTUAL, DisplayDevice::DISPLAY_VIRTUAL, width,
439 height, Critical::FALSE, Async::TRUE, secure, GRALLOC_USAGE_HW_COMPOSER>;
440 using Self = HwcVirtualDisplayVariant<width, height, secure>;
441
442 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
443 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
444 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
445 }
446
447 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
448 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
449 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
450 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
451 }
452};
453
454// For this variant, SurfaceFlinger should not configure itself with wide
455// display support, so the display should not be configured for wide-color
456// support.
457struct WideColorSupportNotConfiguredVariant {
458 static constexpr bool WIDE_COLOR_SUPPORTED = false;
459
460 static void injectConfigChange(DisplayTransactionTest* test) {
461 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700462 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800463 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
464 }
465
466 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
467 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
468 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
469 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
470 }
471};
472
473// For this variant, SurfaceFlinger should configure itself with wide display
474// support, and the display should respond with an non-empty list of supported
475// color modes. Wide-color support should be configured.
476template <typename Display>
477struct WideColorP3ColorimetricSupportedVariant {
478 static constexpr bool WIDE_COLOR_SUPPORTED = true;
479
480 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700481 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800482 test->mFlinger.mutableHasWideColorDisplay() = true;
483 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
484 }
485
486 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
487 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
488 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
489 Return(Error::NONE)));
490 EXPECT_CALL(*test->mComposer,
491 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
492 .WillOnce(DoAll(SetArgPointee<2>(
493 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
494 Return(Error::NONE)));
495 EXPECT_CALL(*test->mComposer,
496 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
497 RenderIntent::COLORIMETRIC))
498 .WillOnce(Return(Error::NONE));
499 }
500};
501
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800502// For this variant, SurfaceFlinger should configure itself with wide display
503// support, but the display should respond with an empty list of supported color
504// modes. Wide-color support for the display should not be configured.
505template <typename Display>
506struct WideColorNotSupportedVariant {
507 static constexpr bool WIDE_COLOR_SUPPORTED = false;
508
509 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700510 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800511 test->mFlinger.mutableHasWideColorDisplay() = true;
512 }
513
514 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
515 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
516 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700517 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800518 }
519};
520
521// For this variant, the display is not a HWC display, so no HDR support should
522// be configured.
523struct NonHwcDisplayHdrSupportVariant {
524 static constexpr bool HDR10_SUPPORTED = false;
525 static constexpr bool HDR_HLG_SUPPORTED = false;
526 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
527 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
528 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
529 }
530};
531
532// For this variant, the composer should respond with a non-empty list of HDR
533// modes containing HDR10, so HDR10 support should be configured.
534template <typename Display>
535struct Hdr10SupportedVariant {
536 static constexpr bool HDR10_SUPPORTED = true;
537 static constexpr bool HDR_HLG_SUPPORTED = false;
538 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
539 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
540 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
541 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
542 Return(Error::NONE)));
543 }
544};
545
546// For this variant, the composer should respond with a non-empty list of HDR
547// modes containing HLG, so HLG support should be configured.
548template <typename Display>
549struct HdrHlgSupportedVariant {
550 static constexpr bool HDR10_SUPPORTED = false;
551 static constexpr bool HDR_HLG_SUPPORTED = true;
552 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
553 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
554 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
555 .WillOnce(
556 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
557 }
558};
559
560// For this variant, the composer should respond with a non-empty list of HDR
561// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
562template <typename Display>
563struct HdrDolbyVisionSupportedVariant {
564 static constexpr bool HDR10_SUPPORTED = false;
565 static constexpr bool HDR_HLG_SUPPORTED = false;
566 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
567 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
568 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
569 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
570 Return(Error::NONE)));
571 }
572};
573
574// For this variant, the composer should respond with am empty list of HDR
575// modes, so no HDR support should be configured.
576template <typename Display>
577struct HdrNotSupportedVariant {
578 static constexpr bool HDR10_SUPPORTED = false;
579 static constexpr bool HDR_HLG_SUPPORTED = false;
580 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
581 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
582 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
583 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
584 }
585};
586
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700587struct NonHwcPerFrameMetadataSupportVariant {
588 static constexpr int PER_FRAME_METADATA_KEYS = 0;
589 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800590 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700591 }
592};
593
594template <typename Display>
595struct NoPerFrameMetadataSupportVariant {
596 static constexpr int PER_FRAME_METADATA_KEYS = 0;
597 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800598 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
599 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700600 }
601};
602
603template <typename Display>
604struct Smpte2086PerFrameMetadataSupportVariant {
605 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
606 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800607 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
608 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700609 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
610 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
611 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
612 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
613 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
614 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
615 PerFrameMetadataKey::WHITE_POINT_X,
616 PerFrameMetadataKey::WHITE_POINT_Y,
617 PerFrameMetadataKey::MAX_LUMINANCE,
618 PerFrameMetadataKey::MIN_LUMINANCE,
Chia-I Wud7e01d72018-06-21 13:39:09 +0800619 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700620 }
621};
622
623template <typename Display>
624struct Cta861_3_PerFrameMetadataSupportVariant {
625 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
626 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800627 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
628 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700629 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
630 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
Chia-I Wud7e01d72018-06-21 13:39:09 +0800631 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700632 }
633};
634
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800635/* ------------------------------------------------------------------------
636 * Typical display configurations to test
637 */
638
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700639template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
640 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800641struct Case {
642 using Display = DisplayPolicy;
643 using WideColorSupport = WideColorSupportPolicy;
644 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700645 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800646};
647
648using SimplePrimaryDisplayCase =
649 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700650 HdrNotSupportedVariant<PrimaryDisplayVariant>,
651 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800652using SimpleExternalDisplayCase =
653 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700654 HdrNotSupportedVariant<ExternalDisplayVariant>,
655 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800656using SimpleTertiaryDisplayCase =
657 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700658 HdrNotSupportedVariant<TertiaryDisplayVariant>,
659 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800660using NonHwcVirtualDisplayCase =
661 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700662 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
663 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800664using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
665using HwcVirtualDisplayCase =
666 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700667 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800668 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800669using WideColorP3ColorimetricDisplayCase =
670 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700671 HdrNotSupportedVariant<PrimaryDisplayVariant>,
672 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800673using Hdr10DisplayCase =
674 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700675 Hdr10SupportedVariant<PrimaryDisplayVariant>,
676 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800677using HdrHlgDisplayCase =
678 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700679 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
680 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800681using HdrDolbyVisionDisplayCase =
682 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700683 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
684 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
685using HdrSmpte2086DisplayCase =
686 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
687 HdrNotSupportedVariant<PrimaryDisplayVariant>,
688 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
689using HdrCta861_3_DisplayCase =
690 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
691 HdrNotSupportedVariant<PrimaryDisplayVariant>,
692 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700693
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800694/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800695 *
696 * SurfaceFlinger::onHotplugReceived
697 */
698
699TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
700 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700701 constexpr hwc2_display_t hwcDisplayId1 = 456;
702 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800703
704 // --------------------------------------------------------------------
705 // Preconditions
706
707 // Set the current sequence id for accepted events
708 mFlinger.mutableComposerSequenceId() = currentSequenceId;
709
710 // Set the main thread id so that the current thread does not appear to be
711 // the main thread.
712 mFlinger.mutableMainThreadId() = std::thread::id();
713
714 // --------------------------------------------------------------------
715 // Call Expectations
716
717 // We expect invalidate() to be invoked once to trigger display transaction
718 // processing.
719 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
720
721 // --------------------------------------------------------------------
722 // Invocation
723
724 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700725 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
726 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800727
728 // --------------------------------------------------------------------
729 // Postconditions
730
731 // The display transaction needed flag should be set.
732 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
733
734 // All events should be in the pending event queue.
735 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
736 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700737 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800738 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700739 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800740 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
741}
742
743TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
744 constexpr int currentSequenceId = 123;
745 constexpr int otherSequenceId = 321;
746 constexpr hwc2_display_t displayId = 456;
747
748 // --------------------------------------------------------------------
749 // Preconditions
750
751 // Set the current sequence id for accepted events
752 mFlinger.mutableComposerSequenceId() = currentSequenceId;
753
754 // Set the main thread id so that the current thread does not appear to be
755 // the main thread.
756 mFlinger.mutableMainThreadId() = std::thread::id();
757
758 // --------------------------------------------------------------------
759 // Call Expectations
760
761 // We do not expect any calls to invalidate().
762 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
763
764 // --------------------------------------------------------------------
765 // Invocation
766
767 // Call with an unexpected sequence id
768 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
769
770 // --------------------------------------------------------------------
771 // Postconditions
772
773 // The display transaction needed flag should not be set
774 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
775
776 // There should be no pending events
777 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
778}
779
780TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
781 constexpr int currentSequenceId = 123;
782 constexpr hwc2_display_t displayId1 = 456;
783
784 // --------------------------------------------------------------------
785 // Note:
786 // --------------------------------------------------------------------
787 // This test case is a bit tricky. We want to verify that
788 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
789 // don't really want to provide coverage for everything the later function
790 // does as there are specific tests for it.
791 // --------------------------------------------------------------------
792
793 // --------------------------------------------------------------------
794 // Preconditions
795
796 // Set the current sequence id for accepted events
797 mFlinger.mutableComposerSequenceId() = currentSequenceId;
798
799 // Set the main thread id so that the current thread does appear to be the
800 // main thread.
801 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
802
803 // --------------------------------------------------------------------
804 // Call Expectations
805
806 // We expect invalidate() to be invoked once to trigger display transaction
807 // processing.
808 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
809
810 // --------------------------------------------------------------------
811 // Invocation
812
813 // Simulate a disconnect on a display id that is not connected. This should
814 // be enqueued by onHotplugReceived(), and dequeued by
815 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
816 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
817
818 // --------------------------------------------------------------------
819 // Postconditions
820
821 // The display transaction needed flag should be set.
822 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
823
824 // There should be no event queued on return, as it should have been
825 // processed.
826 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
827}
828
829/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -0800830 * SurfaceFlinger::createDisplay
831 */
832
833TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
834 const String8 name("virtual.test");
835
836 // --------------------------------------------------------------------
837 // Call Expectations
838
839 // The call should notify the interceptor that a display was created.
840 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
841
842 // --------------------------------------------------------------------
843 // Invocation
844
845 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
846
847 // --------------------------------------------------------------------
848 // Postconditions
849
850 // The display should have been added to the current state
851 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
852 const auto& display = getCurrentDisplayState(displayToken);
853 EXPECT_EQ(DisplayDevice::DISPLAY_VIRTUAL, display.type);
854 EXPECT_EQ(false, display.isSecure);
855 EXPECT_EQ(name.string(), display.displayName);
856
857 // --------------------------------------------------------------------
858 // Cleanup conditions
859
860 // Destroying the display invalidates the display state.
861 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
862}
863
864TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
865 const String8 name("virtual.test");
866
867 // --------------------------------------------------------------------
868 // Call Expectations
869
870 // The call should notify the interceptor that a display was created.
871 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
872
873 // --------------------------------------------------------------------
874 // Invocation
875
876 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
877
878 // --------------------------------------------------------------------
879 // Postconditions
880
881 // The display should have been added to the current state
882 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
883 const auto& display = getCurrentDisplayState(displayToken);
884 EXPECT_EQ(DisplayDevice::DISPLAY_VIRTUAL, display.type);
885 EXPECT_EQ(true, display.isSecure);
886 EXPECT_EQ(name.string(), display.displayName);
887
888 // --------------------------------------------------------------------
889 // Cleanup conditions
890
891 // Destroying the display invalidates the display state.
892 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
893}
894
895/* ------------------------------------------------------------------------
896 * SurfaceFlinger::destroyDisplay
897 */
898
899TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
900 using Case = NonHwcVirtualDisplayCase;
901
902 // --------------------------------------------------------------------
903 // Preconditions
904
905 // A virtual display exists
906 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
907 existing.inject();
908
909 // --------------------------------------------------------------------
910 // Call Expectations
911
912 // The call should notify the interceptor that a display was created.
913 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
914
915 // Destroying the display invalidates the display state.
916 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
917
918 // --------------------------------------------------------------------
919 // Invocation
920
921 mFlinger.destroyDisplay(existing.token());
922
923 // --------------------------------------------------------------------
924 // Postconditions
925
926 // The display should have been removed from the current state
927 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
928
929 // Ths display should still exist in the drawing state
930 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
931
932 // The display transaction needed flasg should be set
933 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
934}
935
936TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
937 // --------------------------------------------------------------------
938 // Preconditions
939
940 sp<BBinder> displayToken = new BBinder();
941
942 // --------------------------------------------------------------------
943 // Invocation
944
945 mFlinger.destroyDisplay(displayToken);
946}
947
948/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -0800949 * SurfaceFlinger::resetDisplayState
950 */
951
952TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
953 using Case = NonHwcVirtualDisplayCase;
954
955 // --------------------------------------------------------------------
956 // Preconditions
957
958 // vsync is enabled and available
959 mFlinger.mutablePrimaryHWVsyncEnabled() = true;
960 mFlinger.mutableHWVsyncAvailable() = true;
961
962 // A display exists
963 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
964 existing.inject();
965
966 // --------------------------------------------------------------------
967 // Call Expectations
968
969 // The call disable vsyncs
970 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
971
972 // The call clears the current render engine surface
973 EXPECT_CALL(*mRenderEngine, resetCurrentSurface());
974
Lloyd Pique41be5d22018-06-21 13:11:48 -0700975 // The call ends any display resyncs
976 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
977
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -0800978 // --------------------------------------------------------------------
979 // Invocation
980
981 mFlinger.resetDisplayState();
982
983 // --------------------------------------------------------------------
984 // Postconditions
985
986 // vsyncs should be off and not available.
987 EXPECT_FALSE(mFlinger.mutablePrimaryHWVsyncEnabled());
988 EXPECT_FALSE(mFlinger.mutableHWVsyncAvailable());
989
990 // The display should have been removed from the display map.
991 EXPECT_FALSE(hasDisplayDevice(existing.token()));
992
993 // The display should still exist in the current state
994 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
995
996 // The display should have been removed from the drawing state
997 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
998}
999
1000/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001001 * DisplayDevice::GetBestColorMode
1002 */
1003class GetBestColorModeTest : public DisplayTransactionTest {
1004public:
1005 GetBestColorModeTest()
1006 : DisplayTransactionTest(),
1007 mInjector(FakeDisplayDeviceInjector(mFlinger, DisplayDevice::DISPLAY_PRIMARY, 0)) {}
1008
1009 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1010
1011 void addHwcColorModesMapping(ui::ColorMode colorMode,
1012 std::vector<ui::RenderIntent> renderIntents) {
1013 mHwcColorModes[colorMode] = renderIntents;
1014 }
1015
1016 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1017
1018 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1019
1020 void getBestColorMode() {
1021 mInjector.setHwcColorModes(mHwcColorModes);
1022 mInjector.setHasWideColorGamut(mHasWideColorGamut);
1023 auto displayDevice = mInjector.inject();
1024
1025 displayDevice->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1026 &mOutColorMode, &mOutRenderIntent);
1027 }
1028
1029 ui::Dataspace mOutDataspace;
1030 ui::ColorMode mOutColorMode;
1031 ui::RenderIntent mOutRenderIntent;
1032
1033private:
1034 ui::Dataspace mInputDataspace;
1035 ui::RenderIntent mInputRenderIntent;
1036 bool mHasWideColorGamut = false;
1037 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1038 FakeDisplayDeviceInjector mInjector;
1039};
1040
1041TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1042 addHwcColorModesMapping(ui::ColorMode::SRGB,
1043 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1044 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1045 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1046 setHasWideColorGamut(true);
1047
1048 getBestColorMode();
1049
1050 ASSERT_EQ(ui::Dataspace::SRGB, mOutDataspace);
1051 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1052 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1053}
1054
1055TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1056 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1057 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1058 addHwcColorModesMapping(ui::ColorMode::SRGB,
1059 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1060 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1061 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1062 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1063 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1064 setHasWideColorGamut(true);
1065
1066 getBestColorMode();
1067
1068 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1069 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1070 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1071}
1072
1073TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1074 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1075 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1076 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1077 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1078 setHasWideColorGamut(true);
1079
1080 getBestColorMode();
1081
1082 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1083 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1084 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1085}
1086
1087/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001088 * SurfaceFlinger::setupNewDisplayDeviceInternal
1089 */
1090
1091class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1092public:
1093 template <typename T>
1094 void setupNewDisplayDeviceInternalTest();
1095};
1096
1097template <typename Case>
1098void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1099 const sp<BBinder> displayToken = new BBinder();
1100 const sp<mock::DisplaySurface> displaySurface = new mock::DisplaySurface();
1101 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001102
1103 // --------------------------------------------------------------------
1104 // Preconditions
1105
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001106 // Wide color displays support is configured appropriately
1107 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001108
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001109 // The display is setup with the HWC.
1110 Case::Display::injectHwcDisplay(this);
1111
1112 // SurfaceFlinger will use a test-controlled factory for native window
1113 // surfaces.
1114 injectFakeNativeWindowSurfaceFactory();
1115
1116 // --------------------------------------------------------------------
1117 // Call Expectations
1118
1119 // Various native window calls will be made.
1120 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001121 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001122 Case::WideColorSupport::setupComposerCallExpectations(this);
1123 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001124 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001125
1126 // --------------------------------------------------------------------
1127 // Invocation
1128
1129 DisplayDeviceState state;
1130 state.type = Case::Display::TYPE;
1131 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1132
1133 auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::TYPE, state,
1134 displaySurface, producer);
1135
1136 // --------------------------------------------------------------------
1137 // Postconditions
1138
1139 ASSERT_TRUE(device != nullptr);
1140 EXPECT_EQ(Case::Display::TYPE, device->getDisplayType());
1141 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
1142 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1143 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1144 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
1145 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1146 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1147 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001148 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1149 // remapped, and the test only ever sets up one config. If there were an error
1150 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
1151 EXPECT_EQ(0, device->getActiveConfig());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001152 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1153 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001154}
1155
1156TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1157 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1158}
1159
1160TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1161 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1162}
1163
1164TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1165 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1166}
1167
1168TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
1169 // We need to resize this so that the HWC thinks the virtual display
1170 // is something it created.
1171 mFlinger.mutableHwcDisplayData().resize(3);
1172
1173 setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>();
1174}
1175
1176TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1177 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1178}
1179
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001180TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1181 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1182}
1183
1184TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1185 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1186}
1187
1188TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1189 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1190}
1191
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001192TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1193 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1194}
1195
1196TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1197 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1198}
1199
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001200/* ------------------------------------------------------------------------
1201 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1202 */
1203
1204class HandleTransactionLockedTest : public DisplayTransactionTest {
1205public:
1206 template <typename Case>
1207 void setupCommonPreconditions();
1208
1209 template <typename Case>
1210 void setupCommonCallExpectationsForConnectProcessing();
1211
1212 template <typename Case>
1213 void setupCommonCallExpectationsForDisconnectProcessing();
1214
1215 template <typename Case>
1216 void processesHotplugConnectCommon();
1217
1218 template <typename Case>
1219 void ignoresHotplugConnectCommon();
1220
1221 template <typename Case>
1222 void processesHotplugDisconnectCommon();
1223
1224 template <typename Case>
1225 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1226
1227 template <typename Case>
1228 void verifyPhysicalDisplayIsConnected();
1229
1230 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1231};
1232
1233template <typename Case>
1234void HandleTransactionLockedTest::setupCommonPreconditions() {
1235 // Wide color displays support is configured appropriately
1236 Case::WideColorSupport::injectConfigChange(this);
1237
1238 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1239 injectFakeBufferQueueFactory();
1240
1241 // SurfaceFlinger will use a test-controlled factory for native window
1242 // surfaces.
1243 injectFakeNativeWindowSurfaceFactory();
1244}
1245
1246template <typename Case>
1247void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1248 Case::Display::setupHwcHotplugCallExpectations(this);
1249
1250 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1251 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1252 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1253 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1254
1255 Case::WideColorSupport::setupComposerCallExpectations(this);
1256 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001257 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001258
1259 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowski00a6fa22018-06-06 16:42:02 -07001260 EXPECT_CALL(*mEventThread,
1261 onHotplugReceived(Case::Display::TYPE == DisplayDevice::DISPLAY_PRIMARY
1262 ? EventThread::DisplayType::Primary
1263 : EventThread::DisplayType::External,
1264 true))
1265 .Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001266}
1267
1268template <typename Case>
1269void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1270 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski00a6fa22018-06-06 16:42:02 -07001271 EXPECT_CALL(*mEventThread,
1272 onHotplugReceived(Case::Display::TYPE == DisplayDevice::DISPLAY_PRIMARY
1273 ? EventThread::DisplayType::Primary
1274 : EventThread::DisplayType::External,
1275 false))
1276 .Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001277}
1278
1279template <typename Case>
1280void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1281 // The display device should have been set up in the list of displays.
1282 ASSERT_TRUE(hasDisplayDevice(displayToken));
1283 const auto& device = getDisplayDevice(displayToken);
1284 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
1285 EXPECT_EQ(Case::Display::TYPE == DisplayDevice::DISPLAY_PRIMARY, device->isPrimary());
1286
1287 // The display should have been set up in the current display state
1288 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1289 const auto& current = getCurrentDisplayState(displayToken);
1290 EXPECT_EQ(Case::Display::TYPE, current.type);
1291
1292 // The display should have been set up in the drawing display state
1293 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1294 const auto& draw = getDrawingDisplayState(displayToken);
1295 EXPECT_EQ(Case::Display::TYPE, draw.type);
1296}
1297
1298template <typename Case>
1299void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1300 // HWComposer should have an entry for the display
1301 EXPECT_TRUE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1302
1303 // The display should be set up as a built-in display.
1304 static_assert(0 <= Case::Display::TYPE &&
1305 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
1306 "Must use a valid physical display type index for the fixed-size array");
Dominik Laskowskieecd6592018-05-29 10:25:41 -07001307 auto& displayToken = mFlinger.mutableDisplayTokens()[Case::Display::TYPE];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001308 ASSERT_TRUE(displayToken != nullptr);
1309
1310 verifyDisplayIsConnected<Case>(displayToken);
1311}
1312
1313void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1314 EXPECT_FALSE(hasDisplayDevice(displayToken));
1315 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1316 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1317}
1318
1319template <typename Case>
1320void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1321 // --------------------------------------------------------------------
1322 // Preconditions
1323
1324 setupCommonPreconditions<Case>();
1325
1326 // A hotplug connect event is enqueued for a display
1327 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001328
1329 // --------------------------------------------------------------------
1330 // Call Expectations
1331
1332 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001333
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001334 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001335
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001336 // --------------------------------------------------------------------
1337 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001338
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001339 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001340
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001341 // --------------------------------------------------------------------
1342 // Postconditions
1343
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001344 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001345
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001346 // --------------------------------------------------------------------
1347 // Cleanup conditions
1348
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001349 EXPECT_CALL(*mComposer,
1350 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001351 .WillOnce(Return(Error::NONE));
1352 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001353}
1354
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001355template <typename Case>
1356void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1357 // --------------------------------------------------------------------
1358 // Preconditions
1359
1360 setupCommonPreconditions<Case>();
1361
1362 // A hotplug connect event is enqueued for a display
1363 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1364
1365 // --------------------------------------------------------------------
1366 // Invocation
1367
1368 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1369
1370 // --------------------------------------------------------------------
1371 // Postconditions
1372
1373 // HWComposer should not have an entry for the display
1374 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1375}
1376
1377template <typename Case>
1378void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1379 // --------------------------------------------------------------------
1380 // Preconditions
1381
1382 setupCommonPreconditions<Case>();
1383
1384 // A hotplug disconnect event is enqueued for a display
1385 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1386
1387 // The display is already completely set up.
1388 Case::Display::injectHwcDisplay(this);
1389 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1390 existing.inject();
1391
1392 // --------------------------------------------------------------------
1393 // Call Expectations
1394
1395 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001396 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1397 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001398
1399 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1400
1401 // --------------------------------------------------------------------
1402 // Invocation
1403
1404 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1405
1406 // --------------------------------------------------------------------
1407 // Postconditions
1408
1409 // HWComposer should not have an entry for the display
1410 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1411
1412 // The display should not be set up as a built-in display.
1413 ASSERT_TRUE(0 <= Case::Display::TYPE &&
1414 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES);
Dominik Laskowskieecd6592018-05-29 10:25:41 -07001415 auto displayToken = mFlinger.mutableDisplayTokens()[Case::Display::TYPE];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001416 EXPECT_TRUE(displayToken == nullptr);
1417
1418 // The existing token should have been removed
1419 verifyDisplayIsNotConnected(existing.token());
1420}
1421
1422TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1423 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1424}
1425
1426TEST_F(HandleTransactionLockedTest,
1427 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1428 // Inject an external display.
1429 ExternalDisplayVariant::injectHwcDisplay(this);
1430
1431 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1432}
1433
1434TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1435 // Inject a primary display.
1436 PrimaryDisplayVariant::injectHwcDisplay(this);
1437
1438 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1439}
1440
1441TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1442 // Inject both a primary and external display.
1443 PrimaryDisplayVariant::injectHwcDisplay(this);
1444 ExternalDisplayVariant::injectHwcDisplay(this);
1445
1446 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1447
1448 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1449}
1450
1451TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1452 // Inject a primary display.
1453 PrimaryDisplayVariant::injectHwcDisplay(this);
1454
1455 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1456
1457 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1458}
1459
1460TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1461 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1462}
1463
1464TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1465 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1466}
1467
1468TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1469 using Case = SimplePrimaryDisplayCase;
1470
1471 // --------------------------------------------------------------------
1472 // Preconditions
1473
1474 setupCommonPreconditions<Case>();
1475
1476 // A hotplug connect event is enqueued for a display
1477 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1478 // A hotplug disconnect event is also enqueued for the same display
1479 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1480
1481 // --------------------------------------------------------------------
1482 // Call Expectations
1483
1484 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1485
1486 setupCommonCallExpectationsForConnectProcessing<Case>();
1487 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1488
1489 EXPECT_CALL(*mComposer,
1490 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1491 .WillOnce(Return(Error::NONE));
1492 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1493
1494 // --------------------------------------------------------------------
1495 // Invocation
1496
1497 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1498
1499 // --------------------------------------------------------------------
1500 // Postconditions
1501
1502 // HWComposer should not have an entry for the display
1503 EXPECT_FALSE(hasHwcDisplay(Case::Display::HWC_DISPLAY_ID));
1504
1505 // The display should not be set up as a primary built-in display.
1506 ASSERT_TRUE(0 <= Case::Display::TYPE &&
1507 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES);
Dominik Laskowskieecd6592018-05-29 10:25:41 -07001508 auto displayToken = mFlinger.mutableDisplayTokens()[Case::Display::TYPE];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001509 EXPECT_TRUE(displayToken == nullptr);
1510}
1511
1512TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1513 using Case = SimplePrimaryDisplayCase;
1514
1515 // --------------------------------------------------------------------
1516 // Preconditions
1517
1518 setupCommonPreconditions<Case>();
1519
1520 // The display is already completely set up.
1521 Case::Display::injectHwcDisplay(this);
1522 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1523 existing.inject();
1524
1525 // A hotplug disconnect event is enqueued for a display
1526 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1527 // A hotplug connect event is also enqueued for the same display
1528 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1529
1530 // --------------------------------------------------------------------
1531 // Call Expectations
1532
1533 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1534
1535 setupCommonCallExpectationsForConnectProcessing<Case>();
1536 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1537
1538 // --------------------------------------------------------------------
1539 // Invocation
1540
1541 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1542
1543 // --------------------------------------------------------------------
1544 // Postconditions
1545
1546 // The existing token should have been removed
1547 verifyDisplayIsNotConnected(existing.token());
1548 static_assert(0 <= Case::Display::TYPE &&
1549 Case::Display::TYPE < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
1550 "Display type must be a built-in display");
Dominik Laskowskieecd6592018-05-29 10:25:41 -07001551 EXPECT_NE(existing.token(), mFlinger.mutableDisplayTokens()[Case::Display::TYPE]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001552
1553 // A new display should be connected in its place
1554
1555 verifyPhysicalDisplayIsConnected<Case>();
1556
1557 // --------------------------------------------------------------------
1558 // Cleanup conditions
1559
1560 EXPECT_CALL(*mComposer,
1561 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1562 .WillOnce(Return(Error::NONE));
1563 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1564}
1565
1566TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1567 using Case = HwcVirtualDisplayCase;
1568
1569 // --------------------------------------------------------------------
1570 // Preconditions
1571
1572 // The HWC supports at least one virtual display
1573 injectMockComposer(1);
1574
1575 setupCommonPreconditions<Case>();
1576
1577 // A virtual display was added to the current state, and it has a
1578 // surface(producer)
1579 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07001580
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001581 DisplayDeviceState info;
1582 info.type = Case::Display::TYPE;
1583 info.isSecure = static_cast<bool>(Case::Display::SECURE);
1584
1585 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
1586 info.surface = surface;
1587 mFlinger.mutableCurrentState().displays.add(displayToken, info);
1588
1589 // --------------------------------------------------------------------
1590 // Call Expectations
1591
1592 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1593 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1594
1595 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1596 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1597 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1598 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1599 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1600 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1601 Return(NO_ERROR)));
1602 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1603 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1604
1605 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1606
1607 EXPECT_CALL(*mProducer, connect(_, _, _, _)).Times(1);
1608 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1609
1610 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1611 Case::WideColorSupport::setupComposerCallExpectations(this);
1612 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001613 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001614
1615 // --------------------------------------------------------------------
1616 // Invocation
1617
1618 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1619
1620 // --------------------------------------------------------------------
1621 // Postconditions
1622
1623 // The display device should have been set up in the list of displays.
1624 verifyDisplayIsConnected<Case>(displayToken);
1625
1626 // --------------------------------------------------------------------
1627 // Cleanup conditions
1628
1629 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1630 .WillOnce(Return(Error::NONE));
1631 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1632}
1633
1634TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1635 using Case = HwcVirtualDisplayCase;
1636
1637 // --------------------------------------------------------------------
1638 // Preconditions
1639
1640 // The HWC supports at least one virtual display
1641 injectMockComposer(1);
1642
1643 setupCommonPreconditions<Case>();
1644
1645 // A virtual display was added to the current state, but it does not have a
1646 // surface.
1647 sp<BBinder> displayToken = new BBinder();
1648
1649 DisplayDeviceState info;
1650 info.type = Case::Display::TYPE;
Chia-I Wu0f509fb2018-06-21 15:52:50 +08001651 info.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001652
1653 mFlinger.mutableCurrentState().displays.add(displayToken, info);
1654
1655 // --------------------------------------------------------------------
1656 // Call Expectations
1657
1658 // --------------------------------------------------------------------
1659 // Invocation
1660
1661 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1662
1663 // --------------------------------------------------------------------
1664 // Postconditions
1665
1666 // There will not be a display device set up.
1667 EXPECT_FALSE(hasDisplayDevice(displayToken));
1668
1669 // The drawing display state will be set from the current display state.
1670 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1671 const auto& draw = getDrawingDisplayState(displayToken);
1672 EXPECT_EQ(Case::Display::TYPE, draw.type);
1673}
1674
1675TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1676 using Case = HwcVirtualDisplayCase;
1677
1678 // --------------------------------------------------------------------
1679 // Preconditions
1680
1681 // A virtual display is set up but is removed from the current state.
1682 mFlinger.mutableHwcDisplayData().resize(3);
1683 Case::Display::injectHwcDisplay(this);
1684 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1685 existing.inject();
1686 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1687
1688 // --------------------------------------------------------------------
1689 // Call Expectations
1690
1691 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1692
1693 // --------------------------------------------------------------------
1694 // Invocation
1695
1696 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1697
1698 // --------------------------------------------------------------------
1699 // Postconditions
1700
1701 // The existing token should have been removed
1702 verifyDisplayIsNotConnected(existing.token());
1703}
1704
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001705TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
1706 using Case = NonHwcVirtualDisplayCase;
1707
1708 constexpr uint32_t oldLayerStack = 0u;
1709 constexpr uint32_t newLayerStack = 123u;
1710
1711 // --------------------------------------------------------------------
1712 // Preconditions
1713
1714 // A display is set up
1715 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1716 display.inject();
1717
1718 // There is a change to the layerStack state
1719 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
1720 display.mutableCurrentDisplayState().layerStack = newLayerStack;
1721
1722 // --------------------------------------------------------------------
1723 // Invocation
1724
1725 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1726
1727 // --------------------------------------------------------------------
1728 // Postconditions
1729
Lloyd Pique9d9cf402018-02-16 17:47:13 -08001730 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001731}
1732
1733TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
1734 using Case = NonHwcVirtualDisplayCase;
1735
1736 constexpr int oldTransform = 0;
1737 constexpr int newTransform = 2;
1738
1739 // --------------------------------------------------------------------
1740 // Preconditions
1741
1742 // A display is set up
1743 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1744 display.inject();
1745
1746 // There is a change to the orientation state
1747 display.mutableDrawingDisplayState().orientation = oldTransform;
1748 display.mutableCurrentDisplayState().orientation = newTransform;
1749
1750 // --------------------------------------------------------------------
1751 // Invocation
1752
1753 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1754
1755 // --------------------------------------------------------------------
1756 // Postconditions
1757
Lloyd Pique9d9cf402018-02-16 17:47:13 -08001758 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001759}
1760
1761TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
1762 using Case = NonHwcVirtualDisplayCase;
1763
1764 const Rect oldViewport(0, 0, 0, 0);
1765 const Rect newViewport(0, 0, 123, 456);
1766
1767 // --------------------------------------------------------------------
1768 // Preconditions
1769
1770 // A display is set up
1771 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1772 display.inject();
1773
1774 // There is a change to the viewport state
1775 display.mutableDrawingDisplayState().viewport = oldViewport;
1776 display.mutableCurrentDisplayState().viewport = newViewport;
1777
1778 // --------------------------------------------------------------------
1779 // Invocation
1780
1781 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1782
1783 // --------------------------------------------------------------------
1784 // Postconditions
1785
Lloyd Pique9d9cf402018-02-16 17:47:13 -08001786 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001787}
1788
1789TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
1790 using Case = NonHwcVirtualDisplayCase;
1791
1792 const Rect oldFrame(0, 0, 0, 0);
1793 const Rect newFrame(0, 0, 123, 456);
1794
1795 // --------------------------------------------------------------------
1796 // Preconditions
1797
1798 // A display is set up
1799 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1800 display.inject();
1801
1802 // There is a change to the viewport state
1803 display.mutableDrawingDisplayState().frame = oldFrame;
1804 display.mutableCurrentDisplayState().frame = newFrame;
1805
1806 // --------------------------------------------------------------------
1807 // Invocation
1808
1809 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1810
1811 // --------------------------------------------------------------------
1812 // Postconditions
1813
Lloyd Pique9d9cf402018-02-16 17:47:13 -08001814 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001815}
1816
1817TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
1818 using Case = NonHwcVirtualDisplayCase;
1819
1820 constexpr int oldWidth = 0;
1821 constexpr int oldHeight = 10;
1822 constexpr int newWidth = 123;
1823
1824 // --------------------------------------------------------------------
1825 // Preconditions
1826
1827 // A display is set up
1828 auto nativeWindow = new mock::NativeWindow();
1829 auto displaySurface = new mock::DisplaySurface();
Peiyong Lin833074a2018-08-28 11:53:54 -07001830 auto renderSurface = new renderengine::mock::Surface();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001831 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1832 display.setNativeWindow(nativeWindow);
1833 display.setDisplaySurface(displaySurface);
Peiyong Lin833074a2018-08-28 11:53:54 -07001834 display.setRenderSurface(std::unique_ptr<renderengine::Surface>(renderSurface));
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001835 display.inject();
1836
1837 // There is a change to the viewport state
1838 display.mutableDrawingDisplayState().width = oldWidth;
1839 display.mutableDrawingDisplayState().height = oldHeight;
1840 display.mutableCurrentDisplayState().width = newWidth;
1841 display.mutableCurrentDisplayState().height = oldHeight;
1842
1843 // --------------------------------------------------------------------
1844 // Call Expectations
1845
1846 EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
1847 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
1848 EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
Alec Mouri05483a02018-09-10 21:03:42 +00001849 EXPECT_CALL(*renderSurface, getWidth()).WillOnce(Return(newWidth));
1850 EXPECT_CALL(*renderSurface, getHeight()).WillOnce(Return(oldHeight));
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001851
1852 // --------------------------------------------------------------------
1853 // Invocation
1854
1855 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1856}
1857
1858TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
1859 using Case = NonHwcVirtualDisplayCase;
1860
1861 constexpr int oldWidth = 0;
1862 constexpr int oldHeight = 10;
1863 constexpr int newHeight = 123;
1864
1865 // --------------------------------------------------------------------
1866 // Preconditions
1867
1868 // A display is set up
1869 auto nativeWindow = new mock::NativeWindow();
1870 auto displaySurface = new mock::DisplaySurface();
Peiyong Lin833074a2018-08-28 11:53:54 -07001871 auto renderSurface = new renderengine::mock::Surface();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001872 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1873 display.setNativeWindow(nativeWindow);
1874 display.setDisplaySurface(displaySurface);
Peiyong Lin833074a2018-08-28 11:53:54 -07001875 display.setRenderSurface(std::unique_ptr<renderengine::Surface>(renderSurface));
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001876 display.inject();
1877
1878 // There is a change to the viewport state
1879 display.mutableDrawingDisplayState().width = oldWidth;
1880 display.mutableDrawingDisplayState().height = oldHeight;
1881 display.mutableCurrentDisplayState().width = oldWidth;
1882 display.mutableCurrentDisplayState().height = newHeight;
1883
1884 // --------------------------------------------------------------------
1885 // Call Expectations
1886
1887 EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
1888 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
1889 EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
Alec Mouri05483a02018-09-10 21:03:42 +00001890 EXPECT_CALL(*renderSurface, getWidth()).WillOnce(Return(oldWidth));
1891 EXPECT_CALL(*renderSurface, getHeight()).WillOnce(Return(newHeight));
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001892
1893 // --------------------------------------------------------------------
1894 // Invocation
1895
1896 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1897}
1898
Lloyd Pique9d9cf402018-02-16 17:47:13 -08001899/* ------------------------------------------------------------------------
1900 * SurfaceFlinger::setDisplayStateLocked
1901 */
1902
1903TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
1904 // --------------------------------------------------------------------
1905 // Preconditions
1906
1907 // We have an unknown display token not associated with a known display
1908 sp<BBinder> displayToken = new BBinder();
1909
1910 // The requested display state references the unknown display.
1911 DisplayState state;
1912 state.what = DisplayState::eLayerStackChanged;
1913 state.token = displayToken;
1914 state.layerStack = 456;
1915
1916 // --------------------------------------------------------------------
1917 // Invocation
1918
1919 uint32_t flags = mFlinger.setDisplayStateLocked(state);
1920
1921 // --------------------------------------------------------------------
1922 // Postconditions
1923
1924 // The returned flags are empty
1925 EXPECT_EQ(0u, flags);
1926
1927 // The display token still doesn't match anything known.
1928 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1929}
1930
Lloyd Pique9d9cf402018-02-16 17:47:13 -08001931TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
1932 using Case = SimplePrimaryDisplayCase;
1933
1934 // --------------------------------------------------------------------
1935 // Preconditions
1936
1937 // A display is already set up
1938 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1939 display.inject();
1940
1941 // No changes are made to the display
1942 DisplayState state;
1943 state.what = 0;
1944 state.token = display.token();
1945
1946 // --------------------------------------------------------------------
1947 // Invocation
1948
1949 uint32_t flags = mFlinger.setDisplayStateLocked(state);
1950
1951 // --------------------------------------------------------------------
1952 // Postconditions
1953
1954 // The returned flags are empty
1955 EXPECT_EQ(0u, flags);
1956}
1957
1958TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
1959 using Case = SimplePrimaryDisplayCase;
1960
1961 // --------------------------------------------------------------------
1962 // Preconditions
1963
1964 // A display is already set up
1965 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1966 display.inject();
1967
1968 // There is a surface that can be set.
1969 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
1970
1971 // The current display state has the surface set
1972 display.mutableCurrentDisplayState().surface = surface;
1973
1974 // The incoming request sets the same surface
1975 DisplayState state;
1976 state.what = DisplayState::eSurfaceChanged;
1977 state.token = display.token();
1978 state.surface = surface;
1979
1980 // --------------------------------------------------------------------
1981 // Invocation
1982
1983 uint32_t flags = mFlinger.setDisplayStateLocked(state);
1984
1985 // --------------------------------------------------------------------
1986 // Postconditions
1987
1988 // The returned flags are empty
1989 EXPECT_EQ(0u, flags);
1990
1991 // The current display state is unchanged.
1992 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
1993}
1994
1995TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
1996 using Case = SimplePrimaryDisplayCase;
1997
1998 // --------------------------------------------------------------------
1999 // Preconditions
2000
2001 // A display is already set up
2002 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2003 display.inject();
2004
2005 // There is a surface that can be set.
2006 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2007
2008 // The current display state does not have a surface
2009 display.mutableCurrentDisplayState().surface = nullptr;
2010
2011 // The incoming request sets a surface
2012 DisplayState state;
2013 state.what = DisplayState::eSurfaceChanged;
2014 state.token = display.token();
2015 state.surface = surface;
2016
2017 // --------------------------------------------------------------------
2018 // Invocation
2019
2020 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2021
2022 // --------------------------------------------------------------------
2023 // Postconditions
2024
2025 // The returned flags indicate a transaction is needed
2026 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2027
2028 // The current display layer stack state is set to the new value
2029 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2030}
2031
2032TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2033 using Case = SimplePrimaryDisplayCase;
2034
2035 // --------------------------------------------------------------------
2036 // Preconditions
2037
2038 // A display is already set up
2039 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2040 display.inject();
2041
2042 // The display has a layer stack set
2043 display.mutableCurrentDisplayState().layerStack = 456u;
2044
2045 // The incoming request sets the same layer stack
2046 DisplayState state;
2047 state.what = DisplayState::eLayerStackChanged;
2048 state.token = display.token();
2049 state.layerStack = 456u;
2050
2051 // --------------------------------------------------------------------
2052 // Invocation
2053
2054 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2055
2056 // --------------------------------------------------------------------
2057 // Postconditions
2058
2059 // The returned flags are empty
2060 EXPECT_EQ(0u, flags);
2061
2062 // The current display state is unchanged
2063 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2064}
2065
2066TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2067 using Case = SimplePrimaryDisplayCase;
2068
2069 // --------------------------------------------------------------------
2070 // Preconditions
2071
2072 // A display is set up
2073 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2074 display.inject();
2075
2076 // The display has a layer stack set
2077 display.mutableCurrentDisplayState().layerStack = 654u;
2078
2079 // The incoming request sets a different layer stack
2080 DisplayState state;
2081 state.what = DisplayState::eLayerStackChanged;
2082 state.token = display.token();
2083 state.layerStack = 456u;
2084
2085 // --------------------------------------------------------------------
2086 // Invocation
2087
2088 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2089
2090 // --------------------------------------------------------------------
2091 // Postconditions
2092
2093 // The returned flags indicate a transaction is needed
2094 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2095
2096 // The desired display state has been set to the new value.
2097 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2098}
2099
2100TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2101 using Case = SimplePrimaryDisplayCase;
2102 constexpr int initialOrientation = 180;
2103 const Rect initialFrame = {1, 2, 3, 4};
2104 const Rect initialViewport = {5, 6, 7, 8};
2105
2106 // --------------------------------------------------------------------
2107 // Preconditions
2108
2109 // A display is set up
2110 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2111 display.inject();
2112
2113 // The current display state projection state is all set
2114 display.mutableCurrentDisplayState().orientation = initialOrientation;
2115 display.mutableCurrentDisplayState().frame = initialFrame;
2116 display.mutableCurrentDisplayState().viewport = initialViewport;
2117
2118 // The incoming request sets the same projection state
2119 DisplayState state;
2120 state.what = DisplayState::eDisplayProjectionChanged;
2121 state.token = display.token();
2122 state.orientation = initialOrientation;
2123 state.frame = initialFrame;
2124 state.viewport = initialViewport;
2125
2126 // --------------------------------------------------------------------
2127 // Invocation
2128
2129 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2130
2131 // --------------------------------------------------------------------
2132 // Postconditions
2133
2134 // The returned flags are empty
2135 EXPECT_EQ(0u, flags);
2136
2137 // The current display state is unchanged
2138 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2139
2140 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2141 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2142}
2143
2144TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2145 using Case = SimplePrimaryDisplayCase;
2146 constexpr int initialOrientation = 90;
2147 constexpr int desiredOrientation = 180;
2148
2149 // --------------------------------------------------------------------
2150 // Preconditions
2151
2152 // A display is set up
2153 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2154 display.inject();
2155
2156 // The current display state has an orientation set
2157 display.mutableCurrentDisplayState().orientation = initialOrientation;
2158
2159 // The incoming request sets a different orientation
2160 DisplayState state;
2161 state.what = DisplayState::eDisplayProjectionChanged;
2162 state.token = display.token();
2163 state.orientation = desiredOrientation;
2164
2165 // --------------------------------------------------------------------
2166 // Invocation
2167
2168 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2169
2170 // --------------------------------------------------------------------
2171 // Postconditions
2172
2173 // The returned flags indicate a transaction is needed
2174 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2175
2176 // The current display state has the new value.
2177 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2178}
2179
2180TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2181 using Case = SimplePrimaryDisplayCase;
2182 const Rect initialFrame = {0, 0, 0, 0};
2183 const Rect desiredFrame = {5, 6, 7, 8};
2184
2185 // --------------------------------------------------------------------
2186 // Preconditions
2187
2188 // A display is set up
2189 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2190 display.inject();
2191
2192 // The current display state does not have a frame
2193 display.mutableCurrentDisplayState().frame = initialFrame;
2194
2195 // The incoming request sets a frame
2196 DisplayState state;
2197 state.what = DisplayState::eDisplayProjectionChanged;
2198 state.token = display.token();
2199 state.frame = desiredFrame;
2200
2201 // --------------------------------------------------------------------
2202 // Invocation
2203
2204 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2205
2206 // --------------------------------------------------------------------
2207 // Postconditions
2208
2209 // The returned flags indicate a transaction is needed
2210 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2211
2212 // The current display state has the new value.
2213 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2214}
2215
2216TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2217 using Case = SimplePrimaryDisplayCase;
2218 const Rect initialViewport = {0, 0, 0, 0};
2219 const Rect desiredViewport = {5, 6, 7, 8};
2220
2221 // --------------------------------------------------------------------
2222 // Preconditions
2223
2224 // A display is set up
2225 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2226 display.inject();
2227
2228 // The current display state does not have a viewport
2229 display.mutableCurrentDisplayState().viewport = initialViewport;
2230
2231 // The incoming request sets a viewport
2232 DisplayState state;
2233 state.what = DisplayState::eDisplayProjectionChanged;
2234 state.token = display.token();
2235 state.viewport = desiredViewport;
2236
2237 // --------------------------------------------------------------------
2238 // Invocation
2239
2240 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2241
2242 // --------------------------------------------------------------------
2243 // Postconditions
2244
2245 // The returned flags indicate a transaction is needed
2246 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2247
2248 // The current display state has the new value.
2249 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2250}
2251
2252TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2253 using Case = SimplePrimaryDisplayCase;
2254 constexpr uint32_t initialWidth = 1024;
2255 constexpr uint32_t initialHeight = 768;
2256
2257 // --------------------------------------------------------------------
2258 // Preconditions
2259
2260 // A display is set up
2261 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2262 display.inject();
2263
2264 // The current display state has a size set
2265 display.mutableCurrentDisplayState().width = initialWidth;
2266 display.mutableCurrentDisplayState().height = initialHeight;
2267
2268 // The incoming request sets the same display size
2269 DisplayState state;
2270 state.what = DisplayState::eDisplaySizeChanged;
2271 state.token = display.token();
2272 state.width = initialWidth;
2273 state.height = initialHeight;
2274
2275 // --------------------------------------------------------------------
2276 // Invocation
2277
2278 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2279
2280 // --------------------------------------------------------------------
2281 // Postconditions
2282
2283 // The returned flags are empty
2284 EXPECT_EQ(0u, flags);
2285
2286 // The current display state is unchanged
2287 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2288 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2289}
2290
2291TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2292 using Case = SimplePrimaryDisplayCase;
2293 constexpr uint32_t initialWidth = 0;
2294 constexpr uint32_t desiredWidth = 1024;
2295
2296 // --------------------------------------------------------------------
2297 // Preconditions
2298
2299 // A display is set up
2300 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2301 display.inject();
2302
2303 // The display does not yet have a width
2304 display.mutableCurrentDisplayState().width = initialWidth;
2305
2306 // The incoming request sets a display width
2307 DisplayState state;
2308 state.what = DisplayState::eDisplaySizeChanged;
2309 state.token = display.token();
2310 state.width = desiredWidth;
2311
2312 // --------------------------------------------------------------------
2313 // Invocation
2314
2315 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2316
2317 // --------------------------------------------------------------------
2318 // Postconditions
2319
2320 // The returned flags indicate a transaction is needed
2321 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2322
2323 // The current display state has the new value.
2324 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2325}
2326
2327TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2328 using Case = SimplePrimaryDisplayCase;
2329 constexpr uint32_t initialHeight = 0;
2330 constexpr uint32_t desiredHeight = 768;
2331
2332 // --------------------------------------------------------------------
2333 // Preconditions
2334
2335 // A display is set up
2336 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2337 display.inject();
2338
2339 // The display does not yet have a height
2340 display.mutableCurrentDisplayState().height = initialHeight;
2341
2342 // The incoming request sets a display height
2343 DisplayState state;
2344 state.what = DisplayState::eDisplaySizeChanged;
2345 state.token = display.token();
2346 state.height = desiredHeight;
2347
2348 // --------------------------------------------------------------------
2349 // Invocation
2350
2351 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2352
2353 // --------------------------------------------------------------------
2354 // Postconditions
2355
2356 // The returned flags indicate a transaction is needed
2357 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2358
2359 // The current display state has the new value.
2360 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2361}
2362
Lloyd Pique86016da2018-03-01 16:09:38 -08002363/* ------------------------------------------------------------------------
2364 * SurfaceFlinger::onInitializeDisplays
2365 */
2366
2367TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2368 using Case = SimplePrimaryDisplayCase;
2369
2370 // --------------------------------------------------------------------
2371 // Preconditions
2372
2373 // A primary display is set up
2374 Case::Display::injectHwcDisplay(this);
2375 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2376 primaryDisplay.inject();
2377
2378 // --------------------------------------------------------------------
2379 // Call Expectations
2380
2381 // We expect the surface interceptor to possibly be used, but we treat it as
2382 // disabled since it is called as a side effect rather than directly by this
2383 // function.
2384 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2385
2386 // We expect a call to get the active display config.
2387 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2388
2389 // We expect invalidate() to be invoked once to trigger display transaction
2390 // processing.
2391 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2392
2393 // --------------------------------------------------------------------
2394 // Invocation
2395
2396 mFlinger.onInitializeDisplays();
2397
2398 // --------------------------------------------------------------------
2399 // Postconditions
2400
2401 // The primary display should have a current state
2402 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2403 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2404 // The layer stack state should be set to zero
2405 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2406 // The orientation state should be set to zero
2407 EXPECT_EQ(0, primaryDisplayState.orientation);
2408
2409 // The frame state should be set to INVALID
2410 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2411
2412 // The viewport state should be set to INVALID
2413 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2414
2415 // The width and height should both be zero
2416 EXPECT_EQ(0u, primaryDisplayState.width);
2417 EXPECT_EQ(0u, primaryDisplayState.height);
2418
2419 // The display should be set to HWC_POWER_MODE_NORMAL
2420 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2421 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2422 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2423
2424 // The display refresh period should be set in the frame tracker.
2425 FrameStats stats;
2426 mFlinger.getAnimFrameTracker().getStats(&stats);
2427 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2428
2429 // The display transaction needed flag should be set.
2430 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2431
2432 // The compositor timing should be set to default values
2433 const auto& compositorTiming = mFlinger.getCompositorTiming();
2434 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2435 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2436 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2437}
2438
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002439/* ------------------------------------------------------------------------
2440 * SurfaceFlinger::setPowerModeInternal
2441 */
2442
2443// Used when we simulate a display that supports doze.
2444struct DozeIsSupportedVariant {
2445 static constexpr bool DOZE_SUPPORTED = true;
2446 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2447 IComposerClient::PowerMode::DOZE;
2448 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2449 IComposerClient::PowerMode::DOZE_SUSPEND;
2450};
2451
2452// Used when we simulate a display that does not support doze.
2453struct DozeNotSupportedVariant {
2454 static constexpr bool DOZE_SUPPORTED = false;
2455 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2456 IComposerClient::PowerMode::ON;
2457 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2458 IComposerClient::PowerMode::ON;
2459};
2460
2461struct EventThreadBaseSupportedVariant {
2462 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
2463 // The event control thread should not be notified.
2464 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
2465
2466 // The event thread should not be notified.
2467 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
2468 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
2469 }
2470};
2471
2472struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
2473 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2474 // These calls are only expected for the primary display.
2475
2476 // Instead expect no calls.
2477 setupEventAndEventControlThreadNoCallExpectations(test);
2478 }
2479
2480 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2481 // These calls are only expected for the primary display.
2482
2483 // Instead expect no calls.
2484 setupEventAndEventControlThreadNoCallExpectations(test);
2485 }
2486};
2487
2488struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
2489 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2490 // The event control thread should be notified to enable vsyncs
2491 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
2492
2493 // The event thread should be notified that the screen was acquired.
2494 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
2495 }
2496
2497 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2498 // There should be a call to setVsyncEnabled(false)
2499 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
2500
2501 // The event thread should not be notified that the screen was released.
2502 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
2503 }
2504};
2505
Lloyd Pique41be5d22018-06-21 13:11:48 -07002506struct DispSyncIsSupportedVariant {
2507 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
2508 EXPECT_CALL(*test->mPrimaryDispSync, reset()).Times(1);
2509 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
2510 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
2511 }
2512
2513 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
2514 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
2515 }
2516};
2517
2518struct DispSyncNotSupportedVariant {
2519 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2520
2521 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2522};
2523
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002524// --------------------------------------------------------------------
2525// Note:
2526//
2527// There are a large number of transitions we could test, however we only test a
2528// selected subset which provides complete test coverage of the implementation.
2529// --------------------------------------------------------------------
2530
2531template <int initialPowerMode, int targetPowerMode>
2532struct TransitionVariantCommon {
2533 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
2534 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
2535
2536 static void verifyPostconditions(DisplayTransactionTest*) {}
2537};
2538
2539struct TransitionOffToOnVariant
2540 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
2541 template <typename Case>
2542 static void setupCallExpectations(DisplayTransactionTest* test) {
2543 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2544 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002545 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002546 Case::setupRepaintEverythingCallExpectations(test);
2547 }
2548
2549 static void verifyPostconditions(DisplayTransactionTest* test) {
2550 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2551 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2552 }
2553};
2554
2555struct TransitionOffToDozeSuspendVariant
2556 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
2557 template <typename Case>
2558 static void setupCallExpectations(DisplayTransactionTest* test) {
2559 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2560 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2561 Case::setupRepaintEverythingCallExpectations(test);
2562 }
2563
2564 static void verifyPostconditions(DisplayTransactionTest* test) {
2565 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2566 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2567 }
2568};
2569
2570struct TransitionOnToOffVariant
2571 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
2572 template <typename Case>
2573 static void setupCallExpectations(DisplayTransactionTest* test) {
2574 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002575 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002576 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2577 }
2578
2579 static void verifyPostconditions(DisplayTransactionTest* test) {
2580 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2581 }
2582};
2583
2584struct TransitionDozeSuspendToOffVariant
2585 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
2586 template <typename Case>
2587 static void setupCallExpectations(DisplayTransactionTest* test) {
2588 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2589 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2590 }
2591
2592 static void verifyPostconditions(DisplayTransactionTest* test) {
2593 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2594 }
2595};
2596
2597struct TransitionOnToDozeVariant
2598 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
2599 template <typename Case>
2600 static void setupCallExpectations(DisplayTransactionTest* test) {
2601 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2602 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2603 }
2604};
2605
2606struct TransitionDozeSuspendToDozeVariant
2607 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
2608 template <typename Case>
2609 static void setupCallExpectations(DisplayTransactionTest* test) {
2610 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002611 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002612 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2613 }
2614};
2615
2616struct TransitionDozeToOnVariant
2617 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
2618 template <typename Case>
2619 static void setupCallExpectations(DisplayTransactionTest* test) {
2620 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2621 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2622 }
2623};
2624
2625struct TransitionDozeSuspendToOnVariant
2626 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
2627 template <typename Case>
2628 static void setupCallExpectations(DisplayTransactionTest* test) {
2629 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002630 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002631 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2632 }
2633};
2634
2635struct TransitionOnToDozeSuspendVariant
2636 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
2637 template <typename Case>
2638 static void setupCallExpectations(DisplayTransactionTest* test) {
2639 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002640 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002641 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2642 }
2643};
2644
2645struct TransitionOnToUnknownVariant
2646 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
2647 template <typename Case>
2648 static void setupCallExpectations(DisplayTransactionTest* test) {
2649 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2650 Case::setupNoComposerPowerModeCallExpectations(test);
2651 }
2652};
2653
2654// --------------------------------------------------------------------
2655// Note:
2656//
2657// Rather than testing the cartesian product of of
2658// DozeIsSupported/DozeNotSupported with all other options, we use one for one
2659// display type, and the other for another display type.
2660// --------------------------------------------------------------------
2661
2662template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07002663 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002664struct DisplayPowerCase {
2665 using Display = DisplayVariant;
2666 using Doze = DozeVariant;
2667 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07002668 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002669 using Transition = TransitionVariant;
2670
2671 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
2672 Display::injectHwcDisplay(test);
2673 auto display = Display::makeFakeExistingDisplayInjector(test);
2674 display.inject();
2675 display.mutableDisplayDevice()->setPowerMode(mode);
2676 return display;
2677 }
2678
2679 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
2680 test->mFlinger.mutablePrimaryHWVsyncEnabled() = enabled;
2681 }
2682
2683 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
2684 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
2685 }
2686
2687 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
2688 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
2689 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
2690 }
2691
2692 static void setupComposerCallExpectations(DisplayTransactionTest* test,
2693 IComposerClient::PowerMode mode) {
2694 // Any calls to get the active config will return a default value.
2695 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
2696 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
2697 Return(Error::NONE)));
2698
2699 // Any calls to get whether the display supports dozing will return the value set by the
2700 // policy variant.
2701 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
2702 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
2703
2704 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
2705 }
2706
2707 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
2708 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
2709 }
2710};
2711
2712// A sample configuration for the primary display.
2713// In addition to having event thread support, we emulate doze support.
2714template <typename TransitionVariant>
2715using PrimaryDisplayPowerCase = DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07002716 EventThreadIsSupportedVariant,
2717 DispSyncIsSupportedVariant, TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002718
2719// A sample configuration for the external display.
2720// In addition to not having event thread support, we emulate not having doze
2721// support.
2722template <typename TransitionVariant>
Lloyd Pique41be5d22018-06-21 13:11:48 -07002723using ExternalDisplayPowerCase = DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant,
2724 EventThreadNotSupportedVariant,
2725 DispSyncNotSupportedVariant, TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002726
2727class SetPowerModeInternalTest : public DisplayTransactionTest {
2728public:
2729 template <typename Case>
2730 void transitionDisplayCommon();
2731};
2732
2733template <int PowerMode>
2734struct PowerModeInitialVSyncEnabled : public std::false_type {};
2735
2736template <>
2737struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
2738
2739template <>
2740struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
2741
2742template <typename Case>
2743void SetPowerModeInternalTest::transitionDisplayCommon() {
2744 // --------------------------------------------------------------------
2745 // Preconditions
2746
2747 auto display =
2748 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
2749 Case::setInitialPrimaryHWVsyncEnabled(this,
2750 PowerModeInitialVSyncEnabled<
2751 Case::Transition::INITIAL_POWER_MODE>::value);
2752
2753 // --------------------------------------------------------------------
2754 // Call Expectations
2755
2756 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
2757 Case::Transition::template setupCallExpectations<Case>(this);
2758
2759 // --------------------------------------------------------------------
2760 // Invocation
2761
2762 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
2763 Case::Transition::TARGET_POWER_MODE);
2764
2765 // --------------------------------------------------------------------
2766 // Postconditions
2767
2768 Case::Transition::verifyPostconditions(this);
2769}
2770
2771TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
2772 using Case = SimplePrimaryDisplayCase;
2773
2774 // --------------------------------------------------------------------
2775 // Preconditions
2776
2777 // A primary display device is set up
2778 Case::Display::injectHwcDisplay(this);
2779 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2780 display.inject();
2781
Dominik Laskowskia2edf612018-06-01 13:15:16 -07002782 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002783 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
2784
2785 // --------------------------------------------------------------------
2786 // Invocation
2787
2788 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
2789
2790 // --------------------------------------------------------------------
2791 // Postconditions
2792
2793 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
2794}
2795
Dominik Laskowskieecd6592018-05-29 10:25:41 -07002796TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002797 using Case = HwcVirtualDisplayCase;
2798
2799 // --------------------------------------------------------------------
2800 // Preconditions
2801
2802 // We need to resize this so that the HWC thinks the virtual display
2803 // is something it created.
2804 mFlinger.mutableHwcDisplayData().resize(3);
2805
2806 // A virtual display device is set up
2807 Case::Display::injectHwcDisplay(this);
2808 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2809 display.inject();
2810
Dominik Laskowskieecd6592018-05-29 10:25:41 -07002811 // The display is set to HWC_POWER_MODE_NORMAL
2812 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002813
2814 // --------------------------------------------------------------------
2815 // Invocation
2816
Dominik Laskowskieecd6592018-05-29 10:25:41 -07002817 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002818
2819 // --------------------------------------------------------------------
2820 // Postconditions
2821
2822 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
2823}
2824
2825TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
2826 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
2827}
2828
2829TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
2830 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
2831}
2832
2833TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
2834 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
2835}
2836
2837TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
2838 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
2839}
2840
2841TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
2842 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
2843}
2844
2845TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
2846 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
2847}
2848
2849TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
2850 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
2851}
2852
2853TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
2854 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
2855}
2856
2857TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
2858 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
2859}
2860
2861TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
2862 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
2863}
2864
2865TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
2866 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
2867}
2868
2869TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
2870 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
2871}
2872
2873TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
2874 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
2875}
2876
2877TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
2878 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
2879}
2880
2881TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
2882 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
2883}
2884
2885TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
2886 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
2887}
2888
2889TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
2890 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
2891}
2892
2893TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
2894 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
2895}
2896
2897TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
2898 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
2899}
2900
2901TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
2902 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
2903}
2904
Lloyd Piquef58625d2017-12-19 13:22:33 -08002905} // namespace
2906} // namespace android