blob: 4cb79ab49560607a1e03b6bab42958bf7e3ac410 [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
Dominik Laskowski075d3172018-05-24 15:50:06 -070020#include <type_traits>
21
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070022#include <compositionengine/Display.h>
23#include <compositionengine/DisplayColorProfile.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070024#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080025#include <gmock/gmock.h>
26#include <gtest/gtest.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080027#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070028#include <renderengine/mock/RenderEngine.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070029#include <ui/DebugUtils.h>
Dominik Laskowski075d3172018-05-24 15:50:06 -070030
31#include "DisplayIdentificationTest.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080032#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080033#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070034#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080035#include "mock/MockEventControlThread.h"
36#include "mock/MockEventThread.h"
37#include "mock/MockMessageQueue.h"
38#include "mock/MockNativeWindowSurface.h"
39#include "mock/MockSurfaceInterceptor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080040#include "mock/gui/MockGraphicBufferConsumer.h"
41#include "mock/gui/MockGraphicBufferProducer.h"
42#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080043
44namespace android {
45namespace {
46
Lloyd Piquee39cad22017-12-20 17:01:29 -080047using testing::_;
48using testing::ByMove;
49using testing::DoAll;
50using testing::Mock;
51using testing::Return;
52using testing::SetArgPointee;
53
Lloyd Piqued883d5a2018-04-27 19:32:30 -070054using android::Hwc2::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080055using android::Hwc2::Error;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070056using android::Hwc2::Hdr;
Lloyd Piquee39cad22017-12-20 17:01:29 -080057using android::Hwc2::IComposer;
58using android::Hwc2::IComposerClient;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070059using android::Hwc2::PerFrameMetadataKey;
60using android::Hwc2::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080061
Lloyd Piquec11e0d32018-01-22 18:44:59 -080062using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
63using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080064using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080065using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080066
Lloyd Piquec11e0d32018-01-22 18:44:59 -080067constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080068constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080069constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080070
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080071constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value
72
Lloyd Piquec11e0d32018-01-22 18:44:59 -080073/* ------------------------------------------------------------------------
74 * Boolean avoidance
75 *
76 * To make calls and template instantiations more readable, we define some
77 * local enums along with an implicit bool conversion.
78 */
79
80#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
81
Lloyd Piquec11e0d32018-01-22 18:44:59 -080082BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -070083BOOL_SUBSTITUTE(Critical);
84BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080085BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -070086BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080087
88/* ------------------------------------------------------------------------
89 *
90 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080091
Lloyd Piquef58625d2017-12-19 13:22:33 -080092class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -080093public:
Lloyd Piquef58625d2017-12-19 13:22:33 -080094 DisplayTransactionTest();
95 ~DisplayTransactionTest() override;
96
Lloyd Pique1fa4d462018-01-22 18:03:16 -080097 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -080098 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -080099
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800100 void injectMockComposer(int virtualDisplayCount);
101 void injectFakeBufferQueueFactory();
102 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800103
104 // --------------------------------------------------------------------
105 // Postcondition helpers
106
Dominik Laskowski075d3172018-05-24 15:50:06 -0700107 bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800108 bool hasTransactionFlagSet(int flag);
109 bool hasDisplayDevice(sp<IBinder> displayToken);
110 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
111 bool hasCurrentDisplayState(sp<IBinder> displayToken);
112 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
113 bool hasDrawingDisplayState(sp<IBinder> displayToken);
114 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
115
116 // --------------------------------------------------------------------
117 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800118
Lloyd Piquef58625d2017-12-19 13:22:33 -0800119 TestableSurfaceFlinger mFlinger;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800120 mock::EventThread* mEventThread = new mock::EventThread();
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800121 mock::EventThread* mSFEventThread = new mock::EventThread();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800122 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
Alec Mouriba013fa2018-10-16 12:43:11 -0700123 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800124 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800125
126 // These mocks are created by the test, but are destroyed by SurfaceFlinger
127 // by virtue of being stored into a std::unique_ptr. However we still need
128 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700129 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800130 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800131 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
132 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Lloyd Pique41be5d22018-06-21 13:11:48 -0700133 mock::DispSync* mPrimaryDispSync = new mock::DispSync();
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800134
135 // These mocks are created only when expected to be created via a factory.
136 sp<mock::GraphicBufferConsumer> mConsumer;
137 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700138 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800139};
140
141DisplayTransactionTest::DisplayTransactionTest() {
142 const ::testing::TestInfo* const test_info =
143 ::testing::UnitTest::GetInstance()->current_test_info();
144 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800145
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800146 // Default to no wide color display support configured
147 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700148 mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800149 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
150
151 // Default to using HWC virtual displays
152 mFlinger.mutableUseHwcVirtualDisplays() = true;
153
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800154 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
155 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
156 });
157
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800158 mFlinger.setCreateNativeWindowSurface([](auto) {
159 ADD_FAILURE() << "Unexpected request to create a native window surface.";
160 return nullptr;
161 });
162
163 mFlinger.mutableEventControlThread().reset(mEventControlThread);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800164 mFlinger.mutableEventThread().reset(mEventThread);
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800165 mFlinger.mutableSFEventThread().reset(mSFEventThread);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800166 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700167 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800168 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Pique41be5d22018-06-21 13:11:48 -0700169 mFlinger.mutablePrimaryDispSync().reset(mPrimaryDispSync);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800170
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800171 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800172}
173
174DisplayTransactionTest::~DisplayTransactionTest() {
175 const ::testing::TestInfo* const test_info =
176 ::testing::UnitTest::GetInstance()->current_test_info();
177 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
178}
179
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800180void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
181 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800182 EXPECT_CALL(*mComposer, getCapabilities())
183 .WillOnce(Return(std::vector<IComposer::Capability>()));
184 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
185 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800186
Lloyd Piquee39cad22017-12-20 17:01:29 -0800187 Mock::VerifyAndClear(mComposer);
188}
189
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800190void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800191 // This setup is only expected once per test.
192 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
193
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800194 mConsumer = new mock::GraphicBufferConsumer();
195 mProducer = new mock::GraphicBufferProducer();
196
197 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
198 *outProducer = mProducer;
199 *outConsumer = mConsumer;
200 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800201}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800202
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800203void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800204 // This setup is only expected once per test.
205 ASSERT_TRUE(mNativeWindowSurface == nullptr);
206
Lloyd Pique22098362018-09-13 11:46:49 -0700207 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800208
Lloyd Pique22098362018-09-13 11:46:49 -0700209 mFlinger.setCreateNativeWindowSurface([this](auto) {
210 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
211 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800212}
213
Dominik Laskowski075d3172018-05-24 15:50:06 -0700214bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) {
215 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800216}
217
218bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
219 return mFlinger.mutableTransactionFlags() & flag;
220}
221
222bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700223 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800224}
225
226sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700227 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800228}
229
230bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
231 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
232}
233
234const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
235 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
236}
237
238bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
239 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
240}
241
242const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
243 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
244}
245
246/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800247 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800248 */
249
Dominik Laskowski075d3172018-05-24 15:50:06 -0700250template <typename PhysicalDisplay>
251struct PhysicalDisplayId {};
252
Dominik Laskowski34157762018-10-31 13:07:19 -0700253template <DisplayId::Type displayId>
254using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700255
256struct NoDisplayId {};
257
258template <typename>
259struct IsPhysicalDisplayId : std::bool_constant<false> {};
260
261template <typename PhysicalDisplay>
262struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
263
264template <typename>
265struct DisplayIdGetter;
266
267template <typename PhysicalDisplay>
268struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
269 static std::optional<DisplayId> get() {
270 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
271 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
272 ? HWC_DISPLAY_PRIMARY
273 : HWC_DISPLAY_EXTERNAL);
274 }
275
276 const auto info =
277 parseDisplayIdentificationData(PhysicalDisplay::PORT,
278 PhysicalDisplay::GET_IDENTIFICATION_DATA());
279 return info ? std::make_optional(info->id) : std::nullopt;
280 }
281};
282
Dominik Laskowski34157762018-10-31 13:07:19 -0700283template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700284struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700285 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700286};
287
288template <>
289struct DisplayIdGetter<NoDisplayId> {
290 static std::optional<DisplayId> get() { return {}; }
291};
292
293// DisplayIdType can be:
294// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
295// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
296// 3) NoDisplayId for virtual display without HWC backing.
297template <typename DisplayIdType, int width, int height, Critical critical, Async async,
298 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800299struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700300 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
301
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800302 // The display width and height
303 static constexpr int WIDTH = width;
304 static constexpr int HEIGHT = height;
305
306 static constexpr int GRALLOC_USAGE = grallocUsage;
307
Dominik Laskowski075d3172018-05-24 15:50:06 -0700308 // Whether the display is virtual or physical
309 static constexpr Virtual VIRTUAL =
310 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800311
312 // When creating native window surfaces for the framebuffer, whether those should be critical
313 static constexpr Critical CRITICAL = critical;
314
315 // When creating native window surfaces for the framebuffer, whether those should be async
316 static constexpr Async ASYNC = async;
317
318 // Whether the display should be treated as secure
319 static constexpr Secure SECURE = secure;
320
Dominik Laskowski075d3172018-05-24 15:50:06 -0700321 // Whether the display is primary
322 static constexpr Primary PRIMARY = primary;
323
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800324 static constexpr auto displayType() {
325 return static_cast<bool>(PRIMARY) ? EventThread::DisplayType::Primary
326 : EventThread::DisplayType::External;
327 }
328
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800329 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700330 auto injector =
331 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(),
332 static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY));
333
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800334 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700335 injector.setNativeWindow(test->mNativeWindow);
336
337 // Creating a DisplayDevice requires getting default dimensions from the
338 // native window.
339 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
340 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
341 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
342 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800343 return injector;
344 }
345
346 // Called by tests to set up any native window creation call expectations.
347 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
348 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
349 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800350
Alec Mouriba013fa2018-10-16 12:43:11 -0700351 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
352 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
353 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
354 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800355 }
356
357 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
358 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
359 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
360 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
361 .WillRepeatedly(Return(NO_ERROR));
362 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
363 .WillRepeatedly(Return(NO_ERROR));
364 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
365 .WillRepeatedly(Return(NO_ERROR));
366 }
367
368 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
369 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
370 }
371};
372
Dominik Laskowski075d3172018-05-24 15:50:06 -0700373template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
374 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800375struct HwcDisplayVariant {
376 // The display id supplied by the HWC
377 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
378
379 // The HWC display type
380 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
381
382 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700383 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800384
385 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
386 HWC2::Connection connection) {
387 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
388 HotplugEvent{HWC_DISPLAY_ID, connection});
389 }
390
391 // Called by tests to inject a HWC display setup
392 static void injectHwcDisplay(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700393 const auto displayId = DisplayVariant::DISPLAY_ID::get();
394 ASSERT_TRUE(displayId);
395 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
396 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800397 .setHwcDisplayId(HWC_DISPLAY_ID)
398 .setWidth(DisplayVariant::WIDTH)
399 .setHeight(DisplayVariant::HEIGHT)
400 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
401 .inject(&test->mFlinger, test->mComposer);
402 }
403
404 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
405 EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _))
406 .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>(
407 HWC_DISPLAY_TYPE)),
408 Return(Error::NONE)));
409 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
410 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
411 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
412 Return(Error::NONE)));
413 EXPECT_CALL(*test->mComposer,
414 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
415 IComposerClient::Attribute::WIDTH, _))
416 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
417 EXPECT_CALL(*test->mComposer,
418 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
419 IComposerClient::Attribute::HEIGHT, _))
420 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
421 EXPECT_CALL(*test->mComposer,
422 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
423 IComposerClient::Attribute::VSYNC_PERIOD, _))
424 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
425 EXPECT_CALL(*test->mComposer,
426 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
427 IComposerClient::Attribute::DPI_X, _))
428 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
429 EXPECT_CALL(*test->mComposer,
430 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
431 IComposerClient::Attribute::DPI_Y, _))
432 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700433
434 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
435 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
436 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
437 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
438 Return(Error::NONE)));
439 } else {
440 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
441 .WillOnce(Return(Error::UNSUPPORTED));
442 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800443 }
444
445 // Called by tests to set up HWC call expectations
446 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
447 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700448 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800449 }
450};
451
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800452// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
453constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
454 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
455
Dominik Laskowski075d3172018-05-24 15:50:06 -0700456template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800457 Critical critical>
458struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700459 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
460 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
461 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
462 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
463 critical, Async::FALSE, Secure::TRUE,
464 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
465 PhysicalDisplay> {};
466
467template <bool hasIdentificationData>
468struct PrimaryDisplay {
469 static constexpr Primary PRIMARY = Primary::TRUE;
470 static constexpr uint8_t PORT = 255;
471 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
472 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
473};
474
475template <bool hasIdentificationData>
476struct ExternalDisplay {
477 static constexpr Primary PRIMARY = Primary::FALSE;
478 static constexpr uint8_t PORT = 254;
479 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
480 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
481};
482
483struct TertiaryDisplay {
484 static constexpr Primary PRIMARY = Primary::FALSE;
485};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800486
487// A primary display is a physical display that is critical
488using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700489 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800490
491// An external display is physical display that is not critical.
492using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700493 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800494
495using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700496 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800497
498// A virtual display not supported by the HWC.
499constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
500
501template <int width, int height, Secure secure>
502struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700503 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
504 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
505 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
506 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
507
508 static void injectHwcDisplay(DisplayTransactionTest*) {}
509
510 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
511 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
512 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800513
514 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
515 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
516 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
517 }
518};
519
520// A virtual display supported by the HWC.
521constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
522
523template <int width, int height, Secure secure>
524struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700525 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
526 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
527 HwcDisplayVariant<
528 1010, HWC2::DisplayType::Virtual,
529 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
530 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
531 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
532 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800533 using Self = HwcVirtualDisplayVariant<width, height, secure>;
534
535 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
536 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
537 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
538 }
539
540 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
541 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
542 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
543 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
544 }
545};
546
547// For this variant, SurfaceFlinger should not configure itself with wide
548// display support, so the display should not be configured for wide-color
549// support.
550struct WideColorSupportNotConfiguredVariant {
551 static constexpr bool WIDE_COLOR_SUPPORTED = false;
552
553 static void injectConfigChange(DisplayTransactionTest* test) {
554 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700555 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800556 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
557 }
558
559 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
560 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
561 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
562 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
563 }
564};
565
566// For this variant, SurfaceFlinger should configure itself with wide display
567// support, and the display should respond with an non-empty list of supported
568// color modes. Wide-color support should be configured.
569template <typename Display>
570struct WideColorP3ColorimetricSupportedVariant {
571 static constexpr bool WIDE_COLOR_SUPPORTED = true;
572
573 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700574 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800575 test->mFlinger.mutableHasWideColorDisplay() = true;
576 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
577 }
578
579 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
580 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
581 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
582 Return(Error::NONE)));
583 EXPECT_CALL(*test->mComposer,
584 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
585 .WillOnce(DoAll(SetArgPointee<2>(
586 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
587 Return(Error::NONE)));
588 EXPECT_CALL(*test->mComposer,
589 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
590 RenderIntent::COLORIMETRIC))
591 .WillOnce(Return(Error::NONE));
592 }
593};
594
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800595// For this variant, SurfaceFlinger should configure itself with wide display
596// support, but the display should respond with an empty list of supported color
597// modes. Wide-color support for the display should not be configured.
598template <typename Display>
599struct WideColorNotSupportedVariant {
600 static constexpr bool WIDE_COLOR_SUPPORTED = false;
601
602 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700603 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800604 test->mFlinger.mutableHasWideColorDisplay() = true;
605 }
606
607 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
608 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
609 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700610 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800611 }
612};
613
614// For this variant, the display is not a HWC display, so no HDR support should
615// be configured.
616struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800617 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800618 static constexpr bool HDR10_SUPPORTED = false;
619 static constexpr bool HDR_HLG_SUPPORTED = false;
620 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
621 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
622 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
623 }
624};
625
Valerie Haue9e843a2018-12-18 13:39:23 -0800626template <typename Display>
627struct Hdr10PlusSupportedVariant {
628 static constexpr bool HDR10_PLUS_SUPPORTED = true;
629 static constexpr bool HDR10_SUPPORTED = true;
630 static constexpr bool HDR_HLG_SUPPORTED = false;
631 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
632 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
633 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
634 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
635 Hdr::HDR10_PLUS,
636 Hdr::HDR10,
637 })),
638 Return(Error::NONE)));
639 }
640};
641
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800642// For this variant, the composer should respond with a non-empty list of HDR
643// modes containing HDR10, so HDR10 support should be configured.
644template <typename Display>
645struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800646 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800647 static constexpr bool HDR10_SUPPORTED = true;
648 static constexpr bool HDR_HLG_SUPPORTED = false;
649 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
650 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
651 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
652 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
653 Return(Error::NONE)));
654 }
655};
656
657// For this variant, the composer should respond with a non-empty list of HDR
658// modes containing HLG, so HLG support should be configured.
659template <typename Display>
660struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800661 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800662 static constexpr bool HDR10_SUPPORTED = false;
663 static constexpr bool HDR_HLG_SUPPORTED = true;
664 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
665 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
666 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
667 .WillOnce(
668 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
669 }
670};
671
672// For this variant, the composer should respond with a non-empty list of HDR
673// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
674template <typename Display>
675struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800676 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800677 static constexpr bool HDR10_SUPPORTED = false;
678 static constexpr bool HDR_HLG_SUPPORTED = false;
679 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
680 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
681 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
682 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
683 Return(Error::NONE)));
684 }
685};
686
687// For this variant, the composer should respond with am empty list of HDR
688// modes, so no HDR support should be configured.
689template <typename Display>
690struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800691 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800692 static constexpr bool HDR10_SUPPORTED = false;
693 static constexpr bool HDR_HLG_SUPPORTED = false;
694 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
695 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
696 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
697 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
698 }
699};
700
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700701struct NonHwcPerFrameMetadataSupportVariant {
702 static constexpr int PER_FRAME_METADATA_KEYS = 0;
703 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800704 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700705 }
706};
707
708template <typename Display>
709struct NoPerFrameMetadataSupportVariant {
710 static constexpr int PER_FRAME_METADATA_KEYS = 0;
711 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800712 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
713 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700714 }
715};
716
717template <typename Display>
718struct Smpte2086PerFrameMetadataSupportVariant {
719 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
720 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800721 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
722 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800723 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
724 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
725 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
726 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
727 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
728 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
729 PerFrameMetadataKey::WHITE_POINT_X,
730 PerFrameMetadataKey::WHITE_POINT_Y,
731 PerFrameMetadataKey::MAX_LUMINANCE,
732 PerFrameMetadataKey::MIN_LUMINANCE,
733 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700734 }
735};
736
737template <typename Display>
738struct Cta861_3_PerFrameMetadataSupportVariant {
739 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
740 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800741 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
742 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800743 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
744 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
745 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700746 }
747};
748
Valerie Haue9e843a2018-12-18 13:39:23 -0800749template <typename Display>
750struct Hdr10_Plus_PerFrameMetadataSupportVariant {
751 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
752 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
753 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
754 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
755 PerFrameMetadataKey::HDR10_PLUS_SEI,
756 })));
757 }
758};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800759/* ------------------------------------------------------------------------
760 * Typical display configurations to test
761 */
762
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700763template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
764 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800765struct Case {
766 using Display = DisplayPolicy;
767 using WideColorSupport = WideColorSupportPolicy;
768 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700769 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800770};
771
772using SimplePrimaryDisplayCase =
773 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700774 HdrNotSupportedVariant<PrimaryDisplayVariant>,
775 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800776using SimpleExternalDisplayCase =
777 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700778 HdrNotSupportedVariant<ExternalDisplayVariant>,
779 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800780using SimpleTertiaryDisplayCase =
781 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700782 HdrNotSupportedVariant<TertiaryDisplayVariant>,
783 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800784using NonHwcVirtualDisplayCase =
785 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700786 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
787 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800788using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
789using HwcVirtualDisplayCase =
790 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700791 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800792 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800793using WideColorP3ColorimetricDisplayCase =
794 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700795 HdrNotSupportedVariant<PrimaryDisplayVariant>,
796 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800797using Hdr10PlusDisplayCase =
798 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
799 Hdr10SupportedVariant<PrimaryDisplayVariant>,
800 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800801using Hdr10DisplayCase =
802 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700803 Hdr10SupportedVariant<PrimaryDisplayVariant>,
804 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800805using HdrHlgDisplayCase =
806 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700807 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
808 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800809using HdrDolbyVisionDisplayCase =
810 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700811 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
812 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
813using HdrSmpte2086DisplayCase =
814 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
815 HdrNotSupportedVariant<PrimaryDisplayVariant>,
816 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
817using HdrCta861_3_DisplayCase =
818 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
819 HdrNotSupportedVariant<PrimaryDisplayVariant>,
820 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700821
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800822/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800823 *
824 * SurfaceFlinger::onHotplugReceived
825 */
826
827TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
828 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700829 constexpr hwc2_display_t hwcDisplayId1 = 456;
830 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800831
832 // --------------------------------------------------------------------
833 // Preconditions
834
835 // Set the current sequence id for accepted events
836 mFlinger.mutableComposerSequenceId() = currentSequenceId;
837
838 // Set the main thread id so that the current thread does not appear to be
839 // the main thread.
840 mFlinger.mutableMainThreadId() = std::thread::id();
841
842 // --------------------------------------------------------------------
843 // Call Expectations
844
845 // We expect invalidate() to be invoked once to trigger display transaction
846 // processing.
847 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
848
849 // --------------------------------------------------------------------
850 // Invocation
851
852 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700853 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
854 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800855
856 // --------------------------------------------------------------------
857 // Postconditions
858
859 // The display transaction needed flag should be set.
860 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
861
862 // All events should be in the pending event queue.
863 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
864 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700865 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800866 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700867 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800868 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
869}
870
871TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
872 constexpr int currentSequenceId = 123;
873 constexpr int otherSequenceId = 321;
874 constexpr hwc2_display_t displayId = 456;
875
876 // --------------------------------------------------------------------
877 // Preconditions
878
879 // Set the current sequence id for accepted events
880 mFlinger.mutableComposerSequenceId() = currentSequenceId;
881
882 // Set the main thread id so that the current thread does not appear to be
883 // the main thread.
884 mFlinger.mutableMainThreadId() = std::thread::id();
885
886 // --------------------------------------------------------------------
887 // Call Expectations
888
889 // We do not expect any calls to invalidate().
890 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
891
892 // --------------------------------------------------------------------
893 // Invocation
894
895 // Call with an unexpected sequence id
896 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
897
898 // --------------------------------------------------------------------
899 // Postconditions
900
901 // The display transaction needed flag should not be set
902 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
903
904 // There should be no pending events
905 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
906}
907
908TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
909 constexpr int currentSequenceId = 123;
910 constexpr hwc2_display_t displayId1 = 456;
911
912 // --------------------------------------------------------------------
913 // Note:
914 // --------------------------------------------------------------------
915 // This test case is a bit tricky. We want to verify that
916 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
917 // don't really want to provide coverage for everything the later function
918 // does as there are specific tests for it.
919 // --------------------------------------------------------------------
920
921 // --------------------------------------------------------------------
922 // Preconditions
923
924 // Set the current sequence id for accepted events
925 mFlinger.mutableComposerSequenceId() = currentSequenceId;
926
927 // Set the main thread id so that the current thread does appear to be the
928 // main thread.
929 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
930
931 // --------------------------------------------------------------------
932 // Call Expectations
933
934 // We expect invalidate() to be invoked once to trigger display transaction
935 // processing.
936 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
937
938 // --------------------------------------------------------------------
939 // Invocation
940
941 // Simulate a disconnect on a display id that is not connected. This should
942 // be enqueued by onHotplugReceived(), and dequeued by
943 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
944 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
945
946 // --------------------------------------------------------------------
947 // Postconditions
948
949 // The display transaction needed flag should be set.
950 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
951
952 // There should be no event queued on return, as it should have been
953 // processed.
954 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
955}
956
957/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -0800958 * SurfaceFlinger::createDisplay
959 */
960
961TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
962 const String8 name("virtual.test");
963
964 // --------------------------------------------------------------------
965 // Call Expectations
966
967 // The call should notify the interceptor that a display was created.
968 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
969
970 // --------------------------------------------------------------------
971 // Invocation
972
973 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
974
975 // --------------------------------------------------------------------
976 // Postconditions
977
978 // The display should have been added to the current state
979 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
980 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700981 EXPECT_TRUE(display.isVirtual());
982 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -0800983 EXPECT_EQ(name.string(), display.displayName);
984
985 // --------------------------------------------------------------------
986 // Cleanup conditions
987
988 // Destroying the display invalidates the display state.
989 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
990}
991
992TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
993 const String8 name("virtual.test");
994
995 // --------------------------------------------------------------------
996 // Call Expectations
997
998 // The call should notify the interceptor that a display was created.
999 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1000
1001 // --------------------------------------------------------------------
1002 // Invocation
1003
1004 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1005
1006 // --------------------------------------------------------------------
1007 // Postconditions
1008
1009 // The display should have been added to the current state
1010 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1011 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001012 EXPECT_TRUE(display.isVirtual());
1013 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001014 EXPECT_EQ(name.string(), display.displayName);
1015
1016 // --------------------------------------------------------------------
1017 // Cleanup conditions
1018
1019 // Destroying the display invalidates the display state.
1020 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1021}
1022
1023/* ------------------------------------------------------------------------
1024 * SurfaceFlinger::destroyDisplay
1025 */
1026
1027TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1028 using Case = NonHwcVirtualDisplayCase;
1029
1030 // --------------------------------------------------------------------
1031 // Preconditions
1032
1033 // A virtual display exists
1034 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1035 existing.inject();
1036
1037 // --------------------------------------------------------------------
1038 // Call Expectations
1039
1040 // The call should notify the interceptor that a display was created.
1041 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1042
1043 // Destroying the display invalidates the display state.
1044 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1045
1046 // --------------------------------------------------------------------
1047 // Invocation
1048
1049 mFlinger.destroyDisplay(existing.token());
1050
1051 // --------------------------------------------------------------------
1052 // Postconditions
1053
1054 // The display should have been removed from the current state
1055 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1056
1057 // Ths display should still exist in the drawing state
1058 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1059
1060 // The display transaction needed flasg should be set
1061 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1062}
1063
1064TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1065 // --------------------------------------------------------------------
1066 // Preconditions
1067
1068 sp<BBinder> displayToken = new BBinder();
1069
1070 // --------------------------------------------------------------------
1071 // Invocation
1072
1073 mFlinger.destroyDisplay(displayToken);
1074}
1075
1076/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001077 * SurfaceFlinger::resetDisplayState
1078 */
1079
1080TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1081 using Case = NonHwcVirtualDisplayCase;
1082
1083 // --------------------------------------------------------------------
1084 // Preconditions
1085
1086 // vsync is enabled and available
1087 mFlinger.mutablePrimaryHWVsyncEnabled() = true;
1088 mFlinger.mutableHWVsyncAvailable() = true;
1089
1090 // A display exists
1091 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1092 existing.inject();
1093
1094 // --------------------------------------------------------------------
1095 // Call Expectations
1096
1097 // The call disable vsyncs
1098 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1099
Lloyd Pique41be5d22018-06-21 13:11:48 -07001100 // The call ends any display resyncs
1101 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1102
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001103 // --------------------------------------------------------------------
1104 // Invocation
1105
1106 mFlinger.resetDisplayState();
1107
1108 // --------------------------------------------------------------------
1109 // Postconditions
1110
1111 // vsyncs should be off and not available.
1112 EXPECT_FALSE(mFlinger.mutablePrimaryHWVsyncEnabled());
1113 EXPECT_FALSE(mFlinger.mutableHWVsyncAvailable());
1114
1115 // The display should have been removed from the display map.
1116 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1117
1118 // The display should still exist in the current state
1119 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1120
1121 // The display should have been removed from the drawing state
1122 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1123}
1124
1125/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001126 * DisplayDevice::GetBestColorMode
1127 */
1128class GetBestColorModeTest : public DisplayTransactionTest {
1129public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001130 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001131
Valerie Hau9758ae02018-10-09 16:05:09 -07001132 GetBestColorModeTest()
1133 : DisplayTransactionTest(),
Dominik Laskowski075d3172018-05-24 15:50:06 -07001134 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */,
1135 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001136
1137 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1138
1139 void addHwcColorModesMapping(ui::ColorMode colorMode,
1140 std::vector<ui::RenderIntent> renderIntents) {
1141 mHwcColorModes[colorMode] = renderIntents;
1142 }
1143
1144 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1145
1146 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1147
1148 void getBestColorMode() {
1149 mInjector.setHwcColorModes(mHwcColorModes);
1150 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001151 mInjector.setNativeWindow(mNativeWindow);
1152
1153 // Creating a DisplayDevice requires getting default dimensions from the
1154 // native window.
1155 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1156 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1157 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1158 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Alec Mouri4efb6c22018-11-16 13:07:47 -08001159 EXPECT_CALL(*mNativeWindow, perform(9)).Times(1);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08001160 EXPECT_CALL(*mNativeWindow, perform(13)).Times(1);
Alec Mouri4efb6c22018-11-16 13:07:47 -08001161 EXPECT_CALL(*mNativeWindow, perform(30)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001162 auto displayDevice = mInjector.inject();
1163
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001164 displayDevice->getCompositionDisplay()
1165 ->getDisplayColorProfile()
1166 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1167 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001168 }
1169
1170 ui::Dataspace mOutDataspace;
1171 ui::ColorMode mOutColorMode;
1172 ui::RenderIntent mOutRenderIntent;
1173
1174private:
1175 ui::Dataspace mInputDataspace;
1176 ui::RenderIntent mInputRenderIntent;
1177 bool mHasWideColorGamut = false;
1178 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1179 FakeDisplayDeviceInjector mInjector;
1180};
1181
1182TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1183 addHwcColorModesMapping(ui::ColorMode::SRGB,
1184 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1185 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1186 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1187 setHasWideColorGamut(true);
1188
1189 getBestColorMode();
1190
Peiyong Lin14724e62018-12-05 07:27:30 -08001191 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001192 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1193 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1194}
1195
1196TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1197 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1198 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1199 addHwcColorModesMapping(ui::ColorMode::SRGB,
1200 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1201 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1202 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1203 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1204 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1205 setHasWideColorGamut(true);
1206
1207 getBestColorMode();
1208
1209 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1210 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1211 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1212}
1213
1214TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1215 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1216 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1217 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1218 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1219 setHasWideColorGamut(true);
1220
1221 getBestColorMode();
1222
1223 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1224 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1225 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1226}
1227
1228/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001229 * SurfaceFlinger::getDisplayNativePrimaries
1230 */
1231
1232class GetDisplayNativePrimaries : public DisplayTransactionTest {
1233public:
1234 GetDisplayNativePrimaries();
1235 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1236 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1237
1238private:
1239 static constexpr float mStartingTestValue = 1.0f;
1240};
1241
1242GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1243 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1244 injectFakeNativeWindowSurfaceFactory();
1245}
1246
1247void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1248 ui::DisplayPrimaries& primaries) {
1249 float startingVal = mStartingTestValue;
1250 primaries.red.X = startingVal++;
1251 primaries.red.Y = startingVal++;
1252 primaries.red.Z = startingVal++;
1253 primaries.green.X = startingVal++;
1254 primaries.green.Y = startingVal++;
1255 primaries.green.Z = startingVal++;
1256 primaries.blue.X = startingVal++;
1257 primaries.blue.Y = startingVal++;
1258 primaries.blue.Z = startingVal++;
1259 primaries.white.X = startingVal++;
1260 primaries.white.Y = startingVal++;
1261 primaries.white.Z = startingVal++;
1262}
1263
1264void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1265 const ui::DisplayPrimaries& primaries) {
1266 float startingVal = mStartingTestValue;
1267 EXPECT_EQ(primaries.red.X, startingVal++);
1268 EXPECT_EQ(primaries.red.Y, startingVal++);
1269 EXPECT_EQ(primaries.red.Z, startingVal++);
1270 EXPECT_EQ(primaries.green.X, startingVal++);
1271 EXPECT_EQ(primaries.green.Y, startingVal++);
1272 EXPECT_EQ(primaries.green.Z, startingVal++);
1273 EXPECT_EQ(primaries.blue.X, startingVal++);
1274 EXPECT_EQ(primaries.blue.Y, startingVal++);
1275 EXPECT_EQ(primaries.blue.Z, startingVal++);
1276 EXPECT_EQ(primaries.white.X, startingVal++);
1277 EXPECT_EQ(primaries.white.Y, startingVal++);
1278 EXPECT_EQ(primaries.white.Z, startingVal++);
1279}
1280
1281TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1282 ui::DisplayPrimaries primaries;
1283 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1284}
1285
1286TEST_F(GetDisplayNativePrimaries, internalDisplayWithDefaultPrimariesData) {
1287 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1288 injector.inject();
1289 auto internalDisplayToken = injector.token();
1290 // A nullptr would trigger a different execution path than what's being tested here
1291 EXPECT_NE(nullptr, internalDisplayToken.get());
1292
1293 mFlinger.initDefaultDisplayNativePrimaries();
1294
1295 ui::DisplayPrimaries primaries;
1296 // Expecting sRGB primaries
1297 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1298 EXPECT_EQ(primaries.red.X, 0.4123f);
1299 EXPECT_EQ(primaries.red.Y, 0.2126f);
1300 EXPECT_EQ(primaries.red.Z, 0.0193f);
1301 EXPECT_EQ(primaries.green.X, 0.3576f);
1302 EXPECT_EQ(primaries.green.Y, 0.7152f);
1303 EXPECT_EQ(primaries.green.Z, 0.1192f);
1304 EXPECT_EQ(primaries.blue.X, 0.1805f);
1305 EXPECT_EQ(primaries.blue.Y, 0.0722f);
1306 EXPECT_EQ(primaries.blue.Z, 0.9506f);
1307 EXPECT_EQ(primaries.white.X, 0.9505f);
1308 EXPECT_EQ(primaries.white.Y, 1.0000f);
1309 EXPECT_EQ(primaries.white.Z, 1.0891f);
1310}
1311
1312TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1313 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1314 injector.inject();
1315 auto internalDisplayToken = injector.token();
1316
1317 ui::DisplayPrimaries expectedPrimaries;
1318 populateDummyDisplayNativePrimaries(expectedPrimaries);
1319 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1320
1321 ui::DisplayPrimaries primaries;
1322 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1323
1324 checkDummyDisplayNativePrimaries(primaries);
1325}
1326
1327TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1328 sp<BBinder> notInternalDisplayToken = new BBinder();
1329
1330 ui::DisplayPrimaries primaries;
1331 populateDummyDisplayNativePrimaries(primaries);
1332 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1333
1334 // Check primaries argument wasn't modified in case of failure
1335 checkDummyDisplayNativePrimaries(primaries);
1336}
1337
1338/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001339 * SurfaceFlinger::setupNewDisplayDeviceInternal
1340 */
1341
1342class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1343public:
1344 template <typename T>
1345 void setupNewDisplayDeviceInternalTest();
1346};
1347
1348template <typename Case>
1349void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1350 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001351 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1352 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001353 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001354
1355 // --------------------------------------------------------------------
1356 // Preconditions
1357
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001358 // Wide color displays support is configured appropriately
1359 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001360
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001361 // The display is setup with the HWC.
1362 Case::Display::injectHwcDisplay(this);
1363
1364 // SurfaceFlinger will use a test-controlled factory for native window
1365 // surfaces.
1366 injectFakeNativeWindowSurfaceFactory();
1367
1368 // --------------------------------------------------------------------
1369 // Call Expectations
1370
1371 // Various native window calls will be made.
1372 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001373 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001374 Case::WideColorSupport::setupComposerCallExpectations(this);
1375 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001376 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001377
1378 // --------------------------------------------------------------------
1379 // Invocation
1380
1381 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001382 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1383 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001384 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1385
Dominik Laskowski075d3172018-05-24 15:50:06 -07001386 auto device =
1387 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1388 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001389
1390 // --------------------------------------------------------------------
1391 // Postconditions
1392
1393 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001394 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1395 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001396 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001397 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001398 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1399 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1400 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001401 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001402 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1403 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1404 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001405 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1406 // remapped, and the test only ever sets up one config. If there were an error
1407 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
1408 EXPECT_EQ(0, device->getActiveConfig());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001409 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1410 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001411}
1412
1413TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1414 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1415}
1416
1417TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1418 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1419}
1420
1421TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1422 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1423}
1424
1425TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001426 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001427
Dominik Laskowski075d3172018-05-24 15:50:06 -07001428 // Insert display data so that the HWC thinks it created the virtual display.
1429 const auto displayId = Case::Display::DISPLAY_ID::get();
1430 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001431 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001432
1433 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001434}
1435
1436TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1437 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1438}
1439
Valerie Haue9e843a2018-12-18 13:39:23 -08001440TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1441 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1442}
1443
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001444TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1445 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1446}
1447
1448TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1449 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1450}
1451
1452TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1453 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1454}
1455
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001456TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1457 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1458}
1459
1460TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1461 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1462}
1463
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001464/* ------------------------------------------------------------------------
1465 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1466 */
1467
1468class HandleTransactionLockedTest : public DisplayTransactionTest {
1469public:
1470 template <typename Case>
1471 void setupCommonPreconditions();
1472
1473 template <typename Case>
1474 void setupCommonCallExpectationsForConnectProcessing();
1475
1476 template <typename Case>
1477 void setupCommonCallExpectationsForDisconnectProcessing();
1478
1479 template <typename Case>
1480 void processesHotplugConnectCommon();
1481
1482 template <typename Case>
1483 void ignoresHotplugConnectCommon();
1484
1485 template <typename Case>
1486 void processesHotplugDisconnectCommon();
1487
1488 template <typename Case>
1489 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1490
1491 template <typename Case>
1492 void verifyPhysicalDisplayIsConnected();
1493
1494 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1495};
1496
1497template <typename Case>
1498void HandleTransactionLockedTest::setupCommonPreconditions() {
1499 // Wide color displays support is configured appropriately
1500 Case::WideColorSupport::injectConfigChange(this);
1501
1502 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1503 injectFakeBufferQueueFactory();
1504
1505 // SurfaceFlinger will use a test-controlled factory for native window
1506 // surfaces.
1507 injectFakeNativeWindowSurfaceFactory();
1508}
1509
1510template <typename Case>
1511void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1512 Case::Display::setupHwcHotplugCallExpectations(this);
1513
1514 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1515 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1516 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1517 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1518
1519 Case::WideColorSupport::setupComposerCallExpectations(this);
1520 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001521 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001522
1523 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001524
1525 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::displayType(), true)).Times(1);
1526 EXPECT_CALL(*mSFEventThread, onHotplugReceived(Case::Display::displayType(), true)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001527}
1528
1529template <typename Case>
1530void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1531 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001532
1533 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::displayType(), false)).Times(1);
1534 EXPECT_CALL(*mSFEventThread, onHotplugReceived(Case::Display::displayType(), false)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001535}
1536
1537template <typename Case>
1538void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1539 // The display device should have been set up in the list of displays.
1540 ASSERT_TRUE(hasDisplayDevice(displayToken));
1541 const auto& device = getDisplayDevice(displayToken);
1542 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001543 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001544
1545 // The display should have been set up in the current display state
1546 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1547 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001548 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1549 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1550 : Case::Display::DISPLAY_ID::get(),
1551 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001552
1553 // The display should have been set up in the drawing display state
1554 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1555 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001556 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1557 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1558 : Case::Display::DISPLAY_ID::get(),
1559 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001560}
1561
1562template <typename Case>
1563void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1564 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001565 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001566
Dominik Laskowski075d3172018-05-24 15:50:06 -07001567 // SF should have a display token.
1568 const auto displayId = Case::Display::DISPLAY_ID::get();
1569 ASSERT_TRUE(displayId);
1570 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1571 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001572
1573 verifyDisplayIsConnected<Case>(displayToken);
1574}
1575
1576void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1577 EXPECT_FALSE(hasDisplayDevice(displayToken));
1578 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1579 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1580}
1581
1582template <typename Case>
1583void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1584 // --------------------------------------------------------------------
1585 // Preconditions
1586
1587 setupCommonPreconditions<Case>();
1588
1589 // A hotplug connect event is enqueued for a display
1590 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001591
1592 // --------------------------------------------------------------------
1593 // Call Expectations
1594
1595 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001596
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001597 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001598
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001599 // --------------------------------------------------------------------
1600 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001601
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001602 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001603
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001604 // --------------------------------------------------------------------
1605 // Postconditions
1606
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001607 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001608
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001609 // --------------------------------------------------------------------
1610 // Cleanup conditions
1611
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001612 EXPECT_CALL(*mComposer,
1613 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001614 .WillOnce(Return(Error::NONE));
1615 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001616}
1617
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001618template <typename Case>
1619void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1620 // --------------------------------------------------------------------
1621 // Preconditions
1622
1623 setupCommonPreconditions<Case>();
1624
1625 // A hotplug connect event is enqueued for a display
1626 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1627
1628 // --------------------------------------------------------------------
1629 // Invocation
1630
1631 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1632
1633 // --------------------------------------------------------------------
1634 // Postconditions
1635
1636 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001637 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001638}
1639
1640template <typename Case>
1641void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1642 // --------------------------------------------------------------------
1643 // Preconditions
1644
1645 setupCommonPreconditions<Case>();
1646
1647 // A hotplug disconnect event is enqueued for a display
1648 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1649
1650 // The display is already completely set up.
1651 Case::Display::injectHwcDisplay(this);
1652 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1653 existing.inject();
1654
1655 // --------------------------------------------------------------------
1656 // Call Expectations
1657
1658 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001659 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1660 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001661
1662 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1663
1664 // --------------------------------------------------------------------
1665 // Invocation
1666
1667 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1668
1669 // --------------------------------------------------------------------
1670 // Postconditions
1671
1672 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001673 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001674
Dominik Laskowski075d3172018-05-24 15:50:06 -07001675 // SF should not have a display token.
1676 const auto displayId = Case::Display::DISPLAY_ID::get();
1677 ASSERT_TRUE(displayId);
1678 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001679
1680 // The existing token should have been removed
1681 verifyDisplayIsNotConnected(existing.token());
1682}
1683
1684TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1685 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1686}
1687
1688TEST_F(HandleTransactionLockedTest,
1689 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1690 // Inject an external display.
1691 ExternalDisplayVariant::injectHwcDisplay(this);
1692
1693 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1694}
1695
1696TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1697 // Inject a primary display.
1698 PrimaryDisplayVariant::injectHwcDisplay(this);
1699
1700 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1701}
1702
1703TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1704 // Inject both a primary and external display.
1705 PrimaryDisplayVariant::injectHwcDisplay(this);
1706 ExternalDisplayVariant::injectHwcDisplay(this);
1707
1708 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1709
1710 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1711}
1712
1713TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1714 // Inject a primary display.
1715 PrimaryDisplayVariant::injectHwcDisplay(this);
1716
1717 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1718
1719 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1720}
1721
1722TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1723 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1724}
1725
1726TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1727 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1728}
1729
1730TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1731 using Case = SimplePrimaryDisplayCase;
1732
1733 // --------------------------------------------------------------------
1734 // Preconditions
1735
1736 setupCommonPreconditions<Case>();
1737
1738 // A hotplug connect event is enqueued for a display
1739 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1740 // A hotplug disconnect event is also enqueued for the same display
1741 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1742
1743 // --------------------------------------------------------------------
1744 // Call Expectations
1745
1746 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1747
1748 setupCommonCallExpectationsForConnectProcessing<Case>();
1749 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1750
1751 EXPECT_CALL(*mComposer,
1752 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1753 .WillOnce(Return(Error::NONE));
1754 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1755
1756 // --------------------------------------------------------------------
1757 // Invocation
1758
1759 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1760
1761 // --------------------------------------------------------------------
1762 // Postconditions
1763
1764 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001765 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001766
Dominik Laskowski075d3172018-05-24 15:50:06 -07001767 // SF should not have a display token.
1768 const auto displayId = Case::Display::DISPLAY_ID::get();
1769 ASSERT_TRUE(displayId);
1770 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001771}
1772
1773TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1774 using Case = SimplePrimaryDisplayCase;
1775
1776 // --------------------------------------------------------------------
1777 // Preconditions
1778
1779 setupCommonPreconditions<Case>();
1780
1781 // The display is already completely set up.
1782 Case::Display::injectHwcDisplay(this);
1783 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1784 existing.inject();
1785
1786 // A hotplug disconnect event is enqueued for a display
1787 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1788 // A hotplug connect event is also enqueued for the same display
1789 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1790
1791 // --------------------------------------------------------------------
1792 // Call Expectations
1793
1794 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1795
1796 setupCommonCallExpectationsForConnectProcessing<Case>();
1797 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1798
1799 // --------------------------------------------------------------------
1800 // Invocation
1801
1802 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1803
1804 // --------------------------------------------------------------------
1805 // Postconditions
1806
1807 // The existing token should have been removed
1808 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001809 const auto displayId = Case::Display::DISPLAY_ID::get();
1810 ASSERT_TRUE(displayId);
1811 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1812 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001813
1814 // A new display should be connected in its place
1815
1816 verifyPhysicalDisplayIsConnected<Case>();
1817
1818 // --------------------------------------------------------------------
1819 // Cleanup conditions
1820
1821 EXPECT_CALL(*mComposer,
1822 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1823 .WillOnce(Return(Error::NONE));
1824 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1825}
1826
1827TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1828 using Case = HwcVirtualDisplayCase;
1829
1830 // --------------------------------------------------------------------
1831 // Preconditions
1832
1833 // The HWC supports at least one virtual display
1834 injectMockComposer(1);
1835
1836 setupCommonPreconditions<Case>();
1837
1838 // A virtual display was added to the current state, and it has a
1839 // surface(producer)
1840 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07001841
Dominik Laskowski075d3172018-05-24 15:50:06 -07001842 DisplayDeviceState state;
1843 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001844
1845 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001846 state.surface = surface;
1847 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001848
1849 // --------------------------------------------------------------------
1850 // Call Expectations
1851
1852 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1853 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1854
1855 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1856 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1857 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1858 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1859 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1860 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1861 Return(NO_ERROR)));
1862 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1863 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1864
1865 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1866
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001867 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1868
1869 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1870 Case::WideColorSupport::setupComposerCallExpectations(this);
1871 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001872 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001873
1874 // --------------------------------------------------------------------
1875 // Invocation
1876
1877 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1878
1879 // --------------------------------------------------------------------
1880 // Postconditions
1881
1882 // The display device should have been set up in the list of displays.
1883 verifyDisplayIsConnected<Case>(displayToken);
1884
1885 // --------------------------------------------------------------------
1886 // Cleanup conditions
1887
1888 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1889 .WillOnce(Return(Error::NONE));
1890 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1891}
1892
1893TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1894 using Case = HwcVirtualDisplayCase;
1895
1896 // --------------------------------------------------------------------
1897 // Preconditions
1898
1899 // The HWC supports at least one virtual display
1900 injectMockComposer(1);
1901
1902 setupCommonPreconditions<Case>();
1903
1904 // A virtual display was added to the current state, but it does not have a
1905 // surface.
1906 sp<BBinder> displayToken = new BBinder();
1907
Dominik Laskowski075d3172018-05-24 15:50:06 -07001908 DisplayDeviceState state;
1909 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001910
Dominik Laskowski075d3172018-05-24 15:50:06 -07001911 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001912
1913 // --------------------------------------------------------------------
1914 // Call Expectations
1915
1916 // --------------------------------------------------------------------
1917 // Invocation
1918
1919 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1920
1921 // --------------------------------------------------------------------
1922 // Postconditions
1923
1924 // There will not be a display device set up.
1925 EXPECT_FALSE(hasDisplayDevice(displayToken));
1926
1927 // The drawing display state will be set from the current display state.
1928 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1929 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001930 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001931}
1932
1933TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1934 using Case = HwcVirtualDisplayCase;
1935
1936 // --------------------------------------------------------------------
1937 // Preconditions
1938
1939 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07001940 const auto displayId = Case::Display::DISPLAY_ID::get();
1941 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001942 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001943 Case::Display::injectHwcDisplay(this);
1944 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1945 existing.inject();
1946 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1947
1948 // --------------------------------------------------------------------
1949 // Call Expectations
1950
1951 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1952
1953 // --------------------------------------------------------------------
1954 // Invocation
1955
1956 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1957
1958 // --------------------------------------------------------------------
1959 // Postconditions
1960
1961 // The existing token should have been removed
1962 verifyDisplayIsNotConnected(existing.token());
1963}
1964
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001965TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
1966 using Case = NonHwcVirtualDisplayCase;
1967
1968 constexpr uint32_t oldLayerStack = 0u;
1969 constexpr uint32_t newLayerStack = 123u;
1970
1971 // --------------------------------------------------------------------
1972 // Preconditions
1973
1974 // A display is set up
1975 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
1976 display.inject();
1977
1978 // There is a change to the layerStack state
1979 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
1980 display.mutableCurrentDisplayState().layerStack = newLayerStack;
1981
1982 // --------------------------------------------------------------------
1983 // Invocation
1984
1985 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1986
1987 // --------------------------------------------------------------------
1988 // Postconditions
1989
Lloyd Pique9d9cf402018-02-16 17:47:13 -08001990 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08001991}
1992
1993TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
1994 using Case = NonHwcVirtualDisplayCase;
1995
1996 constexpr int oldTransform = 0;
1997 constexpr int newTransform = 2;
1998
1999 // --------------------------------------------------------------------
2000 // Preconditions
2001
2002 // A display is set up
2003 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2004 display.inject();
2005
2006 // There is a change to the orientation state
2007 display.mutableDrawingDisplayState().orientation = oldTransform;
2008 display.mutableCurrentDisplayState().orientation = newTransform;
2009
2010 // --------------------------------------------------------------------
2011 // Invocation
2012
2013 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2014
2015 // --------------------------------------------------------------------
2016 // Postconditions
2017
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002018 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002019}
2020
2021TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2022 using Case = NonHwcVirtualDisplayCase;
2023
2024 const Rect oldViewport(0, 0, 0, 0);
2025 const Rect newViewport(0, 0, 123, 456);
2026
2027 // --------------------------------------------------------------------
2028 // Preconditions
2029
2030 // A display is set up
2031 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2032 display.inject();
2033
2034 // There is a change to the viewport state
2035 display.mutableDrawingDisplayState().viewport = oldViewport;
2036 display.mutableCurrentDisplayState().viewport = newViewport;
2037
2038 // --------------------------------------------------------------------
2039 // Invocation
2040
2041 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2042
2043 // --------------------------------------------------------------------
2044 // Postconditions
2045
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002046 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002047}
2048
2049TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2050 using Case = NonHwcVirtualDisplayCase;
2051
2052 const Rect oldFrame(0, 0, 0, 0);
2053 const Rect newFrame(0, 0, 123, 456);
2054
2055 // --------------------------------------------------------------------
2056 // Preconditions
2057
2058 // A display is set up
2059 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2060 display.inject();
2061
2062 // There is a change to the viewport state
2063 display.mutableDrawingDisplayState().frame = oldFrame;
2064 display.mutableCurrentDisplayState().frame = newFrame;
2065
2066 // --------------------------------------------------------------------
2067 // Invocation
2068
2069 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2070
2071 // --------------------------------------------------------------------
2072 // Postconditions
2073
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002074 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002075}
2076
2077TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2078 using Case = NonHwcVirtualDisplayCase;
2079
2080 constexpr int oldWidth = 0;
2081 constexpr int oldHeight = 10;
2082 constexpr int newWidth = 123;
2083
2084 // --------------------------------------------------------------------
2085 // Preconditions
2086
2087 // A display is set up
2088 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002089 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002090 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002091 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2092 display.setNativeWindow(nativeWindow);
2093 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002094 // Setup injection expections
2095 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2096 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2097 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2098 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Alec Mouri4efb6c22018-11-16 13:07:47 -08002099 EXPECT_CALL(*nativeWindow, perform(9)).Times(1);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002100 EXPECT_CALL(*nativeWindow, perform(13)).Times(1);
Alec Mouri4efb6c22018-11-16 13:07:47 -08002101 EXPECT_CALL(*nativeWindow, perform(30)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002102 display.inject();
2103
2104 // There is a change to the viewport state
2105 display.mutableDrawingDisplayState().width = oldWidth;
2106 display.mutableDrawingDisplayState().height = oldHeight;
2107 display.mutableCurrentDisplayState().width = newWidth;
2108 display.mutableCurrentDisplayState().height = oldHeight;
2109
2110 // --------------------------------------------------------------------
2111 // Call Expectations
2112
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002113 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002114
2115 // --------------------------------------------------------------------
2116 // Invocation
2117
2118 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2119}
2120
2121TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2122 using Case = NonHwcVirtualDisplayCase;
2123
2124 constexpr int oldWidth = 0;
2125 constexpr int oldHeight = 10;
2126 constexpr int newHeight = 123;
2127
2128 // --------------------------------------------------------------------
2129 // Preconditions
2130
2131 // A display is set up
2132 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002133 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002134 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002135 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2136 display.setNativeWindow(nativeWindow);
2137 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002138 // Setup injection expections
2139 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2140 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2141 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2142 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Alec Mouri4efb6c22018-11-16 13:07:47 -08002143 EXPECT_CALL(*nativeWindow, perform(9)).Times(1);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002144 EXPECT_CALL(*nativeWindow, perform(13)).Times(1);
Alec Mouri4efb6c22018-11-16 13:07:47 -08002145 EXPECT_CALL(*nativeWindow, perform(30)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002146 display.inject();
2147
2148 // There is a change to the viewport state
2149 display.mutableDrawingDisplayState().width = oldWidth;
2150 display.mutableDrawingDisplayState().height = oldHeight;
2151 display.mutableCurrentDisplayState().width = oldWidth;
2152 display.mutableCurrentDisplayState().height = newHeight;
2153
2154 // --------------------------------------------------------------------
2155 // Call Expectations
2156
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002157 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002158
2159 // --------------------------------------------------------------------
2160 // Invocation
2161
2162 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2163}
2164
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002165/* ------------------------------------------------------------------------
2166 * SurfaceFlinger::setDisplayStateLocked
2167 */
2168
2169TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2170 // --------------------------------------------------------------------
2171 // Preconditions
2172
2173 // We have an unknown display token not associated with a known display
2174 sp<BBinder> displayToken = new BBinder();
2175
2176 // The requested display state references the unknown display.
2177 DisplayState state;
2178 state.what = DisplayState::eLayerStackChanged;
2179 state.token = displayToken;
2180 state.layerStack = 456;
2181
2182 // --------------------------------------------------------------------
2183 // Invocation
2184
2185 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2186
2187 // --------------------------------------------------------------------
2188 // Postconditions
2189
2190 // The returned flags are empty
2191 EXPECT_EQ(0u, flags);
2192
2193 // The display token still doesn't match anything known.
2194 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2195}
2196
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002197TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2198 using Case = SimplePrimaryDisplayCase;
2199
2200 // --------------------------------------------------------------------
2201 // Preconditions
2202
2203 // A display is already set up
2204 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2205 display.inject();
2206
2207 // No changes are made to the display
2208 DisplayState state;
2209 state.what = 0;
2210 state.token = display.token();
2211
2212 // --------------------------------------------------------------------
2213 // Invocation
2214
2215 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2216
2217 // --------------------------------------------------------------------
2218 // Postconditions
2219
2220 // The returned flags are empty
2221 EXPECT_EQ(0u, flags);
2222}
2223
2224TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2225 using Case = SimplePrimaryDisplayCase;
2226
2227 // --------------------------------------------------------------------
2228 // Preconditions
2229
2230 // A display is already set up
2231 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2232 display.inject();
2233
2234 // There is a surface that can be set.
2235 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2236
2237 // The current display state has the surface set
2238 display.mutableCurrentDisplayState().surface = surface;
2239
2240 // The incoming request sets the same surface
2241 DisplayState state;
2242 state.what = DisplayState::eSurfaceChanged;
2243 state.token = display.token();
2244 state.surface = surface;
2245
2246 // --------------------------------------------------------------------
2247 // Invocation
2248
2249 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2250
2251 // --------------------------------------------------------------------
2252 // Postconditions
2253
2254 // The returned flags are empty
2255 EXPECT_EQ(0u, flags);
2256
2257 // The current display state is unchanged.
2258 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2259}
2260
2261TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2262 using Case = SimplePrimaryDisplayCase;
2263
2264 // --------------------------------------------------------------------
2265 // Preconditions
2266
2267 // A display is already set up
2268 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2269 display.inject();
2270
2271 // There is a surface that can be set.
2272 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2273
2274 // The current display state does not have a surface
2275 display.mutableCurrentDisplayState().surface = nullptr;
2276
2277 // The incoming request sets a surface
2278 DisplayState state;
2279 state.what = DisplayState::eSurfaceChanged;
2280 state.token = display.token();
2281 state.surface = surface;
2282
2283 // --------------------------------------------------------------------
2284 // Invocation
2285
2286 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2287
2288 // --------------------------------------------------------------------
2289 // Postconditions
2290
2291 // The returned flags indicate a transaction is needed
2292 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2293
2294 // The current display layer stack state is set to the new value
2295 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2296}
2297
2298TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2299 using Case = SimplePrimaryDisplayCase;
2300
2301 // --------------------------------------------------------------------
2302 // Preconditions
2303
2304 // A display is already set up
2305 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2306 display.inject();
2307
2308 // The display has a layer stack set
2309 display.mutableCurrentDisplayState().layerStack = 456u;
2310
2311 // The incoming request sets the same layer stack
2312 DisplayState state;
2313 state.what = DisplayState::eLayerStackChanged;
2314 state.token = display.token();
2315 state.layerStack = 456u;
2316
2317 // --------------------------------------------------------------------
2318 // Invocation
2319
2320 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2321
2322 // --------------------------------------------------------------------
2323 // Postconditions
2324
2325 // The returned flags are empty
2326 EXPECT_EQ(0u, flags);
2327
2328 // The current display state is unchanged
2329 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2330}
2331
2332TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2333 using Case = SimplePrimaryDisplayCase;
2334
2335 // --------------------------------------------------------------------
2336 // Preconditions
2337
2338 // A display is set up
2339 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2340 display.inject();
2341
2342 // The display has a layer stack set
2343 display.mutableCurrentDisplayState().layerStack = 654u;
2344
2345 // The incoming request sets a different layer stack
2346 DisplayState state;
2347 state.what = DisplayState::eLayerStackChanged;
2348 state.token = display.token();
2349 state.layerStack = 456u;
2350
2351 // --------------------------------------------------------------------
2352 // Invocation
2353
2354 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2355
2356 // --------------------------------------------------------------------
2357 // Postconditions
2358
2359 // The returned flags indicate a transaction is needed
2360 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2361
2362 // The desired display state has been set to the new value.
2363 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2364}
2365
2366TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2367 using Case = SimplePrimaryDisplayCase;
2368 constexpr int initialOrientation = 180;
2369 const Rect initialFrame = {1, 2, 3, 4};
2370 const Rect initialViewport = {5, 6, 7, 8};
2371
2372 // --------------------------------------------------------------------
2373 // Preconditions
2374
2375 // A display is set up
2376 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2377 display.inject();
2378
2379 // The current display state projection state is all set
2380 display.mutableCurrentDisplayState().orientation = initialOrientation;
2381 display.mutableCurrentDisplayState().frame = initialFrame;
2382 display.mutableCurrentDisplayState().viewport = initialViewport;
2383
2384 // The incoming request sets the same projection state
2385 DisplayState state;
2386 state.what = DisplayState::eDisplayProjectionChanged;
2387 state.token = display.token();
2388 state.orientation = initialOrientation;
2389 state.frame = initialFrame;
2390 state.viewport = initialViewport;
2391
2392 // --------------------------------------------------------------------
2393 // Invocation
2394
2395 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2396
2397 // --------------------------------------------------------------------
2398 // Postconditions
2399
2400 // The returned flags are empty
2401 EXPECT_EQ(0u, flags);
2402
2403 // The current display state is unchanged
2404 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2405
2406 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2407 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2408}
2409
2410TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2411 using Case = SimplePrimaryDisplayCase;
2412 constexpr int initialOrientation = 90;
2413 constexpr int desiredOrientation = 180;
2414
2415 // --------------------------------------------------------------------
2416 // Preconditions
2417
2418 // A display is set up
2419 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2420 display.inject();
2421
2422 // The current display state has an orientation set
2423 display.mutableCurrentDisplayState().orientation = initialOrientation;
2424
2425 // The incoming request sets a different orientation
2426 DisplayState state;
2427 state.what = DisplayState::eDisplayProjectionChanged;
2428 state.token = display.token();
2429 state.orientation = desiredOrientation;
2430
2431 // --------------------------------------------------------------------
2432 // Invocation
2433
2434 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2435
2436 // --------------------------------------------------------------------
2437 // Postconditions
2438
2439 // The returned flags indicate a transaction is needed
2440 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2441
2442 // The current display state has the new value.
2443 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2444}
2445
2446TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2447 using Case = SimplePrimaryDisplayCase;
2448 const Rect initialFrame = {0, 0, 0, 0};
2449 const Rect desiredFrame = {5, 6, 7, 8};
2450
2451 // --------------------------------------------------------------------
2452 // Preconditions
2453
2454 // A display is set up
2455 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2456 display.inject();
2457
2458 // The current display state does not have a frame
2459 display.mutableCurrentDisplayState().frame = initialFrame;
2460
2461 // The incoming request sets a frame
2462 DisplayState state;
2463 state.what = DisplayState::eDisplayProjectionChanged;
2464 state.token = display.token();
2465 state.frame = desiredFrame;
2466
2467 // --------------------------------------------------------------------
2468 // Invocation
2469
2470 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2471
2472 // --------------------------------------------------------------------
2473 // Postconditions
2474
2475 // The returned flags indicate a transaction is needed
2476 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2477
2478 // The current display state has the new value.
2479 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2480}
2481
2482TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2483 using Case = SimplePrimaryDisplayCase;
2484 const Rect initialViewport = {0, 0, 0, 0};
2485 const Rect desiredViewport = {5, 6, 7, 8};
2486
2487 // --------------------------------------------------------------------
2488 // Preconditions
2489
2490 // A display is set up
2491 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2492 display.inject();
2493
2494 // The current display state does not have a viewport
2495 display.mutableCurrentDisplayState().viewport = initialViewport;
2496
2497 // The incoming request sets a viewport
2498 DisplayState state;
2499 state.what = DisplayState::eDisplayProjectionChanged;
2500 state.token = display.token();
2501 state.viewport = desiredViewport;
2502
2503 // --------------------------------------------------------------------
2504 // Invocation
2505
2506 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2507
2508 // --------------------------------------------------------------------
2509 // Postconditions
2510
2511 // The returned flags indicate a transaction is needed
2512 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2513
2514 // The current display state has the new value.
2515 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2516}
2517
2518TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2519 using Case = SimplePrimaryDisplayCase;
2520 constexpr uint32_t initialWidth = 1024;
2521 constexpr uint32_t initialHeight = 768;
2522
2523 // --------------------------------------------------------------------
2524 // Preconditions
2525
2526 // A display is set up
2527 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2528 display.inject();
2529
2530 // The current display state has a size set
2531 display.mutableCurrentDisplayState().width = initialWidth;
2532 display.mutableCurrentDisplayState().height = initialHeight;
2533
2534 // The incoming request sets the same display size
2535 DisplayState state;
2536 state.what = DisplayState::eDisplaySizeChanged;
2537 state.token = display.token();
2538 state.width = initialWidth;
2539 state.height = initialHeight;
2540
2541 // --------------------------------------------------------------------
2542 // Invocation
2543
2544 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2545
2546 // --------------------------------------------------------------------
2547 // Postconditions
2548
2549 // The returned flags are empty
2550 EXPECT_EQ(0u, flags);
2551
2552 // The current display state is unchanged
2553 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2554 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2555}
2556
2557TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2558 using Case = SimplePrimaryDisplayCase;
2559 constexpr uint32_t initialWidth = 0;
2560 constexpr uint32_t desiredWidth = 1024;
2561
2562 // --------------------------------------------------------------------
2563 // Preconditions
2564
2565 // A display is set up
2566 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2567 display.inject();
2568
2569 // The display does not yet have a width
2570 display.mutableCurrentDisplayState().width = initialWidth;
2571
2572 // The incoming request sets a display width
2573 DisplayState state;
2574 state.what = DisplayState::eDisplaySizeChanged;
2575 state.token = display.token();
2576 state.width = desiredWidth;
2577
2578 // --------------------------------------------------------------------
2579 // Invocation
2580
2581 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2582
2583 // --------------------------------------------------------------------
2584 // Postconditions
2585
2586 // The returned flags indicate a transaction is needed
2587 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2588
2589 // The current display state has the new value.
2590 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2591}
2592
2593TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2594 using Case = SimplePrimaryDisplayCase;
2595 constexpr uint32_t initialHeight = 0;
2596 constexpr uint32_t desiredHeight = 768;
2597
2598 // --------------------------------------------------------------------
2599 // Preconditions
2600
2601 // A display is set up
2602 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2603 display.inject();
2604
2605 // The display does not yet have a height
2606 display.mutableCurrentDisplayState().height = initialHeight;
2607
2608 // The incoming request sets a display height
2609 DisplayState state;
2610 state.what = DisplayState::eDisplaySizeChanged;
2611 state.token = display.token();
2612 state.height = desiredHeight;
2613
2614 // --------------------------------------------------------------------
2615 // Invocation
2616
2617 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2618
2619 // --------------------------------------------------------------------
2620 // Postconditions
2621
2622 // The returned flags indicate a transaction is needed
2623 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2624
2625 // The current display state has the new value.
2626 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2627}
2628
Lloyd Pique86016da2018-03-01 16:09:38 -08002629/* ------------------------------------------------------------------------
2630 * SurfaceFlinger::onInitializeDisplays
2631 */
2632
2633TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2634 using Case = SimplePrimaryDisplayCase;
2635
2636 // --------------------------------------------------------------------
2637 // Preconditions
2638
2639 // A primary display is set up
2640 Case::Display::injectHwcDisplay(this);
2641 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2642 primaryDisplay.inject();
2643
2644 // --------------------------------------------------------------------
2645 // Call Expectations
2646
2647 // We expect the surface interceptor to possibly be used, but we treat it as
2648 // disabled since it is called as a side effect rather than directly by this
2649 // function.
2650 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2651
2652 // We expect a call to get the active display config.
2653 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2654
2655 // We expect invalidate() to be invoked once to trigger display transaction
2656 // processing.
2657 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2658
2659 // --------------------------------------------------------------------
2660 // Invocation
2661
2662 mFlinger.onInitializeDisplays();
2663
2664 // --------------------------------------------------------------------
2665 // Postconditions
2666
2667 // The primary display should have a current state
2668 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2669 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2670 // The layer stack state should be set to zero
2671 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2672 // The orientation state should be set to zero
2673 EXPECT_EQ(0, primaryDisplayState.orientation);
2674
2675 // The frame state should be set to INVALID
2676 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2677
2678 // The viewport state should be set to INVALID
2679 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2680
2681 // The width and height should both be zero
2682 EXPECT_EQ(0u, primaryDisplayState.width);
2683 EXPECT_EQ(0u, primaryDisplayState.height);
2684
2685 // The display should be set to HWC_POWER_MODE_NORMAL
2686 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2687 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2688 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2689
2690 // The display refresh period should be set in the frame tracker.
2691 FrameStats stats;
2692 mFlinger.getAnimFrameTracker().getStats(&stats);
2693 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2694
2695 // The display transaction needed flag should be set.
2696 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2697
2698 // The compositor timing should be set to default values
2699 const auto& compositorTiming = mFlinger.getCompositorTiming();
2700 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2701 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2702 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2703}
2704
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002705/* ------------------------------------------------------------------------
2706 * SurfaceFlinger::setPowerModeInternal
2707 */
2708
2709// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07002710template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002711struct DozeIsSupportedVariant {
2712 static constexpr bool DOZE_SUPPORTED = true;
2713 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2714 IComposerClient::PowerMode::DOZE;
2715 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2716 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07002717
2718 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2719 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2720 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
2721 {Hwc2::DisplayCapability::DOZE})),
2722 Return(Error::NONE)));
2723 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002724};
2725
Peiyong Lined531a32018-10-26 18:27:56 -07002726template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002727// Used when we simulate a display that does not support doze.
2728struct DozeNotSupportedVariant {
2729 static constexpr bool DOZE_SUPPORTED = false;
2730 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2731 IComposerClient::PowerMode::ON;
2732 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2733 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07002734
2735 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2736 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2737 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
2738 Return(Error::NONE)));
2739 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002740};
2741
2742struct EventThreadBaseSupportedVariant {
2743 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
2744 // The event control thread should not be notified.
2745 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
2746
2747 // The event thread should not be notified.
2748 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
2749 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
2750 }
2751};
2752
2753struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
2754 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2755 // These calls are only expected for the primary display.
2756
2757 // Instead expect no calls.
2758 setupEventAndEventControlThreadNoCallExpectations(test);
2759 }
2760
2761 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2762 // These calls are only expected for the primary display.
2763
2764 // Instead expect no calls.
2765 setupEventAndEventControlThreadNoCallExpectations(test);
2766 }
2767};
2768
2769struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
2770 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2771 // The event control thread should be notified to enable vsyncs
2772 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
2773
2774 // The event thread should be notified that the screen was acquired.
2775 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
2776 }
2777
2778 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2779 // There should be a call to setVsyncEnabled(false)
2780 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
2781
2782 // The event thread should not be notified that the screen was released.
2783 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
2784 }
2785};
2786
Lloyd Pique41be5d22018-06-21 13:11:48 -07002787struct DispSyncIsSupportedVariant {
2788 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
2789 EXPECT_CALL(*test->mPrimaryDispSync, reset()).Times(1);
2790 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
2791 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
2792 }
2793
2794 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
2795 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
2796 }
2797};
2798
2799struct DispSyncNotSupportedVariant {
2800 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2801
2802 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2803};
2804
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002805// --------------------------------------------------------------------
2806// Note:
2807//
2808// There are a large number of transitions we could test, however we only test a
2809// selected subset which provides complete test coverage of the implementation.
2810// --------------------------------------------------------------------
2811
2812template <int initialPowerMode, int targetPowerMode>
2813struct TransitionVariantCommon {
2814 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
2815 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
2816
2817 static void verifyPostconditions(DisplayTransactionTest*) {}
2818};
2819
2820struct TransitionOffToOnVariant
2821 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
2822 template <typename Case>
2823 static void setupCallExpectations(DisplayTransactionTest* test) {
2824 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2825 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002826 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002827 Case::setupRepaintEverythingCallExpectations(test);
2828 }
2829
2830 static void verifyPostconditions(DisplayTransactionTest* test) {
2831 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2832 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2833 }
2834};
2835
2836struct TransitionOffToDozeSuspendVariant
2837 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
2838 template <typename Case>
2839 static void setupCallExpectations(DisplayTransactionTest* test) {
2840 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2841 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2842 Case::setupRepaintEverythingCallExpectations(test);
2843 }
2844
2845 static void verifyPostconditions(DisplayTransactionTest* test) {
2846 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2847 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2848 }
2849};
2850
2851struct TransitionOnToOffVariant
2852 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
2853 template <typename Case>
2854 static void setupCallExpectations(DisplayTransactionTest* test) {
2855 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002856 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002857 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2858 }
2859
2860 static void verifyPostconditions(DisplayTransactionTest* test) {
2861 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2862 }
2863};
2864
2865struct TransitionDozeSuspendToOffVariant
2866 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
2867 template <typename Case>
2868 static void setupCallExpectations(DisplayTransactionTest* test) {
2869 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2870 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2871 }
2872
2873 static void verifyPostconditions(DisplayTransactionTest* test) {
2874 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2875 }
2876};
2877
2878struct TransitionOnToDozeVariant
2879 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
2880 template <typename Case>
2881 static void setupCallExpectations(DisplayTransactionTest* test) {
2882 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2883 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2884 }
2885};
2886
2887struct TransitionDozeSuspendToDozeVariant
2888 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
2889 template <typename Case>
2890 static void setupCallExpectations(DisplayTransactionTest* test) {
2891 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002892 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002893 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2894 }
2895};
2896
2897struct TransitionDozeToOnVariant
2898 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
2899 template <typename Case>
2900 static void setupCallExpectations(DisplayTransactionTest* test) {
2901 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2902 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2903 }
2904};
2905
2906struct TransitionDozeSuspendToOnVariant
2907 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
2908 template <typename Case>
2909 static void setupCallExpectations(DisplayTransactionTest* test) {
2910 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002911 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002912 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2913 }
2914};
2915
2916struct TransitionOnToDozeSuspendVariant
2917 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
2918 template <typename Case>
2919 static void setupCallExpectations(DisplayTransactionTest* test) {
2920 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002921 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002922 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2923 }
2924};
2925
2926struct TransitionOnToUnknownVariant
2927 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
2928 template <typename Case>
2929 static void setupCallExpectations(DisplayTransactionTest* test) {
2930 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2931 Case::setupNoComposerPowerModeCallExpectations(test);
2932 }
2933};
2934
2935// --------------------------------------------------------------------
2936// Note:
2937//
2938// Rather than testing the cartesian product of of
2939// DozeIsSupported/DozeNotSupported with all other options, we use one for one
2940// display type, and the other for another display type.
2941// --------------------------------------------------------------------
2942
2943template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07002944 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002945struct DisplayPowerCase {
2946 using Display = DisplayVariant;
2947 using Doze = DozeVariant;
2948 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07002949 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002950 using Transition = TransitionVariant;
2951
2952 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
2953 Display::injectHwcDisplay(test);
2954 auto display = Display::makeFakeExistingDisplayInjector(test);
2955 display.inject();
2956 display.mutableDisplayDevice()->setPowerMode(mode);
2957 return display;
2958 }
2959
2960 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
2961 test->mFlinger.mutablePrimaryHWVsyncEnabled() = enabled;
2962 }
2963
2964 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
2965 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
2966 }
2967
2968 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
2969 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
2970 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
2971 }
2972
2973 static void setupComposerCallExpectations(DisplayTransactionTest* test,
2974 IComposerClient::PowerMode mode) {
2975 // Any calls to get the active config will return a default value.
2976 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
2977 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
2978 Return(Error::NONE)));
2979
2980 // Any calls to get whether the display supports dozing will return the value set by the
2981 // policy variant.
2982 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
2983 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
2984
2985 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
2986 }
2987
2988 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
2989 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
2990 }
2991};
2992
2993// A sample configuration for the primary display.
2994// In addition to having event thread support, we emulate doze support.
2995template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07002996using PrimaryDisplayPowerCase =
2997 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
2998 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
2999 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003000
3001// A sample configuration for the external display.
3002// In addition to not having event thread support, we emulate not having doze
3003// support.
3004template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003005using ExternalDisplayPowerCase =
3006 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3007 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3008 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003009
3010class SetPowerModeInternalTest : public DisplayTransactionTest {
3011public:
3012 template <typename Case>
3013 void transitionDisplayCommon();
3014};
3015
3016template <int PowerMode>
3017struct PowerModeInitialVSyncEnabled : public std::false_type {};
3018
3019template <>
3020struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3021
3022template <>
3023struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3024
3025template <typename Case>
3026void SetPowerModeInternalTest::transitionDisplayCommon() {
3027 // --------------------------------------------------------------------
3028 // Preconditions
3029
Peiyong Lined531a32018-10-26 18:27:56 -07003030 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003031 auto display =
3032 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3033 Case::setInitialPrimaryHWVsyncEnabled(this,
3034 PowerModeInitialVSyncEnabled<
3035 Case::Transition::INITIAL_POWER_MODE>::value);
3036
3037 // --------------------------------------------------------------------
3038 // Call Expectations
3039
3040 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3041 Case::Transition::template setupCallExpectations<Case>(this);
3042
3043 // --------------------------------------------------------------------
3044 // Invocation
3045
3046 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3047 Case::Transition::TARGET_POWER_MODE);
3048
3049 // --------------------------------------------------------------------
3050 // Postconditions
3051
3052 Case::Transition::verifyPostconditions(this);
3053}
3054
3055TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3056 using Case = SimplePrimaryDisplayCase;
3057
3058 // --------------------------------------------------------------------
3059 // Preconditions
3060
3061 // A primary display device is set up
3062 Case::Display::injectHwcDisplay(this);
3063 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3064 display.inject();
3065
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003066 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003067 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3068
3069 // --------------------------------------------------------------------
3070 // Invocation
3071
3072 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3073
3074 // --------------------------------------------------------------------
3075 // Postconditions
3076
3077 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3078}
3079
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003080TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003081 using Case = HwcVirtualDisplayCase;
3082
3083 // --------------------------------------------------------------------
3084 // Preconditions
3085
Dominik Laskowski075d3172018-05-24 15:50:06 -07003086 // Insert display data so that the HWC thinks it created the virtual display.
3087 const auto displayId = Case::Display::DISPLAY_ID::get();
3088 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003089 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003090
3091 // A virtual display device is set up
3092 Case::Display::injectHwcDisplay(this);
3093 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3094 display.inject();
3095
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003096 // The display is set to HWC_POWER_MODE_NORMAL
3097 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003098
3099 // --------------------------------------------------------------------
3100 // Invocation
3101
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003102 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003103
3104 // --------------------------------------------------------------------
3105 // Postconditions
3106
3107 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3108}
3109
3110TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3111 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3112}
3113
3114TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3115 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3116}
3117
3118TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3119 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3120}
3121
3122TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3123 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3124}
3125
3126TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3127 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3128}
3129
3130TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3131 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3132}
3133
3134TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3135 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3136}
3137
3138TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3139 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3140}
3141
3142TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3143 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3144}
3145
3146TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3147 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3148}
3149
3150TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3151 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3152}
3153
3154TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3155 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3156}
3157
3158TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3159 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3160}
3161
3162TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3163 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3164}
3165
3166TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3167 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3168}
3169
3170TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3171 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3172}
3173
3174TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3175 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3176}
3177
3178TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3179 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3180}
3181
3182TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3183 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3184}
3185
3186TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3187 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3188}
3189
Lloyd Piquef58625d2017-12-19 13:22:33 -08003190} // namespace
3191} // namespace android