blob: dddad92f794e70b238f67d36f071f81f8dceee2f [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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Lloyd Piquef58625d2017-12-19 13:22:33 -080021#undef LOG_TAG
22#define LOG_TAG "LibSurfaceFlingerUnittests"
23
Dominik Laskowski075d3172018-05-24 15:50:06 -070024#include <type_traits>
25
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070026#include <compositionengine/Display.h>
27#include <compositionengine/DisplayColorProfile.h>
Lloyd Pique33050472019-12-19 17:12:44 -080028#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070029#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080030#include <gmock/gmock.h>
31#include <gtest/gtest.h>
Lloyd Pique1ebe0902019-10-04 14:47:13 -070032#include <gui/mock/GraphicBufferConsumer.h>
33#include <gui/mock/GraphicBufferProducer.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080034#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070035#include <renderengine/mock/RenderEngine.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070036#include <ui/DebugUtils.h>
Dominik Laskowski075d3172018-05-24 15:50:06 -070037
38#include "DisplayIdentificationTest.h"
Ana Krulecafb45842019-02-13 13:33:03 -080039#include "TestableScheduler.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080040#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080041#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070042#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080043#include "mock/MockEventControlThread.h"
44#include "mock/MockEventThread.h"
45#include "mock/MockMessageQueue.h"
46#include "mock/MockNativeWindowSurface.h"
47#include "mock/MockSurfaceInterceptor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080048#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080049
50namespace android {
51namespace {
52
Lloyd Piquee39cad22017-12-20 17:01:29 -080053using testing::_;
Lloyd Piquee39cad22017-12-20 17:01:29 -080054using testing::DoAll;
55using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080056using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080057using testing::Return;
58using testing::SetArgPointee;
59
Lloyd Piqued883d5a2018-04-27 19:32:30 -070060using android::Hwc2::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080061using android::Hwc2::Error;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070062using android::Hwc2::Hdr;
Lloyd Piquee39cad22017-12-20 17:01:29 -080063using android::Hwc2::IComposer;
64using android::Hwc2::IComposerClient;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070065using android::Hwc2::PerFrameMetadataKey;
66using android::Hwc2::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080067
Lloyd Piquec11e0d32018-01-22 18:44:59 -080068using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
69using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080070using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080071using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080072
Lloyd Piquec11e0d32018-01-22 18:44:59 -080073constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080074constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080075constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080076
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080077constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value
78
Lloyd Piquec11e0d32018-01-22 18:44:59 -080079/* ------------------------------------------------------------------------
80 * Boolean avoidance
81 *
82 * To make calls and template instantiations more readable, we define some
83 * local enums along with an implicit bool conversion.
84 */
85
86#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
87
Lloyd Piquec11e0d32018-01-22 18:44:59 -080088BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -070089BOOL_SUBSTITUTE(Critical);
90BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080091BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -070092BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080093
94/* ------------------------------------------------------------------------
95 *
96 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080097
Lloyd Piquef58625d2017-12-19 13:22:33 -080098class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -080099public:
Lloyd Piquef58625d2017-12-19 13:22:33 -0800100 DisplayTransactionTest();
101 ~DisplayTransactionTest() override;
102
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800103 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800104 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800105
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700106 void injectMockScheduler();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800107 void injectMockComposer(int virtualDisplayCount);
108 void injectFakeBufferQueueFactory();
109 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800110
111 // --------------------------------------------------------------------
112 // Postcondition helpers
113
Dominik Laskowski075d3172018-05-24 15:50:06 -0700114 bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800115 bool hasTransactionFlagSet(int flag);
116 bool hasDisplayDevice(sp<IBinder> displayToken);
117 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
118 bool hasCurrentDisplayState(sp<IBinder> displayToken);
119 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
120 bool hasDrawingDisplayState(sp<IBinder> displayToken);
121 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
122
123 // --------------------------------------------------------------------
124 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800125
Lloyd Piquef58625d2017-12-19 13:22:33 -0800126 TestableSurfaceFlinger mFlinger;
Alec Mouriba013fa2018-10-16 12:43:11 -0700127 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800128 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800129
130 // These mocks are created by the test, but are destroyed by SurfaceFlinger
131 // by virtue of being stored into a std::unique_ptr. However we still need
132 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700133 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800134 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800135 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
136 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700137
138 mock::DispSync* mPrimaryDispSync = new mock::DispSync;
139 mock::EventControlThread* mEventControlThread = new mock::EventControlThread;
140 mock::EventThread* mEventThread = new mock::EventThread;
141 mock::EventThread* mSFEventThread = new mock::EventThread;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800142
143 // These mocks are created only when expected to be created via a factory.
144 sp<mock::GraphicBufferConsumer> mConsumer;
145 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700146 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800147};
148
149DisplayTransactionTest::DisplayTransactionTest() {
150 const ::testing::TestInfo* const test_info =
151 ::testing::UnitTest::GetInstance()->current_test_info();
152 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800153
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800154 // Default to no wide color display support configured
155 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700156 mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800157 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800158
159 // Default to using HWC virtual displays
160 mFlinger.mutableUseHwcVirtualDisplays() = true;
161
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800162 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
163 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
164 });
165
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800166 mFlinger.setCreateNativeWindowSurface([](auto) {
167 ADD_FAILURE() << "Unexpected request to create a native window surface.";
168 return nullptr;
169 });
170
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700171 injectMockScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800172 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700173 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800174 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800175
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800176 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800177}
178
179DisplayTransactionTest::~DisplayTransactionTest() {
180 const ::testing::TestInfo* const test_info =
181 ::testing::UnitTest::GetInstance()->current_test_info();
182 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
183}
184
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700185void DisplayTransactionTest::injectMockScheduler() {
Ana Krulecafb45842019-02-13 13:33:03 -0800186 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700187 EXPECT_CALL(*mEventThread, createEventConnection(_, _))
188 .WillOnce(Return(new EventThreadConnection(mEventThread, ResyncCallback(),
189 ISurfaceComposer::eConfigChangedSuppress)));
190
Ana Krulecafb45842019-02-13 13:33:03 -0800191 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700192 EXPECT_CALL(*mSFEventThread, createEventConnection(_, _))
193 .WillOnce(Return(new EventThreadConnection(mSFEventThread, ResyncCallback(),
194 ISurfaceComposer::eConfigChangedSuppress)));
Ana Krulecafb45842019-02-13 13:33:03 -0800195
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700196 mFlinger.setupScheduler(std::unique_ptr<DispSync>(mPrimaryDispSync),
197 std::unique_ptr<EventControlThread>(mEventControlThread),
198 std::unique_ptr<EventThread>(mEventThread),
199 std::unique_ptr<EventThread>(mSFEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800200}
201
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800202void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
203 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800204 EXPECT_CALL(*mComposer, getCapabilities())
205 .WillOnce(Return(std::vector<IComposer::Capability>()));
206 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
207 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800208
Lloyd Piquee39cad22017-12-20 17:01:29 -0800209 Mock::VerifyAndClear(mComposer);
210}
211
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800212void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800213 // This setup is only expected once per test.
214 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
215
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800216 mConsumer = new mock::GraphicBufferConsumer();
217 mProducer = new mock::GraphicBufferProducer();
218
219 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
220 *outProducer = mProducer;
221 *outConsumer = mConsumer;
222 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800223}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800224
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800225void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800226 // This setup is only expected once per test.
227 ASSERT_TRUE(mNativeWindowSurface == nullptr);
228
Lloyd Pique22098362018-09-13 11:46:49 -0700229 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800230
Lloyd Pique22098362018-09-13 11:46:49 -0700231 mFlinger.setCreateNativeWindowSurface([this](auto) {
232 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
233 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800234}
235
Dominik Laskowski075d3172018-05-24 15:50:06 -0700236bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) {
237 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800238}
239
240bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
241 return mFlinger.mutableTransactionFlags() & flag;
242}
243
244bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700245 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800246}
247
248sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700249 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800250}
251
252bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
253 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
254}
255
256const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
257 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
258}
259
260bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
261 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
262}
263
264const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
265 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
266}
267
268/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800269 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800270 */
271
Dominik Laskowski075d3172018-05-24 15:50:06 -0700272template <typename PhysicalDisplay>
273struct PhysicalDisplayId {};
274
Dominik Laskowski34157762018-10-31 13:07:19 -0700275template <DisplayId::Type displayId>
276using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700277
278struct NoDisplayId {};
279
280template <typename>
281struct IsPhysicalDisplayId : std::bool_constant<false> {};
282
283template <typename PhysicalDisplay>
284struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
285
286template <typename>
287struct DisplayIdGetter;
288
289template <typename PhysicalDisplay>
290struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
291 static std::optional<DisplayId> get() {
292 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
293 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
294 ? HWC_DISPLAY_PRIMARY
295 : HWC_DISPLAY_EXTERNAL);
296 }
297
298 const auto info =
299 parseDisplayIdentificationData(PhysicalDisplay::PORT,
300 PhysicalDisplay::GET_IDENTIFICATION_DATA());
301 return info ? std::make_optional(info->id) : std::nullopt;
302 }
303};
304
Dominik Laskowski34157762018-10-31 13:07:19 -0700305template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700306struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700307 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700308};
309
310template <>
311struct DisplayIdGetter<NoDisplayId> {
312 static std::optional<DisplayId> get() { return {}; }
313};
314
315// DisplayIdType can be:
316// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
317// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
318// 3) NoDisplayId for virtual display without HWC backing.
319template <typename DisplayIdType, int width, int height, Critical critical, Async async,
320 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800321struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700322 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
323
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800324 // The display width and height
325 static constexpr int WIDTH = width;
326 static constexpr int HEIGHT = height;
327
328 static constexpr int GRALLOC_USAGE = grallocUsage;
329
Dominik Laskowski075d3172018-05-24 15:50:06 -0700330 // Whether the display is virtual or physical
331 static constexpr Virtual VIRTUAL =
332 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800333
334 // When creating native window surfaces for the framebuffer, whether those should be critical
335 static constexpr Critical CRITICAL = critical;
336
337 // When creating native window surfaces for the framebuffer, whether those should be async
338 static constexpr Async ASYNC = async;
339
340 // Whether the display should be treated as secure
341 static constexpr Secure SECURE = secure;
342
Dominik Laskowski075d3172018-05-24 15:50:06 -0700343 // Whether the display is primary
344 static constexpr Primary PRIMARY = primary;
345
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800346 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700347 auto injector =
348 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(),
349 static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY));
350
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800351 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700352 injector.setNativeWindow(test->mNativeWindow);
353
354 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800355 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700356 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
357 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
358 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
359 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800360 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
361 .WillRepeatedly(Return(0));
362 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
363 .WillRepeatedly(Return(0));
364 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
365 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700366 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
367 .WillRepeatedly(Return(0));
368
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800369 return injector;
370 }
371
372 // Called by tests to set up any native window creation call expectations.
373 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
374 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
375 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800376
Alec Mouriba013fa2018-10-16 12:43:11 -0700377 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
378 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
379 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
380 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800381 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
382 .WillRepeatedly(Return(0));
383 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
384 .WillRepeatedly(Return(0));
385 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
386 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700387 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
388 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800389 }
390
391 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
392 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
393 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
394 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
395 .WillRepeatedly(Return(NO_ERROR));
396 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
397 .WillRepeatedly(Return(NO_ERROR));
398 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
399 .WillRepeatedly(Return(NO_ERROR));
400 }
401
402 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
403 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
404 }
405};
406
Dominik Laskowski075d3172018-05-24 15:50:06 -0700407template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
408 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800409struct HwcDisplayVariant {
410 // The display id supplied by the HWC
411 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
412
413 // The HWC display type
414 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
415
416 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700417 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700418 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800419
420 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
421 HWC2::Connection connection) {
422 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
423 HotplugEvent{HWC_DISPLAY_ID, connection});
424 }
425
426 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800427 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700428 const auto displayId = DisplayVariant::DISPLAY_ID::get();
429 ASSERT_TRUE(displayId);
430 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
431 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800432 .setHwcDisplayId(HWC_DISPLAY_ID)
433 .setWidth(DisplayVariant::WIDTH)
434 .setHeight(DisplayVariant::HEIGHT)
435 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700436 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800437 .inject(&test->mFlinger, test->mComposer);
438 }
439
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800440 // Called by tests to inject a HWC display setup
441 static void injectHwcDisplay(DisplayTransactionTest* test) {
442 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
443 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
444 Return(Error::NONE)));
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700445 EXPECT_CALL(*test->mComposer,
446 setPowerMode(HWC_DISPLAY_ID,
447 static_cast<Hwc2::IComposerClient::PowerMode>(INIT_POWER_MODE)))
448 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800449 injectHwcDisplayWithNoDefaultCapabilities(test);
450 }
451
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800452 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800453 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
454 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
455 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
456 Return(Error::NONE)));
457 EXPECT_CALL(*test->mComposer,
458 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
459 IComposerClient::Attribute::WIDTH, _))
460 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
461 EXPECT_CALL(*test->mComposer,
462 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
463 IComposerClient::Attribute::HEIGHT, _))
464 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
465 EXPECT_CALL(*test->mComposer,
466 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
467 IComposerClient::Attribute::VSYNC_PERIOD, _))
468 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
469 EXPECT_CALL(*test->mComposer,
470 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
471 IComposerClient::Attribute::DPI_X, _))
472 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
473 EXPECT_CALL(*test->mComposer,
474 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
475 IComposerClient::Attribute::DPI_Y, _))
476 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Ady Abraham7159f572019-10-11 11:10:18 -0700477 EXPECT_CALL(*test->mComposer,
478 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
479 IComposerClient::Attribute::CONFIG_GROUP, _))
480 .WillOnce(DoAll(SetArgPointee<3>(-1), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700481
482 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
483 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
484 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
485 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
486 Return(Error::NONE)));
487 } else {
488 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
489 .WillOnce(Return(Error::UNSUPPORTED));
490 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800491 }
492
493 // Called by tests to set up HWC call expectations
494 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
495 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700496 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800497 }
498};
499
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800500// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
501constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
502 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
503
Dominik Laskowski075d3172018-05-24 15:50:06 -0700504template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800505 Critical critical>
506struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700507 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
508 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
509 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
510 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
511 critical, Async::FALSE, Secure::TRUE,
512 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
513 PhysicalDisplay> {};
514
515template <bool hasIdentificationData>
516struct PrimaryDisplay {
517 static constexpr Primary PRIMARY = Primary::TRUE;
518 static constexpr uint8_t PORT = 255;
519 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
520 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
521};
522
523template <bool hasIdentificationData>
524struct ExternalDisplay {
525 static constexpr Primary PRIMARY = Primary::FALSE;
526 static constexpr uint8_t PORT = 254;
527 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
528 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
529};
530
531struct TertiaryDisplay {
532 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800533 static constexpr uint8_t PORT = 253;
534 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700535};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800536
537// A primary display is a physical display that is critical
538using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700539 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800540
541// An external display is physical display that is not critical.
542using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700543 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800544
545using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700546 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800547
548// A virtual display not supported by the HWC.
549constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
550
551template <int width, int height, Secure secure>
552struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700553 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
554 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
555 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
556 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
557
558 static void injectHwcDisplay(DisplayTransactionTest*) {}
559
560 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
561 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
562 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800563
564 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
565 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
566 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
567 }
568};
569
570// A virtual display supported by the HWC.
571constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
572
573template <int width, int height, Secure secure>
574struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700575 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
576 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
577 HwcDisplayVariant<
578 1010, HWC2::DisplayType::Virtual,
579 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
580 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
581 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
582 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800583 using Self = HwcVirtualDisplayVariant<width, height, secure>;
584
585 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
586 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
587 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
588 }
589
590 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
591 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
592 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
593 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
594 }
595};
596
597// For this variant, SurfaceFlinger should not configure itself with wide
598// display support, so the display should not be configured for wide-color
599// support.
600struct WideColorSupportNotConfiguredVariant {
601 static constexpr bool WIDE_COLOR_SUPPORTED = false;
602
603 static void injectConfigChange(DisplayTransactionTest* test) {
604 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700605 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800606 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800607 }
608
609 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
610 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
611 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
612 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
613 }
614};
615
616// For this variant, SurfaceFlinger should configure itself with wide display
617// support, and the display should respond with an non-empty list of supported
618// color modes. Wide-color support should be configured.
619template <typename Display>
620struct WideColorP3ColorimetricSupportedVariant {
621 static constexpr bool WIDE_COLOR_SUPPORTED = true;
622
623 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700624 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800625 test->mFlinger.mutableHasWideColorDisplay() = true;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800626 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800627 }
628
629 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800630 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
631
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800632 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
633 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
634 Return(Error::NONE)));
635 EXPECT_CALL(*test->mComposer,
636 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
637 .WillOnce(DoAll(SetArgPointee<2>(
638 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
639 Return(Error::NONE)));
640 EXPECT_CALL(*test->mComposer,
641 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
642 RenderIntent::COLORIMETRIC))
643 .WillOnce(Return(Error::NONE));
644 }
645};
646
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800647// For this variant, SurfaceFlinger should configure itself with wide display
648// support, but the display should respond with an empty list of supported color
649// modes. Wide-color support for the display should not be configured.
650template <typename Display>
651struct WideColorNotSupportedVariant {
652 static constexpr bool WIDE_COLOR_SUPPORTED = false;
653
654 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700655 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800656 test->mFlinger.mutableHasWideColorDisplay() = true;
657 }
658
659 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
660 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
661 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700662 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800663 }
664};
665
666// For this variant, the display is not a HWC display, so no HDR support should
667// be configured.
668struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800669 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800670 static constexpr bool HDR10_SUPPORTED = false;
671 static constexpr bool HDR_HLG_SUPPORTED = false;
672 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
673 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
674 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
675 }
676};
677
Valerie Haue9e843a2018-12-18 13:39:23 -0800678template <typename Display>
679struct Hdr10PlusSupportedVariant {
680 static constexpr bool HDR10_PLUS_SUPPORTED = true;
681 static constexpr bool HDR10_SUPPORTED = true;
682 static constexpr bool HDR_HLG_SUPPORTED = false;
683 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
684 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
685 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
686 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
687 Hdr::HDR10_PLUS,
688 Hdr::HDR10,
689 })),
690 Return(Error::NONE)));
691 }
692};
693
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800694// For this variant, the composer should respond with a non-empty list of HDR
695// modes containing HDR10, so HDR10 support should be configured.
696template <typename Display>
697struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800698 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800699 static constexpr bool HDR10_SUPPORTED = true;
700 static constexpr bool HDR_HLG_SUPPORTED = false;
701 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
702 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
703 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
704 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
705 Return(Error::NONE)));
706 }
707};
708
709// For this variant, the composer should respond with a non-empty list of HDR
710// modes containing HLG, so HLG support should be configured.
711template <typename Display>
712struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800713 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800714 static constexpr bool HDR10_SUPPORTED = false;
715 static constexpr bool HDR_HLG_SUPPORTED = true;
716 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
717 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
718 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
719 .WillOnce(
720 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
721 }
722};
723
724// For this variant, the composer should respond with a non-empty list of HDR
725// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
726template <typename Display>
727struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800728 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800729 static constexpr bool HDR10_SUPPORTED = false;
730 static constexpr bool HDR_HLG_SUPPORTED = false;
731 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
732 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
733 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
734 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
735 Return(Error::NONE)));
736 }
737};
738
739// For this variant, the composer should respond with am empty list of HDR
740// modes, so no HDR support should be configured.
741template <typename Display>
742struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800743 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800744 static constexpr bool HDR10_SUPPORTED = false;
745 static constexpr bool HDR_HLG_SUPPORTED = false;
746 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
747 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
748 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
749 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
750 }
751};
752
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700753struct NonHwcPerFrameMetadataSupportVariant {
754 static constexpr int PER_FRAME_METADATA_KEYS = 0;
755 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800756 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700757 }
758};
759
760template <typename Display>
761struct NoPerFrameMetadataSupportVariant {
762 static constexpr int PER_FRAME_METADATA_KEYS = 0;
763 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800764 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
765 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700766 }
767};
768
769template <typename Display>
770struct Smpte2086PerFrameMetadataSupportVariant {
771 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
772 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800773 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
774 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800775 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
776 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
777 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
778 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
779 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
780 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
781 PerFrameMetadataKey::WHITE_POINT_X,
782 PerFrameMetadataKey::WHITE_POINT_Y,
783 PerFrameMetadataKey::MAX_LUMINANCE,
784 PerFrameMetadataKey::MIN_LUMINANCE,
785 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700786 }
787};
788
789template <typename Display>
790struct Cta861_3_PerFrameMetadataSupportVariant {
791 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
792 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800793 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
794 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800795 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
796 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
797 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700798 }
799};
800
Valerie Haue9e843a2018-12-18 13:39:23 -0800801template <typename Display>
802struct Hdr10_Plus_PerFrameMetadataSupportVariant {
803 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
804 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
805 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
806 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
807 PerFrameMetadataKey::HDR10_PLUS_SEI,
808 })));
809 }
810};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800811/* ------------------------------------------------------------------------
812 * Typical display configurations to test
813 */
814
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700815template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
816 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800817struct Case {
818 using Display = DisplayPolicy;
819 using WideColorSupport = WideColorSupportPolicy;
820 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700821 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800822};
823
824using SimplePrimaryDisplayCase =
825 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700826 HdrNotSupportedVariant<PrimaryDisplayVariant>,
827 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800828using SimpleExternalDisplayCase =
829 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700830 HdrNotSupportedVariant<ExternalDisplayVariant>,
831 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800832using SimpleTertiaryDisplayCase =
833 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700834 HdrNotSupportedVariant<TertiaryDisplayVariant>,
835 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800836using NonHwcVirtualDisplayCase =
837 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700838 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
839 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800840using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
841using HwcVirtualDisplayCase =
842 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700843 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800844 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800845using WideColorP3ColorimetricDisplayCase =
846 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700847 HdrNotSupportedVariant<PrimaryDisplayVariant>,
848 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800849using Hdr10PlusDisplayCase =
850 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
851 Hdr10SupportedVariant<PrimaryDisplayVariant>,
852 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800853using Hdr10DisplayCase =
854 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700855 Hdr10SupportedVariant<PrimaryDisplayVariant>,
856 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800857using HdrHlgDisplayCase =
858 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700859 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
860 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800861using HdrDolbyVisionDisplayCase =
862 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700863 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
864 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
865using HdrSmpte2086DisplayCase =
866 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
867 HdrNotSupportedVariant<PrimaryDisplayVariant>,
868 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
869using HdrCta861_3_DisplayCase =
870 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
871 HdrNotSupportedVariant<PrimaryDisplayVariant>,
872 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700873
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800874/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800875 *
876 * SurfaceFlinger::onHotplugReceived
877 */
878
879TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
880 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700881 constexpr hwc2_display_t hwcDisplayId1 = 456;
882 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800883
884 // --------------------------------------------------------------------
885 // Preconditions
886
887 // Set the current sequence id for accepted events
888 mFlinger.mutableComposerSequenceId() = currentSequenceId;
889
890 // Set the main thread id so that the current thread does not appear to be
891 // the main thread.
892 mFlinger.mutableMainThreadId() = std::thread::id();
893
894 // --------------------------------------------------------------------
895 // Call Expectations
896
897 // We expect invalidate() to be invoked once to trigger display transaction
898 // processing.
899 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
900
901 // --------------------------------------------------------------------
902 // Invocation
903
904 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700905 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
906 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800907
908 // --------------------------------------------------------------------
909 // Postconditions
910
911 // The display transaction needed flag should be set.
912 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
913
914 // All events should be in the pending event queue.
915 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
916 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700917 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800918 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700919 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800920 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
921}
922
923TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
924 constexpr int currentSequenceId = 123;
925 constexpr int otherSequenceId = 321;
926 constexpr hwc2_display_t displayId = 456;
927
928 // --------------------------------------------------------------------
929 // Preconditions
930
931 // Set the current sequence id for accepted events
932 mFlinger.mutableComposerSequenceId() = currentSequenceId;
933
934 // Set the main thread id so that the current thread does not appear to be
935 // the main thread.
936 mFlinger.mutableMainThreadId() = std::thread::id();
937
938 // --------------------------------------------------------------------
939 // Call Expectations
940
941 // We do not expect any calls to invalidate().
942 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
943
944 // --------------------------------------------------------------------
945 // Invocation
946
947 // Call with an unexpected sequence id
948 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
949
950 // --------------------------------------------------------------------
951 // Postconditions
952
953 // The display transaction needed flag should not be set
954 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
955
956 // There should be no pending events
957 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
958}
959
960TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
961 constexpr int currentSequenceId = 123;
962 constexpr hwc2_display_t displayId1 = 456;
963
964 // --------------------------------------------------------------------
965 // Note:
966 // --------------------------------------------------------------------
967 // This test case is a bit tricky. We want to verify that
968 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
969 // don't really want to provide coverage for everything the later function
970 // does as there are specific tests for it.
971 // --------------------------------------------------------------------
972
973 // --------------------------------------------------------------------
974 // Preconditions
975
976 // Set the current sequence id for accepted events
977 mFlinger.mutableComposerSequenceId() = currentSequenceId;
978
979 // Set the main thread id so that the current thread does appear to be the
980 // main thread.
981 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
982
983 // --------------------------------------------------------------------
984 // Call Expectations
985
986 // We expect invalidate() to be invoked once to trigger display transaction
987 // processing.
988 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
989
990 // --------------------------------------------------------------------
991 // Invocation
992
993 // Simulate a disconnect on a display id that is not connected. This should
994 // be enqueued by onHotplugReceived(), and dequeued by
995 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
996 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
997
998 // --------------------------------------------------------------------
999 // Postconditions
1000
1001 // The display transaction needed flag should be set.
1002 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1003
1004 // There should be no event queued on return, as it should have been
1005 // processed.
1006 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1007}
1008
1009/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001010 * SurfaceFlinger::createDisplay
1011 */
1012
1013TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1014 const String8 name("virtual.test");
1015
1016 // --------------------------------------------------------------------
1017 // Call Expectations
1018
1019 // The call should notify the interceptor that a display was created.
1020 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1021
1022 // --------------------------------------------------------------------
1023 // Invocation
1024
1025 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1026
1027 // --------------------------------------------------------------------
1028 // Postconditions
1029
1030 // The display should have been added to the current state
1031 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1032 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001033 EXPECT_TRUE(display.isVirtual());
1034 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001035 EXPECT_EQ(name.string(), display.displayName);
1036
1037 // --------------------------------------------------------------------
1038 // Cleanup conditions
1039
1040 // Destroying the display invalidates the display state.
1041 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1042}
1043
1044TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1045 const String8 name("virtual.test");
1046
1047 // --------------------------------------------------------------------
1048 // Call Expectations
1049
1050 // The call should notify the interceptor that a display was created.
1051 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1052
1053 // --------------------------------------------------------------------
1054 // Invocation
1055
1056 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1057
1058 // --------------------------------------------------------------------
1059 // Postconditions
1060
1061 // The display should have been added to the current state
1062 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1063 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001064 EXPECT_TRUE(display.isVirtual());
1065 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001066 EXPECT_EQ(name.string(), display.displayName);
1067
1068 // --------------------------------------------------------------------
1069 // Cleanup conditions
1070
1071 // Destroying the display invalidates the display state.
1072 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1073}
1074
1075/* ------------------------------------------------------------------------
1076 * SurfaceFlinger::destroyDisplay
1077 */
1078
1079TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1080 using Case = NonHwcVirtualDisplayCase;
1081
1082 // --------------------------------------------------------------------
1083 // Preconditions
1084
1085 // A virtual display exists
1086 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1087 existing.inject();
1088
1089 // --------------------------------------------------------------------
1090 // Call Expectations
1091
1092 // The call should notify the interceptor that a display was created.
1093 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1094
1095 // Destroying the display invalidates the display state.
1096 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1097
1098 // --------------------------------------------------------------------
1099 // Invocation
1100
1101 mFlinger.destroyDisplay(existing.token());
1102
1103 // --------------------------------------------------------------------
1104 // Postconditions
1105
1106 // The display should have been removed from the current state
1107 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1108
1109 // Ths display should still exist in the drawing state
1110 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1111
1112 // The display transaction needed flasg should be set
1113 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1114}
1115
1116TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1117 // --------------------------------------------------------------------
1118 // Preconditions
1119
1120 sp<BBinder> displayToken = new BBinder();
1121
1122 // --------------------------------------------------------------------
1123 // Invocation
1124
1125 mFlinger.destroyDisplay(displayToken);
1126}
1127
1128/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001129 * SurfaceFlinger::resetDisplayState
1130 */
1131
1132TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1133 using Case = NonHwcVirtualDisplayCase;
1134
1135 // --------------------------------------------------------------------
1136 // Preconditions
1137
1138 // vsync is enabled and available
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001139 mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = true;
1140 mFlinger.scheduler()->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001141
1142 // A display exists
1143 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1144 existing.inject();
1145
1146 // --------------------------------------------------------------------
1147 // Call Expectations
1148
1149 // The call disable vsyncs
1150 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1151
Lloyd Pique41be5d22018-06-21 13:11:48 -07001152 // The call ends any display resyncs
1153 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1154
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001155 // --------------------------------------------------------------------
1156 // Invocation
1157
1158 mFlinger.resetDisplayState();
1159
1160 // --------------------------------------------------------------------
1161 // Postconditions
1162
1163 // vsyncs should be off and not available.
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001164 EXPECT_FALSE(mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled());
1165 EXPECT_FALSE(mFlinger.scheduler()->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001166
1167 // The display should have been removed from the display map.
1168 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1169
1170 // The display should still exist in the current state
1171 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1172
1173 // The display should have been removed from the drawing state
1174 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1175}
1176
1177/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001178 * DisplayDevice::GetBestColorMode
1179 */
1180class GetBestColorModeTest : public DisplayTransactionTest {
1181public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001182 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001183
Valerie Hau9758ae02018-10-09 16:05:09 -07001184 GetBestColorModeTest()
1185 : DisplayTransactionTest(),
Dominik Laskowski075d3172018-05-24 15:50:06 -07001186 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */,
1187 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001188
1189 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1190
1191 void addHwcColorModesMapping(ui::ColorMode colorMode,
1192 std::vector<ui::RenderIntent> renderIntents) {
1193 mHwcColorModes[colorMode] = renderIntents;
1194 }
1195
1196 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1197
1198 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1199
1200 void getBestColorMode() {
1201 mInjector.setHwcColorModes(mHwcColorModes);
1202 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001203 mInjector.setNativeWindow(mNativeWindow);
1204
1205 // Creating a DisplayDevice requires getting default dimensions from the
1206 // native window.
1207 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1208 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1209 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1210 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001211 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1212 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1213 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07001214 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001215 auto displayDevice = mInjector.inject();
1216
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001217 displayDevice->getCompositionDisplay()
1218 ->getDisplayColorProfile()
1219 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1220 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001221 }
1222
1223 ui::Dataspace mOutDataspace;
1224 ui::ColorMode mOutColorMode;
1225 ui::RenderIntent mOutRenderIntent;
1226
1227private:
1228 ui::Dataspace mInputDataspace;
1229 ui::RenderIntent mInputRenderIntent;
1230 bool mHasWideColorGamut = false;
1231 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1232 FakeDisplayDeviceInjector mInjector;
1233};
1234
1235TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1236 addHwcColorModesMapping(ui::ColorMode::SRGB,
1237 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1238 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1239 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1240 setHasWideColorGamut(true);
1241
1242 getBestColorMode();
1243
Peiyong Lin14724e62018-12-05 07:27:30 -08001244 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001245 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1246 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1247}
1248
1249TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1250 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1251 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1252 addHwcColorModesMapping(ui::ColorMode::SRGB,
1253 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1254 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1255 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1256 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1257 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1258 setHasWideColorGamut(true);
1259
1260 getBestColorMode();
1261
1262 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1263 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1264 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1265}
1266
1267TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1268 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1269 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1270 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1271 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1272 setHasWideColorGamut(true);
1273
1274 getBestColorMode();
1275
1276 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1277 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1278 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1279}
1280
1281/* ------------------------------------------------------------------------
Lloyd Pique33050472019-12-19 17:12:44 -08001282 * DisplayDevice::setProjection
1283 */
1284
1285class DisplayDeviceSetProjectionTest : public DisplayTransactionTest {
1286public:
1287 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
1288 static constexpr bool DEFAULT_DISPLAY_IS_VIRTUAL = false;
1289 static constexpr bool DEFAULT_DISPLAY_IS_PRIMARY = true;
1290 static constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1080; // arbitrary
1291 static constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1920; // arbitrary
1292
1293 static constexpr int32_t TRANSFORM_FLAGS_ROT_0 = 0;
1294 static constexpr int32_t TRANSFORM_FLAGS_ROT_90 = HAL_TRANSFORM_ROT_90;
1295 static constexpr int32_t TRANSFORM_FLAGS_ROT_180 = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V;
1296 static constexpr int32_t TRANSFORM_FLAGS_ROT_270 =
1297 HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
1298
1299 DisplayDeviceSetProjectionTest(ui::Size flingerDisplaySize, ui::Size hardwareDisplaySize,
1300 ui::Rotation physicalOrientation)
1301 : mFlingerDisplaySize(flingerDisplaySize),
1302 mHardwareDisplaySize(hardwareDisplaySize),
1303 mPhysicalOrientation(physicalOrientation),
1304 mDisplayDevice(createDisplayDevice()) {}
1305
1306 sp<DisplayDevice> createDisplayDevice() {
1307 // The DisplayDevice is required to have a framebuffer (behind the
1308 // ANativeWindow interface) which uses the actual hardware display
1309 // size.
1310 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1311 .WillRepeatedly(DoAll(SetArgPointee<1>(mHardwareDisplaySize.width), Return(0)));
1312 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1313 .WillRepeatedly(DoAll(SetArgPointee<1>(mHardwareDisplaySize.height), Return(0)));
1314 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT));
1315 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT));
1316 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64));
1317 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT));
1318
1319 return FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, DEFAULT_DISPLAY_IS_VIRTUAL,
1320 DEFAULT_DISPLAY_IS_PRIMARY)
1321 .setNativeWindow(mNativeWindow)
1322 .setPhysicalOrientation(mPhysicalOrientation)
1323 .inject();
1324 }
1325
1326 ui::Size SwapWH(const ui::Size size) const { return ui::Size(size.height, size.width); }
1327
1328 void setProjectionForRotation0() {
1329 // A logical rotation of 0 uses the SurfaceFlinger display size
1330 mDisplayDevice->setProjection(ui::ROTATION_0, Rect(mFlingerDisplaySize),
1331 Rect(mFlingerDisplaySize));
1332 }
1333
1334 void setProjectionForRotation90() {
1335 // A logical rotation of 90 uses the SurfaceFlinger display size with
1336 // the width/height swapped.
1337 mDisplayDevice->setProjection(ui::ROTATION_90, Rect(SwapWH(mFlingerDisplaySize)),
1338 Rect(SwapWH(mFlingerDisplaySize)));
1339 }
1340
1341 void setProjectionForRotation180() {
1342 // A logical rotation of 180 uses the SurfaceFlinger display size
1343 mDisplayDevice->setProjection(ui::ROTATION_180, Rect(mFlingerDisplaySize),
1344 Rect(mFlingerDisplaySize));
1345 }
1346
1347 void setProjectionForRotation270() {
1348 // A logical rotation of 270 uses the SurfaceFlinger display size with
1349 // the width/height swapped.
1350 mDisplayDevice->setProjection(ui::ROTATION_270, Rect(SwapWH(mFlingerDisplaySize)),
1351 Rect(SwapWH(mFlingerDisplaySize)));
1352 }
1353
1354 void expectStateForHardwareTransform0() {
1355 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1356 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_0, mHardwareDisplaySize.width,
1357 mHardwareDisplaySize.height),
1358 compositionState.transform);
1359 EXPECT_EQ(TRANSFORM_FLAGS_ROT_0, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001360 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1361 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001362 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1363 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1364 EXPECT_EQ(false, compositionState.needsFiltering);
1365 }
1366
1367 void expectStateForHardwareTransform90() {
1368 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1369 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width,
1370 mHardwareDisplaySize.height),
1371 compositionState.transform);
1372 EXPECT_EQ(TRANSFORM_FLAGS_ROT_90, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001373 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1374 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001375 // For 90, the frame and viewport have the hardware display size width and height swapped
1376 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1377 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1378 EXPECT_EQ(false, compositionState.needsFiltering);
1379 }
1380
1381 void expectStateForHardwareTransform180() {
1382 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1383 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width,
1384 mHardwareDisplaySize.height),
1385 compositionState.transform);
1386 EXPECT_EQ(TRANSFORM_FLAGS_ROT_180, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001387 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1388 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001389 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1390 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1391 EXPECT_EQ(false, compositionState.needsFiltering);
1392 }
1393
1394 void expectStateForHardwareTransform270() {
1395 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1396 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width,
1397 mHardwareDisplaySize.height),
1398 compositionState.transform);
1399 EXPECT_EQ(TRANSFORM_FLAGS_ROT_270, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001400 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1401 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001402 // For 270, the frame and viewport have the hardware display size width and height swapped
1403 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1404 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1405 EXPECT_EQ(false, compositionState.needsFiltering);
1406 }
1407
1408 const ui::Size mFlingerDisplaySize;
1409 const ui::Size mHardwareDisplaySize;
1410 const ui::Rotation mPhysicalOrientation;
1411 const sp<DisplayDevice> mDisplayDevice;
1412};
1413
1414struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest {
1415 DisplayDeviceSetProjectionTest_Installed0()
1416 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1417 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1418 ui::ROTATION_0) {}
1419};
1420
1421TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) {
1422 setProjectionForRotation0();
1423 expectStateForHardwareTransform0();
1424}
1425
1426TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) {
1427 setProjectionForRotation90();
1428 expectStateForHardwareTransform90();
1429}
1430
1431TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) {
1432 setProjectionForRotation180();
1433 expectStateForHardwareTransform180();
1434}
1435
1436TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) {
1437 setProjectionForRotation270();
1438 expectStateForHardwareTransform270();
1439}
1440
1441struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest {
1442 DisplayDeviceSetProjectionTest_Installed90()
1443 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1444 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1445 ui::ROTATION_90) {}
1446};
1447
1448TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) {
1449 setProjectionForRotation0();
1450 expectStateForHardwareTransform90();
1451}
1452
1453TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) {
1454 setProjectionForRotation90();
1455 expectStateForHardwareTransform180();
1456}
1457
1458TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) {
1459 setProjectionForRotation180();
1460 expectStateForHardwareTransform270();
1461}
1462
1463TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) {
1464 setProjectionForRotation270();
1465 expectStateForHardwareTransform0();
1466}
1467
1468struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest {
1469 DisplayDeviceSetProjectionTest_Installed180()
1470 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1471 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1472 ui::ROTATION_180) {}
1473};
1474
1475TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) {
1476 setProjectionForRotation0();
1477 expectStateForHardwareTransform180();
1478}
1479
1480TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) {
1481 setProjectionForRotation90();
1482 expectStateForHardwareTransform270();
1483}
1484
1485TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) {
1486 setProjectionForRotation180();
1487 expectStateForHardwareTransform0();
1488}
1489
1490TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) {
1491 setProjectionForRotation270();
1492 expectStateForHardwareTransform90();
1493}
1494
1495struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest {
1496 DisplayDeviceSetProjectionTest_Installed270()
1497 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1498 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1499 ui::ROTATION_270) {}
1500};
1501
1502TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) {
1503 setProjectionForRotation0();
1504 expectStateForHardwareTransform270();
1505}
1506
1507TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) {
1508 setProjectionForRotation90();
1509 expectStateForHardwareTransform0();
1510}
1511
1512TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) {
1513 setProjectionForRotation180();
1514 expectStateForHardwareTransform90();
1515}
1516
1517TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) {
1518 setProjectionForRotation270();
1519 expectStateForHardwareTransform180();
1520}
1521
1522/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001523 * SurfaceFlinger::getDisplayNativePrimaries
1524 */
1525
1526class GetDisplayNativePrimaries : public DisplayTransactionTest {
1527public:
1528 GetDisplayNativePrimaries();
1529 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1530 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1531
1532private:
1533 static constexpr float mStartingTestValue = 1.0f;
1534};
1535
1536GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1537 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1538 injectFakeNativeWindowSurfaceFactory();
1539}
1540
1541void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1542 ui::DisplayPrimaries& primaries) {
1543 float startingVal = mStartingTestValue;
1544 primaries.red.X = startingVal++;
1545 primaries.red.Y = startingVal++;
1546 primaries.red.Z = startingVal++;
1547 primaries.green.X = startingVal++;
1548 primaries.green.Y = startingVal++;
1549 primaries.green.Z = startingVal++;
1550 primaries.blue.X = startingVal++;
1551 primaries.blue.Y = startingVal++;
1552 primaries.blue.Z = startingVal++;
1553 primaries.white.X = startingVal++;
1554 primaries.white.Y = startingVal++;
1555 primaries.white.Z = startingVal++;
1556}
1557
1558void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1559 const ui::DisplayPrimaries& primaries) {
1560 float startingVal = mStartingTestValue;
1561 EXPECT_EQ(primaries.red.X, startingVal++);
1562 EXPECT_EQ(primaries.red.Y, startingVal++);
1563 EXPECT_EQ(primaries.red.Z, startingVal++);
1564 EXPECT_EQ(primaries.green.X, startingVal++);
1565 EXPECT_EQ(primaries.green.Y, startingVal++);
1566 EXPECT_EQ(primaries.green.Z, startingVal++);
1567 EXPECT_EQ(primaries.blue.X, startingVal++);
1568 EXPECT_EQ(primaries.blue.Y, startingVal++);
1569 EXPECT_EQ(primaries.blue.Z, startingVal++);
1570 EXPECT_EQ(primaries.white.X, startingVal++);
1571 EXPECT_EQ(primaries.white.Y, startingVal++);
1572 EXPECT_EQ(primaries.white.Z, startingVal++);
1573}
1574
1575TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1576 ui::DisplayPrimaries primaries;
1577 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1578}
1579
Daniel Solomon42d04562019-01-20 21:03:19 -08001580TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1581 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1582 injector.inject();
1583 auto internalDisplayToken = injector.token();
1584
1585 ui::DisplayPrimaries expectedPrimaries;
1586 populateDummyDisplayNativePrimaries(expectedPrimaries);
1587 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1588
1589 ui::DisplayPrimaries primaries;
1590 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1591
1592 checkDummyDisplayNativePrimaries(primaries);
1593}
1594
1595TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1596 sp<BBinder> notInternalDisplayToken = new BBinder();
1597
1598 ui::DisplayPrimaries primaries;
1599 populateDummyDisplayNativePrimaries(primaries);
1600 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1601
1602 // Check primaries argument wasn't modified in case of failure
1603 checkDummyDisplayNativePrimaries(primaries);
1604}
1605
1606/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001607 * SurfaceFlinger::setupNewDisplayDeviceInternal
1608 */
1609
1610class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1611public:
1612 template <typename T>
1613 void setupNewDisplayDeviceInternalTest();
1614};
1615
1616template <typename Case>
1617void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1618 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001619 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1620 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001621 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001622
1623 // --------------------------------------------------------------------
1624 // Preconditions
1625
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001626 // Wide color displays support is configured appropriately
1627 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001628
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001629 // The display is setup with the HWC.
1630 Case::Display::injectHwcDisplay(this);
1631
1632 // SurfaceFlinger will use a test-controlled factory for native window
1633 // surfaces.
1634 injectFakeNativeWindowSurfaceFactory();
1635
1636 // --------------------------------------------------------------------
1637 // Call Expectations
1638
1639 // Various native window calls will be made.
1640 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001641 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001642 Case::WideColorSupport::setupComposerCallExpectations(this);
1643 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001644 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001645
1646 // --------------------------------------------------------------------
1647 // Invocation
1648
1649 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001650 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1651 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001652 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1653
Dominik Laskowski075d3172018-05-24 15:50:06 -07001654 auto device =
1655 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1656 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001657
1658 // --------------------------------------------------------------------
1659 // Postconditions
1660
1661 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001662 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1663 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001664 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001665 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001666 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1667 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1668 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001669 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001670 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1671 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1672 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001673 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1674 // remapped, and the test only ever sets up one config. If there were an error
1675 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
Ady Abraham2139f732019-11-13 18:56:40 -08001676 EXPECT_EQ(0, device->getActiveConfig().value());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001677 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1678 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001679}
1680
1681TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1682 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1683}
1684
1685TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1686 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1687}
1688
1689TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1690 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1691}
1692
1693TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001694 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001695
Dominik Laskowski075d3172018-05-24 15:50:06 -07001696 // Insert display data so that the HWC thinks it created the virtual display.
1697 const auto displayId = Case::Display::DISPLAY_ID::get();
1698 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001699 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001700
1701 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001702}
1703
1704TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1705 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1706}
1707
Valerie Haue9e843a2018-12-18 13:39:23 -08001708TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1709 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1710}
1711
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001712TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1713 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1714}
1715
1716TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1717 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1718}
1719
1720TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1721 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1722}
1723
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001724TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1725 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1726}
1727
1728TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1729 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1730}
1731
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001732/* ------------------------------------------------------------------------
1733 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1734 */
1735
1736class HandleTransactionLockedTest : public DisplayTransactionTest {
1737public:
1738 template <typename Case>
1739 void setupCommonPreconditions();
1740
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001741 template <typename Case, bool connected>
1742 static void expectHotplugReceived(mock::EventThread*);
1743
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001744 template <typename Case>
1745 void setupCommonCallExpectationsForConnectProcessing();
1746
1747 template <typename Case>
1748 void setupCommonCallExpectationsForDisconnectProcessing();
1749
1750 template <typename Case>
1751 void processesHotplugConnectCommon();
1752
1753 template <typename Case>
1754 void ignoresHotplugConnectCommon();
1755
1756 template <typename Case>
1757 void processesHotplugDisconnectCommon();
1758
1759 template <typename Case>
1760 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1761
1762 template <typename Case>
1763 void verifyPhysicalDisplayIsConnected();
1764
1765 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1766};
1767
1768template <typename Case>
1769void HandleTransactionLockedTest::setupCommonPreconditions() {
1770 // Wide color displays support is configured appropriately
1771 Case::WideColorSupport::injectConfigChange(this);
1772
1773 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1774 injectFakeBufferQueueFactory();
1775
1776 // SurfaceFlinger will use a test-controlled factory for native window
1777 // surfaces.
1778 injectFakeNativeWindowSurfaceFactory();
1779}
1780
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001781template <typename Case, bool connected>
1782void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1783 const auto convert = [](auto physicalDisplayId) {
1784 return std::make_optional(DisplayId{physicalDisplayId});
1785 };
1786
1787 EXPECT_CALL(*eventThread,
1788 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1789 .Times(1);
1790}
1791
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001792template <typename Case>
1793void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1794 Case::Display::setupHwcHotplugCallExpectations(this);
1795
1796 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1797 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1798 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1799 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1800
1801 Case::WideColorSupport::setupComposerCallExpectations(this);
1802 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001803 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001804
1805 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001806 expectHotplugReceived<Case, true>(mEventThread);
1807 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001808}
1809
1810template <typename Case>
1811void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1812 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001813
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001814 expectHotplugReceived<Case, false>(mEventThread);
1815 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001816}
1817
1818template <typename Case>
1819void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1820 // The display device should have been set up in the list of displays.
1821 ASSERT_TRUE(hasDisplayDevice(displayToken));
1822 const auto& device = getDisplayDevice(displayToken);
1823 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001824 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001825
1826 // The display should have been set up in the current display state
1827 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1828 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001829 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1830 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1831 : Case::Display::DISPLAY_ID::get(),
1832 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001833
1834 // The display should have been set up in the drawing display state
1835 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1836 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001837 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1838 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1839 : Case::Display::DISPLAY_ID::get(),
1840 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001841}
1842
1843template <typename Case>
1844void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1845 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001846 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001847
Dominik Laskowski075d3172018-05-24 15:50:06 -07001848 // SF should have a display token.
1849 const auto displayId = Case::Display::DISPLAY_ID::get();
1850 ASSERT_TRUE(displayId);
1851 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1852 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001853
1854 verifyDisplayIsConnected<Case>(displayToken);
1855}
1856
1857void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1858 EXPECT_FALSE(hasDisplayDevice(displayToken));
1859 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1860 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1861}
1862
1863template <typename Case>
1864void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1865 // --------------------------------------------------------------------
1866 // Preconditions
1867
1868 setupCommonPreconditions<Case>();
1869
1870 // A hotplug connect event is enqueued for a display
1871 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001872
1873 // --------------------------------------------------------------------
1874 // Call Expectations
1875
1876 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001877
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001878 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001879
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001880 // --------------------------------------------------------------------
1881 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001882
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001883 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001884
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001885 // --------------------------------------------------------------------
1886 // Postconditions
1887
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001888 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001889
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001890 // --------------------------------------------------------------------
1891 // Cleanup conditions
1892
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001893 EXPECT_CALL(*mComposer,
1894 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001895 .WillOnce(Return(Error::NONE));
1896 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001897}
1898
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001899template <typename Case>
1900void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1901 // --------------------------------------------------------------------
1902 // Preconditions
1903
1904 setupCommonPreconditions<Case>();
1905
1906 // A hotplug connect event is enqueued for a display
1907 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1908
1909 // --------------------------------------------------------------------
1910 // Invocation
1911
1912 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1913
1914 // --------------------------------------------------------------------
1915 // Postconditions
1916
1917 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001918 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001919}
1920
1921template <typename Case>
1922void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1923 // --------------------------------------------------------------------
1924 // Preconditions
1925
1926 setupCommonPreconditions<Case>();
1927
1928 // A hotplug disconnect event is enqueued for a display
1929 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1930
1931 // The display is already completely set up.
1932 Case::Display::injectHwcDisplay(this);
1933 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1934 existing.inject();
1935
1936 // --------------------------------------------------------------------
1937 // Call Expectations
1938
1939 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001940 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1941 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001942
1943 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1944
1945 // --------------------------------------------------------------------
1946 // Invocation
1947
1948 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1949
1950 // --------------------------------------------------------------------
1951 // Postconditions
1952
1953 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001954 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001955
Dominik Laskowski075d3172018-05-24 15:50:06 -07001956 // SF should not have a display token.
1957 const auto displayId = Case::Display::DISPLAY_ID::get();
1958 ASSERT_TRUE(displayId);
1959 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001960
1961 // The existing token should have been removed
1962 verifyDisplayIsNotConnected(existing.token());
1963}
1964
1965TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1966 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1967}
1968
1969TEST_F(HandleTransactionLockedTest,
1970 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1971 // Inject an external display.
1972 ExternalDisplayVariant::injectHwcDisplay(this);
1973
1974 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1975}
1976
1977TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1978 // Inject a primary display.
1979 PrimaryDisplayVariant::injectHwcDisplay(this);
1980
1981 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1982}
1983
1984TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1985 // Inject both a primary and external display.
1986 PrimaryDisplayVariant::injectHwcDisplay(this);
1987 ExternalDisplayVariant::injectHwcDisplay(this);
1988
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001989 // TODO: This is an unnecessary call.
1990 EXPECT_CALL(*mComposer,
1991 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
1992 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
1993 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
1994 Return(Error::NONE)));
1995
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001996 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1997
1998 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1999}
2000
2001TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
2002 // Inject a primary display.
2003 PrimaryDisplayVariant::injectHwcDisplay(this);
2004
2005 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
2006
2007 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
2008}
2009
2010TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
2011 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
2012}
2013
2014TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
2015 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
2016}
2017
2018TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
2019 using Case = SimplePrimaryDisplayCase;
2020
2021 // --------------------------------------------------------------------
2022 // Preconditions
2023
2024 setupCommonPreconditions<Case>();
2025
2026 // A hotplug connect event is enqueued for a display
2027 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
2028 // A hotplug disconnect event is also enqueued for the same display
2029 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
2030
2031 // --------------------------------------------------------------------
2032 // Call Expectations
2033
2034 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2035
2036 setupCommonCallExpectationsForConnectProcessing<Case>();
2037 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2038
2039 EXPECT_CALL(*mComposer,
2040 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2041 .WillOnce(Return(Error::NONE));
2042 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2043
2044 // --------------------------------------------------------------------
2045 // Invocation
2046
2047 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2048
2049 // --------------------------------------------------------------------
2050 // Postconditions
2051
2052 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002053 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002054
Dominik Laskowski075d3172018-05-24 15:50:06 -07002055 // SF should not have a display token.
2056 const auto displayId = Case::Display::DISPLAY_ID::get();
2057 ASSERT_TRUE(displayId);
2058 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002059}
2060
2061TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
2062 using Case = SimplePrimaryDisplayCase;
2063
2064 // --------------------------------------------------------------------
2065 // Preconditions
2066
2067 setupCommonPreconditions<Case>();
2068
2069 // The display is already completely set up.
2070 Case::Display::injectHwcDisplay(this);
2071 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2072 existing.inject();
2073
2074 // A hotplug disconnect event is enqueued for a display
2075 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
2076 // A hotplug connect event is also enqueued for the same display
2077 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
2078
2079 // --------------------------------------------------------------------
2080 // Call Expectations
2081
2082 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2083
2084 setupCommonCallExpectationsForConnectProcessing<Case>();
2085 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2086
2087 // --------------------------------------------------------------------
2088 // Invocation
2089
2090 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2091
2092 // --------------------------------------------------------------------
2093 // Postconditions
2094
2095 // The existing token should have been removed
2096 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07002097 const auto displayId = Case::Display::DISPLAY_ID::get();
2098 ASSERT_TRUE(displayId);
2099 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
2100 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002101
2102 // A new display should be connected in its place
2103
2104 verifyPhysicalDisplayIsConnected<Case>();
2105
2106 // --------------------------------------------------------------------
2107 // Cleanup conditions
2108
2109 EXPECT_CALL(*mComposer,
2110 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2111 .WillOnce(Return(Error::NONE));
2112 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2113}
2114
2115TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
2116 using Case = HwcVirtualDisplayCase;
2117
2118 // --------------------------------------------------------------------
2119 // Preconditions
2120
2121 // The HWC supports at least one virtual display
2122 injectMockComposer(1);
2123
2124 setupCommonPreconditions<Case>();
2125
2126 // A virtual display was added to the current state, and it has a
2127 // surface(producer)
2128 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07002129
Dominik Laskowski075d3172018-05-24 15:50:06 -07002130 DisplayDeviceState state;
2131 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002132
2133 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07002134 state.surface = surface;
2135 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002136
2137 // --------------------------------------------------------------------
2138 // Call Expectations
2139
2140 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
2141 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
2142
2143 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
2144 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
2145 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
2146 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
2147 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
2148 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
2149 Return(NO_ERROR)));
2150 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
2151 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
2152
2153 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
2154
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002155 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002156 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
2157
2158 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
2159 Case::WideColorSupport::setupComposerCallExpectations(this);
2160 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07002161 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002162
2163 // --------------------------------------------------------------------
2164 // Invocation
2165
2166 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2167
2168 // --------------------------------------------------------------------
2169 // Postconditions
2170
2171 // The display device should have been set up in the list of displays.
2172 verifyDisplayIsConnected<Case>(displayToken);
2173
2174 // --------------------------------------------------------------------
2175 // Cleanup conditions
2176
2177 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
2178 .WillOnce(Return(Error::NONE));
2179 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08002180
2181 // Cleanup
2182 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
2183 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002184}
2185
2186TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
2187 using Case = HwcVirtualDisplayCase;
2188
2189 // --------------------------------------------------------------------
2190 // Preconditions
2191
2192 // The HWC supports at least one virtual display
2193 injectMockComposer(1);
2194
2195 setupCommonPreconditions<Case>();
2196
2197 // A virtual display was added to the current state, but it does not have a
2198 // surface.
2199 sp<BBinder> displayToken = new BBinder();
2200
Dominik Laskowski075d3172018-05-24 15:50:06 -07002201 DisplayDeviceState state;
2202 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002203
Dominik Laskowski075d3172018-05-24 15:50:06 -07002204 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002205
2206 // --------------------------------------------------------------------
2207 // Call Expectations
2208
2209 // --------------------------------------------------------------------
2210 // Invocation
2211
2212 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2213
2214 // --------------------------------------------------------------------
2215 // Postconditions
2216
2217 // There will not be a display device set up.
2218 EXPECT_FALSE(hasDisplayDevice(displayToken));
2219
2220 // The drawing display state will be set from the current display state.
2221 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2222 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002223 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002224}
2225
2226TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
2227 using Case = HwcVirtualDisplayCase;
2228
2229 // --------------------------------------------------------------------
2230 // Preconditions
2231
2232 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002233 const auto displayId = Case::Display::DISPLAY_ID::get();
2234 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08002235 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002236 Case::Display::injectHwcDisplay(this);
2237 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2238 existing.inject();
2239 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2240
2241 // --------------------------------------------------------------------
2242 // Call Expectations
2243
2244 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2245
2246 // --------------------------------------------------------------------
2247 // Invocation
2248
2249 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2250
2251 // --------------------------------------------------------------------
2252 // Postconditions
2253
2254 // The existing token should have been removed
2255 verifyDisplayIsNotConnected(existing.token());
2256}
2257
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002258TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2259 using Case = NonHwcVirtualDisplayCase;
2260
2261 constexpr uint32_t oldLayerStack = 0u;
2262 constexpr uint32_t newLayerStack = 123u;
2263
2264 // --------------------------------------------------------------------
2265 // Preconditions
2266
2267 // A display is set up
2268 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2269 display.inject();
2270
2271 // There is a change to the layerStack state
2272 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2273 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2274
2275 // --------------------------------------------------------------------
2276 // Invocation
2277
2278 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2279
2280 // --------------------------------------------------------------------
2281 // Postconditions
2282
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002283 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002284}
2285
2286TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2287 using Case = NonHwcVirtualDisplayCase;
2288
Dominik Laskowski718f9602019-11-09 20:01:35 -08002289 constexpr ui::Rotation oldTransform = ui::ROTATION_0;
2290 constexpr ui::Rotation newTransform = ui::ROTATION_180;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002291
2292 // --------------------------------------------------------------------
2293 // Preconditions
2294
2295 // A display is set up
2296 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2297 display.inject();
2298
2299 // There is a change to the orientation state
2300 display.mutableDrawingDisplayState().orientation = oldTransform;
2301 display.mutableCurrentDisplayState().orientation = newTransform;
2302
2303 // --------------------------------------------------------------------
2304 // Invocation
2305
2306 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2307
2308 // --------------------------------------------------------------------
2309 // Postconditions
2310
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002311 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002312}
2313
2314TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2315 using Case = NonHwcVirtualDisplayCase;
2316
2317 const Rect oldViewport(0, 0, 0, 0);
2318 const Rect newViewport(0, 0, 123, 456);
2319
2320 // --------------------------------------------------------------------
2321 // Preconditions
2322
2323 // A display is set up
2324 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2325 display.inject();
2326
2327 // There is a change to the viewport state
2328 display.mutableDrawingDisplayState().viewport = oldViewport;
2329 display.mutableCurrentDisplayState().viewport = newViewport;
2330
2331 // --------------------------------------------------------------------
2332 // Invocation
2333
2334 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2335
2336 // --------------------------------------------------------------------
2337 // Postconditions
2338
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002339 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002340}
2341
2342TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2343 using Case = NonHwcVirtualDisplayCase;
2344
2345 const Rect oldFrame(0, 0, 0, 0);
2346 const Rect newFrame(0, 0, 123, 456);
2347
2348 // --------------------------------------------------------------------
2349 // Preconditions
2350
2351 // A display is set up
2352 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2353 display.inject();
2354
2355 // There is a change to the viewport state
2356 display.mutableDrawingDisplayState().frame = oldFrame;
2357 display.mutableCurrentDisplayState().frame = newFrame;
2358
2359 // --------------------------------------------------------------------
2360 // Invocation
2361
2362 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2363
2364 // --------------------------------------------------------------------
2365 // Postconditions
2366
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002367 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002368}
2369
2370TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2371 using Case = NonHwcVirtualDisplayCase;
2372
2373 constexpr int oldWidth = 0;
2374 constexpr int oldHeight = 10;
2375 constexpr int newWidth = 123;
2376
2377 // --------------------------------------------------------------------
2378 // Preconditions
2379
2380 // A display is set up
2381 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002382 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002383 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002384 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2385 display.setNativeWindow(nativeWindow);
2386 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002387 // Setup injection expections
2388 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2389 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2390 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2391 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002392 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2393 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2394 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002395 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002396 display.inject();
2397
2398 // There is a change to the viewport state
2399 display.mutableDrawingDisplayState().width = oldWidth;
2400 display.mutableDrawingDisplayState().height = oldHeight;
2401 display.mutableCurrentDisplayState().width = newWidth;
2402 display.mutableCurrentDisplayState().height = oldHeight;
2403
2404 // --------------------------------------------------------------------
2405 // Call Expectations
2406
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002407 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002408
2409 // --------------------------------------------------------------------
2410 // Invocation
2411
2412 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2413}
2414
2415TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2416 using Case = NonHwcVirtualDisplayCase;
2417
2418 constexpr int oldWidth = 0;
2419 constexpr int oldHeight = 10;
2420 constexpr int newHeight = 123;
2421
2422 // --------------------------------------------------------------------
2423 // Preconditions
2424
2425 // A display is set up
2426 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002427 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002428 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002429 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2430 display.setNativeWindow(nativeWindow);
2431 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002432 // Setup injection expections
2433 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2434 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2435 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2436 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002437 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2438 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2439 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002440 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002441 display.inject();
2442
2443 // There is a change to the viewport state
2444 display.mutableDrawingDisplayState().width = oldWidth;
2445 display.mutableDrawingDisplayState().height = oldHeight;
2446 display.mutableCurrentDisplayState().width = oldWidth;
2447 display.mutableCurrentDisplayState().height = newHeight;
2448
2449 // --------------------------------------------------------------------
2450 // Call Expectations
2451
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002452 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002453
2454 // --------------------------------------------------------------------
2455 // Invocation
2456
2457 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2458}
2459
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002460/* ------------------------------------------------------------------------
2461 * SurfaceFlinger::setDisplayStateLocked
2462 */
2463
2464TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2465 // --------------------------------------------------------------------
2466 // Preconditions
2467
2468 // We have an unknown display token not associated with a known display
2469 sp<BBinder> displayToken = new BBinder();
2470
2471 // The requested display state references the unknown display.
2472 DisplayState state;
2473 state.what = DisplayState::eLayerStackChanged;
2474 state.token = displayToken;
2475 state.layerStack = 456;
2476
2477 // --------------------------------------------------------------------
2478 // Invocation
2479
2480 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2481
2482 // --------------------------------------------------------------------
2483 // Postconditions
2484
2485 // The returned flags are empty
2486 EXPECT_EQ(0u, flags);
2487
2488 // The display token still doesn't match anything known.
2489 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2490}
2491
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002492TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2493 using Case = SimplePrimaryDisplayCase;
2494
2495 // --------------------------------------------------------------------
2496 // Preconditions
2497
2498 // A display is already set up
2499 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2500 display.inject();
2501
2502 // No changes are made to the display
2503 DisplayState state;
2504 state.what = 0;
2505 state.token = display.token();
2506
2507 // --------------------------------------------------------------------
2508 // Invocation
2509
2510 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2511
2512 // --------------------------------------------------------------------
2513 // Postconditions
2514
2515 // The returned flags are empty
2516 EXPECT_EQ(0u, flags);
2517}
2518
2519TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2520 using Case = SimplePrimaryDisplayCase;
2521
2522 // --------------------------------------------------------------------
2523 // Preconditions
2524
2525 // A display is already set up
2526 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2527 display.inject();
2528
2529 // There is a surface that can be set.
2530 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2531
2532 // The current display state has the surface set
2533 display.mutableCurrentDisplayState().surface = surface;
2534
2535 // The incoming request sets the same surface
2536 DisplayState state;
2537 state.what = DisplayState::eSurfaceChanged;
2538 state.token = display.token();
2539 state.surface = surface;
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(surface.get(), display.getCurrentDisplayState().surface.get());
2554}
2555
2556TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2557 using Case = SimplePrimaryDisplayCase;
2558
2559 // --------------------------------------------------------------------
2560 // Preconditions
2561
2562 // A display is already set up
2563 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2564 display.inject();
2565
2566 // There is a surface that can be set.
2567 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2568
2569 // The current display state does not have a surface
2570 display.mutableCurrentDisplayState().surface = nullptr;
2571
2572 // The incoming request sets a surface
2573 DisplayState state;
2574 state.what = DisplayState::eSurfaceChanged;
2575 state.token = display.token();
2576 state.surface = surface;
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 layer stack state is set to the new value
2590 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2591}
2592
2593TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2594 using Case = SimplePrimaryDisplayCase;
2595
2596 // --------------------------------------------------------------------
2597 // Preconditions
2598
2599 // A display is already set up
2600 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2601 display.inject();
2602
2603 // The display has a layer stack set
2604 display.mutableCurrentDisplayState().layerStack = 456u;
2605
2606 // The incoming request sets the same layer stack
2607 DisplayState state;
2608 state.what = DisplayState::eLayerStackChanged;
2609 state.token = display.token();
2610 state.layerStack = 456u;
2611
2612 // --------------------------------------------------------------------
2613 // Invocation
2614
2615 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2616
2617 // --------------------------------------------------------------------
2618 // Postconditions
2619
2620 // The returned flags are empty
2621 EXPECT_EQ(0u, flags);
2622
2623 // The current display state is unchanged
2624 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2625}
2626
2627TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2628 using Case = SimplePrimaryDisplayCase;
2629
2630 // --------------------------------------------------------------------
2631 // Preconditions
2632
2633 // A display is set up
2634 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2635 display.inject();
2636
2637 // The display has a layer stack set
2638 display.mutableCurrentDisplayState().layerStack = 654u;
2639
2640 // The incoming request sets a different layer stack
2641 DisplayState state;
2642 state.what = DisplayState::eLayerStackChanged;
2643 state.token = display.token();
2644 state.layerStack = 456u;
2645
2646 // --------------------------------------------------------------------
2647 // Invocation
2648
2649 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2650
2651 // --------------------------------------------------------------------
2652 // Postconditions
2653
2654 // The returned flags indicate a transaction is needed
2655 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2656
2657 // The desired display state has been set to the new value.
2658 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2659}
2660
2661TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2662 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002663 constexpr ui::Rotation initialOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002664 const Rect initialFrame = {1, 2, 3, 4};
2665 const Rect initialViewport = {5, 6, 7, 8};
2666
2667 // --------------------------------------------------------------------
2668 // Preconditions
2669
2670 // A display is set up
2671 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2672 display.inject();
2673
2674 // The current display state projection state is all set
2675 display.mutableCurrentDisplayState().orientation = initialOrientation;
2676 display.mutableCurrentDisplayState().frame = initialFrame;
2677 display.mutableCurrentDisplayState().viewport = initialViewport;
2678
2679 // The incoming request sets the same projection state
2680 DisplayState state;
2681 state.what = DisplayState::eDisplayProjectionChanged;
2682 state.token = display.token();
2683 state.orientation = initialOrientation;
2684 state.frame = initialFrame;
2685 state.viewport = initialViewport;
2686
2687 // --------------------------------------------------------------------
2688 // Invocation
2689
2690 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2691
2692 // --------------------------------------------------------------------
2693 // Postconditions
2694
2695 // The returned flags are empty
2696 EXPECT_EQ(0u, flags);
2697
2698 // The current display state is unchanged
2699 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2700
2701 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2702 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2703}
2704
2705TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2706 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002707 constexpr ui::Rotation initialOrientation = ui::ROTATION_90;
2708 constexpr ui::Rotation desiredOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002709
2710 // --------------------------------------------------------------------
2711 // Preconditions
2712
2713 // A display is set up
2714 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2715 display.inject();
2716
2717 // The current display state has an orientation set
2718 display.mutableCurrentDisplayState().orientation = initialOrientation;
2719
2720 // The incoming request sets a different orientation
2721 DisplayState state;
2722 state.what = DisplayState::eDisplayProjectionChanged;
2723 state.token = display.token();
2724 state.orientation = desiredOrientation;
2725
2726 // --------------------------------------------------------------------
2727 // Invocation
2728
2729 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2730
2731 // --------------------------------------------------------------------
2732 // Postconditions
2733
2734 // The returned flags indicate a transaction is needed
2735 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2736
2737 // The current display state has the new value.
2738 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2739}
2740
2741TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2742 using Case = SimplePrimaryDisplayCase;
2743 const Rect initialFrame = {0, 0, 0, 0};
2744 const Rect desiredFrame = {5, 6, 7, 8};
2745
2746 // --------------------------------------------------------------------
2747 // Preconditions
2748
2749 // A display is set up
2750 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2751 display.inject();
2752
2753 // The current display state does not have a frame
2754 display.mutableCurrentDisplayState().frame = initialFrame;
2755
2756 // The incoming request sets a frame
2757 DisplayState state;
2758 state.what = DisplayState::eDisplayProjectionChanged;
2759 state.token = display.token();
2760 state.frame = desiredFrame;
2761
2762 // --------------------------------------------------------------------
2763 // Invocation
2764
2765 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2766
2767 // --------------------------------------------------------------------
2768 // Postconditions
2769
2770 // The returned flags indicate a transaction is needed
2771 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2772
2773 // The current display state has the new value.
2774 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2775}
2776
2777TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2778 using Case = SimplePrimaryDisplayCase;
2779 const Rect initialViewport = {0, 0, 0, 0};
2780 const Rect desiredViewport = {5, 6, 7, 8};
2781
2782 // --------------------------------------------------------------------
2783 // Preconditions
2784
2785 // A display is set up
2786 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2787 display.inject();
2788
2789 // The current display state does not have a viewport
2790 display.mutableCurrentDisplayState().viewport = initialViewport;
2791
2792 // The incoming request sets a viewport
2793 DisplayState state;
2794 state.what = DisplayState::eDisplayProjectionChanged;
2795 state.token = display.token();
2796 state.viewport = desiredViewport;
2797
2798 // --------------------------------------------------------------------
2799 // Invocation
2800
2801 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2802
2803 // --------------------------------------------------------------------
2804 // Postconditions
2805
2806 // The returned flags indicate a transaction is needed
2807 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2808
2809 // The current display state has the new value.
2810 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2811}
2812
2813TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2814 using Case = SimplePrimaryDisplayCase;
2815 constexpr uint32_t initialWidth = 1024;
2816 constexpr uint32_t initialHeight = 768;
2817
2818 // --------------------------------------------------------------------
2819 // Preconditions
2820
2821 // A display is set up
2822 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2823 display.inject();
2824
2825 // The current display state has a size set
2826 display.mutableCurrentDisplayState().width = initialWidth;
2827 display.mutableCurrentDisplayState().height = initialHeight;
2828
2829 // The incoming request sets the same display size
2830 DisplayState state;
2831 state.what = DisplayState::eDisplaySizeChanged;
2832 state.token = display.token();
2833 state.width = initialWidth;
2834 state.height = initialHeight;
2835
2836 // --------------------------------------------------------------------
2837 // Invocation
2838
2839 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2840
2841 // --------------------------------------------------------------------
2842 // Postconditions
2843
2844 // The returned flags are empty
2845 EXPECT_EQ(0u, flags);
2846
2847 // The current display state is unchanged
2848 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2849 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2850}
2851
2852TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2853 using Case = SimplePrimaryDisplayCase;
2854 constexpr uint32_t initialWidth = 0;
2855 constexpr uint32_t desiredWidth = 1024;
2856
2857 // --------------------------------------------------------------------
2858 // Preconditions
2859
2860 // A display is set up
2861 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2862 display.inject();
2863
2864 // The display does not yet have a width
2865 display.mutableCurrentDisplayState().width = initialWidth;
2866
2867 // The incoming request sets a display width
2868 DisplayState state;
2869 state.what = DisplayState::eDisplaySizeChanged;
2870 state.token = display.token();
2871 state.width = desiredWidth;
2872
2873 // --------------------------------------------------------------------
2874 // Invocation
2875
2876 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2877
2878 // --------------------------------------------------------------------
2879 // Postconditions
2880
2881 // The returned flags indicate a transaction is needed
2882 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2883
2884 // The current display state has the new value.
2885 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2886}
2887
2888TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2889 using Case = SimplePrimaryDisplayCase;
2890 constexpr uint32_t initialHeight = 0;
2891 constexpr uint32_t desiredHeight = 768;
2892
2893 // --------------------------------------------------------------------
2894 // Preconditions
2895
2896 // A display is set up
2897 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2898 display.inject();
2899
2900 // The display does not yet have a height
2901 display.mutableCurrentDisplayState().height = initialHeight;
2902
2903 // The incoming request sets a display height
2904 DisplayState state;
2905 state.what = DisplayState::eDisplaySizeChanged;
2906 state.token = display.token();
2907 state.height = desiredHeight;
2908
2909 // --------------------------------------------------------------------
2910 // Invocation
2911
2912 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2913
2914 // --------------------------------------------------------------------
2915 // Postconditions
2916
2917 // The returned flags indicate a transaction is needed
2918 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2919
2920 // The current display state has the new value.
2921 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2922}
2923
Lloyd Pique86016da2018-03-01 16:09:38 -08002924/* ------------------------------------------------------------------------
2925 * SurfaceFlinger::onInitializeDisplays
2926 */
2927
2928TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2929 using Case = SimplePrimaryDisplayCase;
2930
2931 // --------------------------------------------------------------------
2932 // Preconditions
2933
2934 // A primary display is set up
2935 Case::Display::injectHwcDisplay(this);
2936 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2937 primaryDisplay.inject();
2938
2939 // --------------------------------------------------------------------
2940 // Call Expectations
2941
2942 // We expect the surface interceptor to possibly be used, but we treat it as
2943 // disabled since it is called as a side effect rather than directly by this
2944 // function.
2945 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2946
2947 // We expect a call to get the active display config.
2948 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2949
2950 // We expect invalidate() to be invoked once to trigger display transaction
2951 // processing.
2952 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2953
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002954 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2955
Lloyd Pique86016da2018-03-01 16:09:38 -08002956 // --------------------------------------------------------------------
2957 // Invocation
2958
2959 mFlinger.onInitializeDisplays();
2960
2961 // --------------------------------------------------------------------
2962 // Postconditions
2963
2964 // The primary display should have a current state
2965 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2966 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2967 // The layer stack state should be set to zero
2968 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2969 // The orientation state should be set to zero
Dominik Laskowski718f9602019-11-09 20:01:35 -08002970 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
Lloyd Pique86016da2018-03-01 16:09:38 -08002971
2972 // The frame state should be set to INVALID
2973 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2974
2975 // The viewport state should be set to INVALID
2976 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2977
2978 // The width and height should both be zero
2979 EXPECT_EQ(0u, primaryDisplayState.width);
2980 EXPECT_EQ(0u, primaryDisplayState.height);
2981
2982 // The display should be set to HWC_POWER_MODE_NORMAL
2983 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2984 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2985 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2986
2987 // The display refresh period should be set in the frame tracker.
2988 FrameStats stats;
2989 mFlinger.getAnimFrameTracker().getStats(&stats);
2990 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2991
2992 // The display transaction needed flag should be set.
2993 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2994
2995 // The compositor timing should be set to default values
2996 const auto& compositorTiming = mFlinger.getCompositorTiming();
2997 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2998 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2999 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
3000}
3001
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003002/* ------------------------------------------------------------------------
3003 * SurfaceFlinger::setPowerModeInternal
3004 */
3005
3006// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07003007template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003008struct DozeIsSupportedVariant {
3009 static constexpr bool DOZE_SUPPORTED = true;
3010 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3011 IComposerClient::PowerMode::DOZE;
3012 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3013 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07003014
3015 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3016 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
3017 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
3018 {Hwc2::DisplayCapability::DOZE})),
3019 Return(Error::NONE)));
3020 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003021};
3022
Peiyong Lined531a32018-10-26 18:27:56 -07003023template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003024// Used when we simulate a display that does not support doze.
3025struct DozeNotSupportedVariant {
3026 static constexpr bool DOZE_SUPPORTED = false;
3027 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3028 IComposerClient::PowerMode::ON;
3029 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3030 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07003031
3032 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3033 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
3034 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
3035 Return(Error::NONE)));
3036 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003037};
3038
3039struct EventThreadBaseSupportedVariant {
3040 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
3041 // The event control thread should not be notified.
3042 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
3043
3044 // The event thread should not be notified.
3045 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
3046 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
3047 }
3048};
3049
3050struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
3051 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3052 // These calls are only expected for the primary display.
3053
3054 // Instead expect no calls.
3055 setupEventAndEventControlThreadNoCallExpectations(test);
3056 }
3057
3058 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3059 // These calls are only expected for the primary display.
3060
3061 // Instead expect no calls.
3062 setupEventAndEventControlThreadNoCallExpectations(test);
3063 }
3064};
3065
3066struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
3067 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3068 // The event control thread should be notified to enable vsyncs
3069 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
3070
3071 // The event thread should be notified that the screen was acquired.
3072 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
3073 }
3074
3075 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3076 // There should be a call to setVsyncEnabled(false)
3077 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
3078
3079 // The event thread should not be notified that the screen was released.
3080 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
3081 }
3082};
3083
Lloyd Pique41be5d22018-06-21 13:11:48 -07003084struct DispSyncIsSupportedVariant {
3085 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique41be5d22018-06-21 13:11:48 -07003086 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
3087 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
3088 }
3089
3090 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
3091 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
3092 }
3093};
3094
3095struct DispSyncNotSupportedVariant {
3096 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3097
3098 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3099};
3100
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003101// --------------------------------------------------------------------
3102// Note:
3103//
3104// There are a large number of transitions we could test, however we only test a
3105// selected subset which provides complete test coverage of the implementation.
3106// --------------------------------------------------------------------
3107
3108template <int initialPowerMode, int targetPowerMode>
3109struct TransitionVariantCommon {
3110 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
3111 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
3112
3113 static void verifyPostconditions(DisplayTransactionTest*) {}
3114};
3115
3116struct TransitionOffToOnVariant
3117 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
3118 template <typename Case>
3119 static void setupCallExpectations(DisplayTransactionTest* test) {
3120 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3121 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003122 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003123 Case::setupRepaintEverythingCallExpectations(test);
3124 }
3125
3126 static void verifyPostconditions(DisplayTransactionTest* test) {
3127 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3128 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3129 }
3130};
3131
3132struct TransitionOffToDozeSuspendVariant
3133 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
3134 template <typename Case>
3135 static void setupCallExpectations(DisplayTransactionTest* test) {
3136 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3137 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3138 Case::setupRepaintEverythingCallExpectations(test);
3139 }
3140
3141 static void verifyPostconditions(DisplayTransactionTest* test) {
3142 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3143 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3144 }
3145};
3146
3147struct TransitionOnToOffVariant
3148 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
3149 template <typename Case>
3150 static void setupCallExpectations(DisplayTransactionTest* test) {
3151 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003152 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003153 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3154 }
3155
3156 static void verifyPostconditions(DisplayTransactionTest* test) {
3157 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3158 }
3159};
3160
3161struct TransitionDozeSuspendToOffVariant
3162 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
3163 template <typename Case>
3164 static void setupCallExpectations(DisplayTransactionTest* test) {
3165 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3166 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3167 }
3168
3169 static void verifyPostconditions(DisplayTransactionTest* test) {
3170 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3171 }
3172};
3173
3174struct TransitionOnToDozeVariant
3175 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
3176 template <typename Case>
3177 static void setupCallExpectations(DisplayTransactionTest* test) {
3178 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3179 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3180 }
3181};
3182
3183struct TransitionDozeSuspendToDozeVariant
3184 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
3185 template <typename Case>
3186 static void setupCallExpectations(DisplayTransactionTest* test) {
3187 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003188 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003189 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3190 }
3191};
3192
3193struct TransitionDozeToOnVariant
3194 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
3195 template <typename Case>
3196 static void setupCallExpectations(DisplayTransactionTest* test) {
3197 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3198 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3199 }
3200};
3201
3202struct TransitionDozeSuspendToOnVariant
3203 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
3204 template <typename Case>
3205 static void setupCallExpectations(DisplayTransactionTest* test) {
3206 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003207 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003208 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3209 }
3210};
3211
3212struct TransitionOnToDozeSuspendVariant
3213 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
3214 template <typename Case>
3215 static void setupCallExpectations(DisplayTransactionTest* test) {
3216 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003217 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003218 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3219 }
3220};
3221
3222struct TransitionOnToUnknownVariant
3223 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
3224 template <typename Case>
3225 static void setupCallExpectations(DisplayTransactionTest* test) {
3226 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3227 Case::setupNoComposerPowerModeCallExpectations(test);
3228 }
3229};
3230
3231// --------------------------------------------------------------------
3232// Note:
3233//
3234// Rather than testing the cartesian product of of
3235// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3236// display type, and the other for another display type.
3237// --------------------------------------------------------------------
3238
3239template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003240 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003241struct DisplayPowerCase {
3242 using Display = DisplayVariant;
3243 using Doze = DozeVariant;
3244 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003245 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003246 using Transition = TransitionVariant;
3247
3248 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003249 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003250 auto display = Display::makeFakeExistingDisplayInjector(test);
3251 display.inject();
3252 display.mutableDisplayDevice()->setPowerMode(mode);
3253 return display;
3254 }
3255
3256 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003257 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003258 }
3259
3260 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3261 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3262 }
3263
3264 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3265 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3266 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3267 }
3268
3269 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3270 IComposerClient::PowerMode mode) {
3271 // Any calls to get the active config will return a default value.
3272 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3273 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3274 Return(Error::NONE)));
3275
3276 // Any calls to get whether the display supports dozing will return the value set by the
3277 // policy variant.
3278 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3279 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3280
3281 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3282 }
3283
3284 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3285 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3286 }
3287};
3288
3289// A sample configuration for the primary display.
3290// In addition to having event thread support, we emulate doze support.
3291template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003292using PrimaryDisplayPowerCase =
3293 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3294 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3295 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003296
3297// A sample configuration for the external display.
3298// In addition to not having event thread support, we emulate not having doze
3299// support.
3300template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003301using ExternalDisplayPowerCase =
3302 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3303 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3304 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003305
3306class SetPowerModeInternalTest : public DisplayTransactionTest {
3307public:
3308 template <typename Case>
3309 void transitionDisplayCommon();
3310};
3311
3312template <int PowerMode>
3313struct PowerModeInitialVSyncEnabled : public std::false_type {};
3314
3315template <>
3316struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3317
3318template <>
3319struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3320
3321template <typename Case>
3322void SetPowerModeInternalTest::transitionDisplayCommon() {
3323 // --------------------------------------------------------------------
3324 // Preconditions
3325
Peiyong Lined531a32018-10-26 18:27:56 -07003326 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003327 auto display =
3328 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3329 Case::setInitialPrimaryHWVsyncEnabled(this,
3330 PowerModeInitialVSyncEnabled<
3331 Case::Transition::INITIAL_POWER_MODE>::value);
3332
3333 // --------------------------------------------------------------------
3334 // Call Expectations
3335
3336 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3337 Case::Transition::template setupCallExpectations<Case>(this);
3338
3339 // --------------------------------------------------------------------
3340 // Invocation
3341
3342 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3343 Case::Transition::TARGET_POWER_MODE);
3344
3345 // --------------------------------------------------------------------
3346 // Postconditions
3347
3348 Case::Transition::verifyPostconditions(this);
3349}
3350
3351TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3352 using Case = SimplePrimaryDisplayCase;
3353
3354 // --------------------------------------------------------------------
3355 // Preconditions
3356
3357 // A primary display device is set up
3358 Case::Display::injectHwcDisplay(this);
3359 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3360 display.inject();
3361
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003362 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003363 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3364
3365 // --------------------------------------------------------------------
3366 // Invocation
3367
3368 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3369
3370 // --------------------------------------------------------------------
3371 // Postconditions
3372
3373 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3374}
3375
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003376TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003377 using Case = HwcVirtualDisplayCase;
3378
3379 // --------------------------------------------------------------------
3380 // Preconditions
3381
Dominik Laskowski075d3172018-05-24 15:50:06 -07003382 // Insert display data so that the HWC thinks it created the virtual display.
3383 const auto displayId = Case::Display::DISPLAY_ID::get();
3384 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003385 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003386
3387 // A virtual display device is set up
3388 Case::Display::injectHwcDisplay(this);
3389 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3390 display.inject();
3391
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003392 // The display is set to HWC_POWER_MODE_NORMAL
3393 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003394
3395 // --------------------------------------------------------------------
3396 // Invocation
3397
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003398 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003399
3400 // --------------------------------------------------------------------
3401 // Postconditions
3402
3403 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3404}
3405
3406TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3407 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3408}
3409
3410TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3411 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3412}
3413
3414TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3415 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3416}
3417
3418TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3419 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3420}
3421
3422TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3423 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3424}
3425
3426TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3427 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3428}
3429
3430TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3431 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3432}
3433
3434TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3435 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3436}
3437
3438TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3439 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3440}
3441
3442TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3443 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3444}
3445
3446TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3447 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3448}
3449
3450TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3451 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3452}
3453
3454TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3455 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3456}
3457
3458TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3459 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3460}
3461
3462TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3463 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3464}
3465
3466TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3467 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3468}
3469
3470TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3471 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3472}
3473
3474TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3475 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3476}
3477
3478TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3479 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3480}
3481
3482TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3483 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3484}
3485
Lloyd Piquef58625d2017-12-19 13:22:33 -08003486} // namespace
3487} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08003488
3489// TODO(b/129481165): remove the #pragma below and fix conversion issues
3490#pragma clang diagnostic pop // ignored "-Wconversion"