blob: 9680a17655242842e57b563f654b5942dcd343c4 [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);
1360 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.scissor);
1361 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1362 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1363 EXPECT_EQ(false, compositionState.needsFiltering);
1364 }
1365
1366 void expectStateForHardwareTransform90() {
1367 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1368 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width,
1369 mHardwareDisplaySize.height),
1370 compositionState.transform);
1371 EXPECT_EQ(TRANSFORM_FLAGS_ROT_90, compositionState.orientation);
1372 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.scissor);
1373 // For 90, the frame and viewport have the hardware display size width and height swapped
1374 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1375 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1376 EXPECT_EQ(false, compositionState.needsFiltering);
1377 }
1378
1379 void expectStateForHardwareTransform180() {
1380 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1381 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width,
1382 mHardwareDisplaySize.height),
1383 compositionState.transform);
1384 EXPECT_EQ(TRANSFORM_FLAGS_ROT_180, compositionState.orientation);
1385 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.scissor);
1386 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1387 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1388 EXPECT_EQ(false, compositionState.needsFiltering);
1389 }
1390
1391 void expectStateForHardwareTransform270() {
1392 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1393 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width,
1394 mHardwareDisplaySize.height),
1395 compositionState.transform);
1396 EXPECT_EQ(TRANSFORM_FLAGS_ROT_270, compositionState.orientation);
1397 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.scissor);
1398 // For 270, the frame and viewport have the hardware display size width and height swapped
1399 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1400 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1401 EXPECT_EQ(false, compositionState.needsFiltering);
1402 }
1403
1404 const ui::Size mFlingerDisplaySize;
1405 const ui::Size mHardwareDisplaySize;
1406 const ui::Rotation mPhysicalOrientation;
1407 const sp<DisplayDevice> mDisplayDevice;
1408};
1409
1410struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest {
1411 DisplayDeviceSetProjectionTest_Installed0()
1412 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1413 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1414 ui::ROTATION_0) {}
1415};
1416
1417TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) {
1418 setProjectionForRotation0();
1419 expectStateForHardwareTransform0();
1420}
1421
1422TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) {
1423 setProjectionForRotation90();
1424 expectStateForHardwareTransform90();
1425}
1426
1427TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) {
1428 setProjectionForRotation180();
1429 expectStateForHardwareTransform180();
1430}
1431
1432TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) {
1433 setProjectionForRotation270();
1434 expectStateForHardwareTransform270();
1435}
1436
1437struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest {
1438 DisplayDeviceSetProjectionTest_Installed90()
1439 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1440 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1441 ui::ROTATION_90) {}
1442};
1443
1444TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) {
1445 setProjectionForRotation0();
1446 expectStateForHardwareTransform90();
1447}
1448
1449TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) {
1450 setProjectionForRotation90();
1451 expectStateForHardwareTransform180();
1452}
1453
1454TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) {
1455 setProjectionForRotation180();
1456 expectStateForHardwareTransform270();
1457}
1458
1459TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) {
1460 setProjectionForRotation270();
1461 expectStateForHardwareTransform0();
1462}
1463
1464struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest {
1465 DisplayDeviceSetProjectionTest_Installed180()
1466 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1467 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1468 ui::ROTATION_180) {}
1469};
1470
1471TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) {
1472 setProjectionForRotation0();
1473 expectStateForHardwareTransform180();
1474}
1475
1476TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) {
1477 setProjectionForRotation90();
1478 expectStateForHardwareTransform270();
1479}
1480
1481TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) {
1482 setProjectionForRotation180();
1483 expectStateForHardwareTransform0();
1484}
1485
1486TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) {
1487 setProjectionForRotation270();
1488 expectStateForHardwareTransform90();
1489}
1490
1491struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest {
1492 DisplayDeviceSetProjectionTest_Installed270()
1493 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1494 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1495 ui::ROTATION_270) {}
1496};
1497
1498TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) {
1499 setProjectionForRotation0();
1500 expectStateForHardwareTransform270();
1501}
1502
1503TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) {
1504 setProjectionForRotation90();
1505 expectStateForHardwareTransform0();
1506}
1507
1508TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) {
1509 setProjectionForRotation180();
1510 expectStateForHardwareTransform90();
1511}
1512
1513TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) {
1514 setProjectionForRotation270();
1515 expectStateForHardwareTransform180();
1516}
1517
1518/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001519 * SurfaceFlinger::getDisplayNativePrimaries
1520 */
1521
1522class GetDisplayNativePrimaries : public DisplayTransactionTest {
1523public:
1524 GetDisplayNativePrimaries();
1525 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1526 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1527
1528private:
1529 static constexpr float mStartingTestValue = 1.0f;
1530};
1531
1532GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1533 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1534 injectFakeNativeWindowSurfaceFactory();
1535}
1536
1537void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1538 ui::DisplayPrimaries& primaries) {
1539 float startingVal = mStartingTestValue;
1540 primaries.red.X = startingVal++;
1541 primaries.red.Y = startingVal++;
1542 primaries.red.Z = startingVal++;
1543 primaries.green.X = startingVal++;
1544 primaries.green.Y = startingVal++;
1545 primaries.green.Z = startingVal++;
1546 primaries.blue.X = startingVal++;
1547 primaries.blue.Y = startingVal++;
1548 primaries.blue.Z = startingVal++;
1549 primaries.white.X = startingVal++;
1550 primaries.white.Y = startingVal++;
1551 primaries.white.Z = startingVal++;
1552}
1553
1554void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1555 const ui::DisplayPrimaries& primaries) {
1556 float startingVal = mStartingTestValue;
1557 EXPECT_EQ(primaries.red.X, startingVal++);
1558 EXPECT_EQ(primaries.red.Y, startingVal++);
1559 EXPECT_EQ(primaries.red.Z, startingVal++);
1560 EXPECT_EQ(primaries.green.X, startingVal++);
1561 EXPECT_EQ(primaries.green.Y, startingVal++);
1562 EXPECT_EQ(primaries.green.Z, startingVal++);
1563 EXPECT_EQ(primaries.blue.X, startingVal++);
1564 EXPECT_EQ(primaries.blue.Y, startingVal++);
1565 EXPECT_EQ(primaries.blue.Z, startingVal++);
1566 EXPECT_EQ(primaries.white.X, startingVal++);
1567 EXPECT_EQ(primaries.white.Y, startingVal++);
1568 EXPECT_EQ(primaries.white.Z, startingVal++);
1569}
1570
1571TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1572 ui::DisplayPrimaries primaries;
1573 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1574}
1575
Daniel Solomon42d04562019-01-20 21:03:19 -08001576TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1577 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1578 injector.inject();
1579 auto internalDisplayToken = injector.token();
1580
1581 ui::DisplayPrimaries expectedPrimaries;
1582 populateDummyDisplayNativePrimaries(expectedPrimaries);
1583 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1584
1585 ui::DisplayPrimaries primaries;
1586 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1587
1588 checkDummyDisplayNativePrimaries(primaries);
1589}
1590
1591TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1592 sp<BBinder> notInternalDisplayToken = new BBinder();
1593
1594 ui::DisplayPrimaries primaries;
1595 populateDummyDisplayNativePrimaries(primaries);
1596 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1597
1598 // Check primaries argument wasn't modified in case of failure
1599 checkDummyDisplayNativePrimaries(primaries);
1600}
1601
1602/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001603 * SurfaceFlinger::setupNewDisplayDeviceInternal
1604 */
1605
1606class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1607public:
1608 template <typename T>
1609 void setupNewDisplayDeviceInternalTest();
1610};
1611
1612template <typename Case>
1613void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1614 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001615 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1616 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001617 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001618
1619 // --------------------------------------------------------------------
1620 // Preconditions
1621
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001622 // Wide color displays support is configured appropriately
1623 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001624
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001625 // The display is setup with the HWC.
1626 Case::Display::injectHwcDisplay(this);
1627
1628 // SurfaceFlinger will use a test-controlled factory for native window
1629 // surfaces.
1630 injectFakeNativeWindowSurfaceFactory();
1631
1632 // --------------------------------------------------------------------
1633 // Call Expectations
1634
1635 // Various native window calls will be made.
1636 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001637 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001638 Case::WideColorSupport::setupComposerCallExpectations(this);
1639 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001640 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001641
1642 // --------------------------------------------------------------------
1643 // Invocation
1644
1645 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001646 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1647 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001648 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1649
Dominik Laskowski075d3172018-05-24 15:50:06 -07001650 auto device =
1651 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1652 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001653
1654 // --------------------------------------------------------------------
1655 // Postconditions
1656
1657 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001658 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1659 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001660 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001661 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001662 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1663 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1664 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001665 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001666 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1667 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1668 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001669 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1670 // remapped, and the test only ever sets up one config. If there were an error
1671 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
Ady Abraham2139f732019-11-13 18:56:40 -08001672 EXPECT_EQ(0, device->getActiveConfig().value());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001673 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1674 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001675}
1676
1677TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1678 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1679}
1680
1681TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1682 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1683}
1684
1685TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1686 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1687}
1688
1689TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001690 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001691
Dominik Laskowski075d3172018-05-24 15:50:06 -07001692 // Insert display data so that the HWC thinks it created the virtual display.
1693 const auto displayId = Case::Display::DISPLAY_ID::get();
1694 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001695 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001696
1697 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001698}
1699
1700TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1701 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1702}
1703
Valerie Haue9e843a2018-12-18 13:39:23 -08001704TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1705 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1706}
1707
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001708TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1709 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1710}
1711
1712TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1713 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1714}
1715
1716TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1717 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1718}
1719
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001720TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1721 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1722}
1723
1724TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1725 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1726}
1727
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001728/* ------------------------------------------------------------------------
1729 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1730 */
1731
1732class HandleTransactionLockedTest : public DisplayTransactionTest {
1733public:
1734 template <typename Case>
1735 void setupCommonPreconditions();
1736
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001737 template <typename Case, bool connected>
1738 static void expectHotplugReceived(mock::EventThread*);
1739
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001740 template <typename Case>
1741 void setupCommonCallExpectationsForConnectProcessing();
1742
1743 template <typename Case>
1744 void setupCommonCallExpectationsForDisconnectProcessing();
1745
1746 template <typename Case>
1747 void processesHotplugConnectCommon();
1748
1749 template <typename Case>
1750 void ignoresHotplugConnectCommon();
1751
1752 template <typename Case>
1753 void processesHotplugDisconnectCommon();
1754
1755 template <typename Case>
1756 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1757
1758 template <typename Case>
1759 void verifyPhysicalDisplayIsConnected();
1760
1761 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1762};
1763
1764template <typename Case>
1765void HandleTransactionLockedTest::setupCommonPreconditions() {
1766 // Wide color displays support is configured appropriately
1767 Case::WideColorSupport::injectConfigChange(this);
1768
1769 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1770 injectFakeBufferQueueFactory();
1771
1772 // SurfaceFlinger will use a test-controlled factory for native window
1773 // surfaces.
1774 injectFakeNativeWindowSurfaceFactory();
1775}
1776
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001777template <typename Case, bool connected>
1778void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1779 const auto convert = [](auto physicalDisplayId) {
1780 return std::make_optional(DisplayId{physicalDisplayId});
1781 };
1782
1783 EXPECT_CALL(*eventThread,
1784 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1785 .Times(1);
1786}
1787
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001788template <typename Case>
1789void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1790 Case::Display::setupHwcHotplugCallExpectations(this);
1791
1792 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1793 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1794 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1795 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1796
1797 Case::WideColorSupport::setupComposerCallExpectations(this);
1798 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001799 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001800
1801 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001802 expectHotplugReceived<Case, true>(mEventThread);
1803 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001804}
1805
1806template <typename Case>
1807void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1808 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001809
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001810 expectHotplugReceived<Case, false>(mEventThread);
1811 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001812}
1813
1814template <typename Case>
1815void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1816 // The display device should have been set up in the list of displays.
1817 ASSERT_TRUE(hasDisplayDevice(displayToken));
1818 const auto& device = getDisplayDevice(displayToken);
1819 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001820 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001821
1822 // The display should have been set up in the current display state
1823 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1824 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001825 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1826 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1827 : Case::Display::DISPLAY_ID::get(),
1828 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001829
1830 // The display should have been set up in the drawing display state
1831 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1832 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001833 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1834 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1835 : Case::Display::DISPLAY_ID::get(),
1836 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001837}
1838
1839template <typename Case>
1840void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1841 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001842 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001843
Dominik Laskowski075d3172018-05-24 15:50:06 -07001844 // SF should have a display token.
1845 const auto displayId = Case::Display::DISPLAY_ID::get();
1846 ASSERT_TRUE(displayId);
1847 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1848 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001849
1850 verifyDisplayIsConnected<Case>(displayToken);
1851}
1852
1853void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1854 EXPECT_FALSE(hasDisplayDevice(displayToken));
1855 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1856 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1857}
1858
1859template <typename Case>
1860void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1861 // --------------------------------------------------------------------
1862 // Preconditions
1863
1864 setupCommonPreconditions<Case>();
1865
1866 // A hotplug connect event is enqueued for a display
1867 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001868
1869 // --------------------------------------------------------------------
1870 // Call Expectations
1871
1872 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001873
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001874 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001875
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001876 // --------------------------------------------------------------------
1877 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001878
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001879 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001880
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001881 // --------------------------------------------------------------------
1882 // Postconditions
1883
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001884 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001885
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001886 // --------------------------------------------------------------------
1887 // Cleanup conditions
1888
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001889 EXPECT_CALL(*mComposer,
1890 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001891 .WillOnce(Return(Error::NONE));
1892 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001893}
1894
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001895template <typename Case>
1896void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1897 // --------------------------------------------------------------------
1898 // Preconditions
1899
1900 setupCommonPreconditions<Case>();
1901
1902 // A hotplug connect event is enqueued for a display
1903 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1904
1905 // --------------------------------------------------------------------
1906 // Invocation
1907
1908 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1909
1910 // --------------------------------------------------------------------
1911 // Postconditions
1912
1913 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001914 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001915}
1916
1917template <typename Case>
1918void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1919 // --------------------------------------------------------------------
1920 // Preconditions
1921
1922 setupCommonPreconditions<Case>();
1923
1924 // A hotplug disconnect event is enqueued for a display
1925 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1926
1927 // The display is already completely set up.
1928 Case::Display::injectHwcDisplay(this);
1929 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1930 existing.inject();
1931
1932 // --------------------------------------------------------------------
1933 // Call Expectations
1934
1935 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001936 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1937 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001938
1939 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1940
1941 // --------------------------------------------------------------------
1942 // Invocation
1943
1944 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1945
1946 // --------------------------------------------------------------------
1947 // Postconditions
1948
1949 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001950 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001951
Dominik Laskowski075d3172018-05-24 15:50:06 -07001952 // SF should not have a display token.
1953 const auto displayId = Case::Display::DISPLAY_ID::get();
1954 ASSERT_TRUE(displayId);
1955 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001956
1957 // The existing token should have been removed
1958 verifyDisplayIsNotConnected(existing.token());
1959}
1960
1961TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1962 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1963}
1964
1965TEST_F(HandleTransactionLockedTest,
1966 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1967 // Inject an external display.
1968 ExternalDisplayVariant::injectHwcDisplay(this);
1969
1970 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1971}
1972
1973TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1974 // Inject a primary display.
1975 PrimaryDisplayVariant::injectHwcDisplay(this);
1976
1977 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1978}
1979
1980TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1981 // Inject both a primary and external display.
1982 PrimaryDisplayVariant::injectHwcDisplay(this);
1983 ExternalDisplayVariant::injectHwcDisplay(this);
1984
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001985 // TODO: This is an unnecessary call.
1986 EXPECT_CALL(*mComposer,
1987 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
1988 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
1989 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
1990 Return(Error::NONE)));
1991
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001992 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1993
1994 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1995}
1996
1997TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1998 // Inject a primary display.
1999 PrimaryDisplayVariant::injectHwcDisplay(this);
2000
2001 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
2002
2003 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
2004}
2005
2006TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
2007 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
2008}
2009
2010TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
2011 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
2012}
2013
2014TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
2015 using Case = SimplePrimaryDisplayCase;
2016
2017 // --------------------------------------------------------------------
2018 // Preconditions
2019
2020 setupCommonPreconditions<Case>();
2021
2022 // A hotplug connect event is enqueued for a display
2023 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
2024 // A hotplug disconnect event is also enqueued for the same display
2025 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
2026
2027 // --------------------------------------------------------------------
2028 // Call Expectations
2029
2030 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2031
2032 setupCommonCallExpectationsForConnectProcessing<Case>();
2033 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2034
2035 EXPECT_CALL(*mComposer,
2036 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2037 .WillOnce(Return(Error::NONE));
2038 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2039
2040 // --------------------------------------------------------------------
2041 // Invocation
2042
2043 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2044
2045 // --------------------------------------------------------------------
2046 // Postconditions
2047
2048 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002049 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002050
Dominik Laskowski075d3172018-05-24 15:50:06 -07002051 // SF should not have a display token.
2052 const auto displayId = Case::Display::DISPLAY_ID::get();
2053 ASSERT_TRUE(displayId);
2054 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002055}
2056
2057TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
2058 using Case = SimplePrimaryDisplayCase;
2059
2060 // --------------------------------------------------------------------
2061 // Preconditions
2062
2063 setupCommonPreconditions<Case>();
2064
2065 // The display is already completely set up.
2066 Case::Display::injectHwcDisplay(this);
2067 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2068 existing.inject();
2069
2070 // A hotplug disconnect event is enqueued for a display
2071 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
2072 // A hotplug connect event is also enqueued for the same display
2073 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
2074
2075 // --------------------------------------------------------------------
2076 // Call Expectations
2077
2078 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2079
2080 setupCommonCallExpectationsForConnectProcessing<Case>();
2081 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2082
2083 // --------------------------------------------------------------------
2084 // Invocation
2085
2086 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2087
2088 // --------------------------------------------------------------------
2089 // Postconditions
2090
2091 // The existing token should have been removed
2092 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07002093 const auto displayId = Case::Display::DISPLAY_ID::get();
2094 ASSERT_TRUE(displayId);
2095 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
2096 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002097
2098 // A new display should be connected in its place
2099
2100 verifyPhysicalDisplayIsConnected<Case>();
2101
2102 // --------------------------------------------------------------------
2103 // Cleanup conditions
2104
2105 EXPECT_CALL(*mComposer,
2106 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2107 .WillOnce(Return(Error::NONE));
2108 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2109}
2110
2111TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
2112 using Case = HwcVirtualDisplayCase;
2113
2114 // --------------------------------------------------------------------
2115 // Preconditions
2116
2117 // The HWC supports at least one virtual display
2118 injectMockComposer(1);
2119
2120 setupCommonPreconditions<Case>();
2121
2122 // A virtual display was added to the current state, and it has a
2123 // surface(producer)
2124 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07002125
Dominik Laskowski075d3172018-05-24 15:50:06 -07002126 DisplayDeviceState state;
2127 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002128
2129 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07002130 state.surface = surface;
2131 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002132
2133 // --------------------------------------------------------------------
2134 // Call Expectations
2135
2136 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
2137 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
2138
2139 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
2140 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
2141 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
2142 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
2143 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
2144 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
2145 Return(NO_ERROR)));
2146 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
2147 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
2148
2149 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
2150
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002151 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002152 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
2153
2154 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
2155 Case::WideColorSupport::setupComposerCallExpectations(this);
2156 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07002157 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002158
2159 // --------------------------------------------------------------------
2160 // Invocation
2161
2162 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2163
2164 // --------------------------------------------------------------------
2165 // Postconditions
2166
2167 // The display device should have been set up in the list of displays.
2168 verifyDisplayIsConnected<Case>(displayToken);
2169
2170 // --------------------------------------------------------------------
2171 // Cleanup conditions
2172
2173 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
2174 .WillOnce(Return(Error::NONE));
2175 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08002176
2177 // Cleanup
2178 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
2179 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002180}
2181
2182TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
2183 using Case = HwcVirtualDisplayCase;
2184
2185 // --------------------------------------------------------------------
2186 // Preconditions
2187
2188 // The HWC supports at least one virtual display
2189 injectMockComposer(1);
2190
2191 setupCommonPreconditions<Case>();
2192
2193 // A virtual display was added to the current state, but it does not have a
2194 // surface.
2195 sp<BBinder> displayToken = new BBinder();
2196
Dominik Laskowski075d3172018-05-24 15:50:06 -07002197 DisplayDeviceState state;
2198 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002199
Dominik Laskowski075d3172018-05-24 15:50:06 -07002200 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002201
2202 // --------------------------------------------------------------------
2203 // Call Expectations
2204
2205 // --------------------------------------------------------------------
2206 // Invocation
2207
2208 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2209
2210 // --------------------------------------------------------------------
2211 // Postconditions
2212
2213 // There will not be a display device set up.
2214 EXPECT_FALSE(hasDisplayDevice(displayToken));
2215
2216 // The drawing display state will be set from the current display state.
2217 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2218 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002219 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002220}
2221
2222TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
2223 using Case = HwcVirtualDisplayCase;
2224
2225 // --------------------------------------------------------------------
2226 // Preconditions
2227
2228 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002229 const auto displayId = Case::Display::DISPLAY_ID::get();
2230 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08002231 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002232 Case::Display::injectHwcDisplay(this);
2233 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2234 existing.inject();
2235 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2236
2237 // --------------------------------------------------------------------
2238 // Call Expectations
2239
2240 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2241
2242 // --------------------------------------------------------------------
2243 // Invocation
2244
2245 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2246
2247 // --------------------------------------------------------------------
2248 // Postconditions
2249
2250 // The existing token should have been removed
2251 verifyDisplayIsNotConnected(existing.token());
2252}
2253
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002254TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2255 using Case = NonHwcVirtualDisplayCase;
2256
2257 constexpr uint32_t oldLayerStack = 0u;
2258 constexpr uint32_t newLayerStack = 123u;
2259
2260 // --------------------------------------------------------------------
2261 // Preconditions
2262
2263 // A display is set up
2264 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2265 display.inject();
2266
2267 // There is a change to the layerStack state
2268 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2269 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2270
2271 // --------------------------------------------------------------------
2272 // Invocation
2273
2274 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2275
2276 // --------------------------------------------------------------------
2277 // Postconditions
2278
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002279 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002280}
2281
2282TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2283 using Case = NonHwcVirtualDisplayCase;
2284
Dominik Laskowski718f9602019-11-09 20:01:35 -08002285 constexpr ui::Rotation oldTransform = ui::ROTATION_0;
2286 constexpr ui::Rotation newTransform = ui::ROTATION_180;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002287
2288 // --------------------------------------------------------------------
2289 // Preconditions
2290
2291 // A display is set up
2292 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2293 display.inject();
2294
2295 // There is a change to the orientation state
2296 display.mutableDrawingDisplayState().orientation = oldTransform;
2297 display.mutableCurrentDisplayState().orientation = newTransform;
2298
2299 // --------------------------------------------------------------------
2300 // Invocation
2301
2302 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2303
2304 // --------------------------------------------------------------------
2305 // Postconditions
2306
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002307 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002308}
2309
2310TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2311 using Case = NonHwcVirtualDisplayCase;
2312
2313 const Rect oldViewport(0, 0, 0, 0);
2314 const Rect newViewport(0, 0, 123, 456);
2315
2316 // --------------------------------------------------------------------
2317 // Preconditions
2318
2319 // A display is set up
2320 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2321 display.inject();
2322
2323 // There is a change to the viewport state
2324 display.mutableDrawingDisplayState().viewport = oldViewport;
2325 display.mutableCurrentDisplayState().viewport = newViewport;
2326
2327 // --------------------------------------------------------------------
2328 // Invocation
2329
2330 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2331
2332 // --------------------------------------------------------------------
2333 // Postconditions
2334
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002335 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002336}
2337
2338TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2339 using Case = NonHwcVirtualDisplayCase;
2340
2341 const Rect oldFrame(0, 0, 0, 0);
2342 const Rect newFrame(0, 0, 123, 456);
2343
2344 // --------------------------------------------------------------------
2345 // Preconditions
2346
2347 // A display is set up
2348 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2349 display.inject();
2350
2351 // There is a change to the viewport state
2352 display.mutableDrawingDisplayState().frame = oldFrame;
2353 display.mutableCurrentDisplayState().frame = newFrame;
2354
2355 // --------------------------------------------------------------------
2356 // Invocation
2357
2358 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2359
2360 // --------------------------------------------------------------------
2361 // Postconditions
2362
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002363 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002364}
2365
2366TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2367 using Case = NonHwcVirtualDisplayCase;
2368
2369 constexpr int oldWidth = 0;
2370 constexpr int oldHeight = 10;
2371 constexpr int newWidth = 123;
2372
2373 // --------------------------------------------------------------------
2374 // Preconditions
2375
2376 // A display is set up
2377 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002378 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002379 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002380 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2381 display.setNativeWindow(nativeWindow);
2382 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002383 // Setup injection expections
2384 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2385 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2386 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2387 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002388 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2389 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2390 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002391 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002392 display.inject();
2393
2394 // There is a change to the viewport state
2395 display.mutableDrawingDisplayState().width = oldWidth;
2396 display.mutableDrawingDisplayState().height = oldHeight;
2397 display.mutableCurrentDisplayState().width = newWidth;
2398 display.mutableCurrentDisplayState().height = oldHeight;
2399
2400 // --------------------------------------------------------------------
2401 // Call Expectations
2402
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002403 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002404
2405 // --------------------------------------------------------------------
2406 // Invocation
2407
2408 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2409}
2410
2411TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2412 using Case = NonHwcVirtualDisplayCase;
2413
2414 constexpr int oldWidth = 0;
2415 constexpr int oldHeight = 10;
2416 constexpr int newHeight = 123;
2417
2418 // --------------------------------------------------------------------
2419 // Preconditions
2420
2421 // A display is set up
2422 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002423 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002424 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002425 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2426 display.setNativeWindow(nativeWindow);
2427 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002428 // Setup injection expections
2429 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2430 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2431 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2432 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002433 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2434 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2435 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002436 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002437 display.inject();
2438
2439 // There is a change to the viewport state
2440 display.mutableDrawingDisplayState().width = oldWidth;
2441 display.mutableDrawingDisplayState().height = oldHeight;
2442 display.mutableCurrentDisplayState().width = oldWidth;
2443 display.mutableCurrentDisplayState().height = newHeight;
2444
2445 // --------------------------------------------------------------------
2446 // Call Expectations
2447
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002448 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002449
2450 // --------------------------------------------------------------------
2451 // Invocation
2452
2453 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2454}
2455
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002456/* ------------------------------------------------------------------------
2457 * SurfaceFlinger::setDisplayStateLocked
2458 */
2459
2460TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2461 // --------------------------------------------------------------------
2462 // Preconditions
2463
2464 // We have an unknown display token not associated with a known display
2465 sp<BBinder> displayToken = new BBinder();
2466
2467 // The requested display state references the unknown display.
2468 DisplayState state;
2469 state.what = DisplayState::eLayerStackChanged;
2470 state.token = displayToken;
2471 state.layerStack = 456;
2472
2473 // --------------------------------------------------------------------
2474 // Invocation
2475
2476 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2477
2478 // --------------------------------------------------------------------
2479 // Postconditions
2480
2481 // The returned flags are empty
2482 EXPECT_EQ(0u, flags);
2483
2484 // The display token still doesn't match anything known.
2485 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2486}
2487
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002488TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2489 using Case = SimplePrimaryDisplayCase;
2490
2491 // --------------------------------------------------------------------
2492 // Preconditions
2493
2494 // A display is already set up
2495 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2496 display.inject();
2497
2498 // No changes are made to the display
2499 DisplayState state;
2500 state.what = 0;
2501 state.token = display.token();
2502
2503 // --------------------------------------------------------------------
2504 // Invocation
2505
2506 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2507
2508 // --------------------------------------------------------------------
2509 // Postconditions
2510
2511 // The returned flags are empty
2512 EXPECT_EQ(0u, flags);
2513}
2514
2515TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2516 using Case = SimplePrimaryDisplayCase;
2517
2518 // --------------------------------------------------------------------
2519 // Preconditions
2520
2521 // A display is already set up
2522 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2523 display.inject();
2524
2525 // There is a surface that can be set.
2526 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2527
2528 // The current display state has the surface set
2529 display.mutableCurrentDisplayState().surface = surface;
2530
2531 // The incoming request sets the same surface
2532 DisplayState state;
2533 state.what = DisplayState::eSurfaceChanged;
2534 state.token = display.token();
2535 state.surface = surface;
2536
2537 // --------------------------------------------------------------------
2538 // Invocation
2539
2540 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2541
2542 // --------------------------------------------------------------------
2543 // Postconditions
2544
2545 // The returned flags are empty
2546 EXPECT_EQ(0u, flags);
2547
2548 // The current display state is unchanged.
2549 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2550}
2551
2552TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2553 using Case = SimplePrimaryDisplayCase;
2554
2555 // --------------------------------------------------------------------
2556 // Preconditions
2557
2558 // A display is already set up
2559 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2560 display.inject();
2561
2562 // There is a surface that can be set.
2563 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2564
2565 // The current display state does not have a surface
2566 display.mutableCurrentDisplayState().surface = nullptr;
2567
2568 // The incoming request sets a surface
2569 DisplayState state;
2570 state.what = DisplayState::eSurfaceChanged;
2571 state.token = display.token();
2572 state.surface = surface;
2573
2574 // --------------------------------------------------------------------
2575 // Invocation
2576
2577 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2578
2579 // --------------------------------------------------------------------
2580 // Postconditions
2581
2582 // The returned flags indicate a transaction is needed
2583 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2584
2585 // The current display layer stack state is set to the new value
2586 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2587}
2588
2589TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2590 using Case = SimplePrimaryDisplayCase;
2591
2592 // --------------------------------------------------------------------
2593 // Preconditions
2594
2595 // A display is already set up
2596 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2597 display.inject();
2598
2599 // The display has a layer stack set
2600 display.mutableCurrentDisplayState().layerStack = 456u;
2601
2602 // The incoming request sets the same layer stack
2603 DisplayState state;
2604 state.what = DisplayState::eLayerStackChanged;
2605 state.token = display.token();
2606 state.layerStack = 456u;
2607
2608 // --------------------------------------------------------------------
2609 // Invocation
2610
2611 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2612
2613 // --------------------------------------------------------------------
2614 // Postconditions
2615
2616 // The returned flags are empty
2617 EXPECT_EQ(0u, flags);
2618
2619 // The current display state is unchanged
2620 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2621}
2622
2623TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2624 using Case = SimplePrimaryDisplayCase;
2625
2626 // --------------------------------------------------------------------
2627 // Preconditions
2628
2629 // A display is set up
2630 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2631 display.inject();
2632
2633 // The display has a layer stack set
2634 display.mutableCurrentDisplayState().layerStack = 654u;
2635
2636 // The incoming request sets a different layer stack
2637 DisplayState state;
2638 state.what = DisplayState::eLayerStackChanged;
2639 state.token = display.token();
2640 state.layerStack = 456u;
2641
2642 // --------------------------------------------------------------------
2643 // Invocation
2644
2645 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2646
2647 // --------------------------------------------------------------------
2648 // Postconditions
2649
2650 // The returned flags indicate a transaction is needed
2651 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2652
2653 // The desired display state has been set to the new value.
2654 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2655}
2656
2657TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2658 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002659 constexpr ui::Rotation initialOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002660 const Rect initialFrame = {1, 2, 3, 4};
2661 const Rect initialViewport = {5, 6, 7, 8};
2662
2663 // --------------------------------------------------------------------
2664 // Preconditions
2665
2666 // A display is set up
2667 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2668 display.inject();
2669
2670 // The current display state projection state is all set
2671 display.mutableCurrentDisplayState().orientation = initialOrientation;
2672 display.mutableCurrentDisplayState().frame = initialFrame;
2673 display.mutableCurrentDisplayState().viewport = initialViewport;
2674
2675 // The incoming request sets the same projection state
2676 DisplayState state;
2677 state.what = DisplayState::eDisplayProjectionChanged;
2678 state.token = display.token();
2679 state.orientation = initialOrientation;
2680 state.frame = initialFrame;
2681 state.viewport = initialViewport;
2682
2683 // --------------------------------------------------------------------
2684 // Invocation
2685
2686 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2687
2688 // --------------------------------------------------------------------
2689 // Postconditions
2690
2691 // The returned flags are empty
2692 EXPECT_EQ(0u, flags);
2693
2694 // The current display state is unchanged
2695 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2696
2697 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2698 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2699}
2700
2701TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2702 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002703 constexpr ui::Rotation initialOrientation = ui::ROTATION_90;
2704 constexpr ui::Rotation desiredOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002705
2706 // --------------------------------------------------------------------
2707 // Preconditions
2708
2709 // A display is set up
2710 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2711 display.inject();
2712
2713 // The current display state has an orientation set
2714 display.mutableCurrentDisplayState().orientation = initialOrientation;
2715
2716 // The incoming request sets a different orientation
2717 DisplayState state;
2718 state.what = DisplayState::eDisplayProjectionChanged;
2719 state.token = display.token();
2720 state.orientation = desiredOrientation;
2721
2722 // --------------------------------------------------------------------
2723 // Invocation
2724
2725 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2726
2727 // --------------------------------------------------------------------
2728 // Postconditions
2729
2730 // The returned flags indicate a transaction is needed
2731 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2732
2733 // The current display state has the new value.
2734 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2735}
2736
2737TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2738 using Case = SimplePrimaryDisplayCase;
2739 const Rect initialFrame = {0, 0, 0, 0};
2740 const Rect desiredFrame = {5, 6, 7, 8};
2741
2742 // --------------------------------------------------------------------
2743 // Preconditions
2744
2745 // A display is set up
2746 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2747 display.inject();
2748
2749 // The current display state does not have a frame
2750 display.mutableCurrentDisplayState().frame = initialFrame;
2751
2752 // The incoming request sets a frame
2753 DisplayState state;
2754 state.what = DisplayState::eDisplayProjectionChanged;
2755 state.token = display.token();
2756 state.frame = desiredFrame;
2757
2758 // --------------------------------------------------------------------
2759 // Invocation
2760
2761 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2762
2763 // --------------------------------------------------------------------
2764 // Postconditions
2765
2766 // The returned flags indicate a transaction is needed
2767 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2768
2769 // The current display state has the new value.
2770 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2771}
2772
2773TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2774 using Case = SimplePrimaryDisplayCase;
2775 const Rect initialViewport = {0, 0, 0, 0};
2776 const Rect desiredViewport = {5, 6, 7, 8};
2777
2778 // --------------------------------------------------------------------
2779 // Preconditions
2780
2781 // A display is set up
2782 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2783 display.inject();
2784
2785 // The current display state does not have a viewport
2786 display.mutableCurrentDisplayState().viewport = initialViewport;
2787
2788 // The incoming request sets a viewport
2789 DisplayState state;
2790 state.what = DisplayState::eDisplayProjectionChanged;
2791 state.token = display.token();
2792 state.viewport = desiredViewport;
2793
2794 // --------------------------------------------------------------------
2795 // Invocation
2796
2797 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2798
2799 // --------------------------------------------------------------------
2800 // Postconditions
2801
2802 // The returned flags indicate a transaction is needed
2803 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2804
2805 // The current display state has the new value.
2806 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2807}
2808
2809TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2810 using Case = SimplePrimaryDisplayCase;
2811 constexpr uint32_t initialWidth = 1024;
2812 constexpr uint32_t initialHeight = 768;
2813
2814 // --------------------------------------------------------------------
2815 // Preconditions
2816
2817 // A display is set up
2818 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2819 display.inject();
2820
2821 // The current display state has a size set
2822 display.mutableCurrentDisplayState().width = initialWidth;
2823 display.mutableCurrentDisplayState().height = initialHeight;
2824
2825 // The incoming request sets the same display size
2826 DisplayState state;
2827 state.what = DisplayState::eDisplaySizeChanged;
2828 state.token = display.token();
2829 state.width = initialWidth;
2830 state.height = initialHeight;
2831
2832 // --------------------------------------------------------------------
2833 // Invocation
2834
2835 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2836
2837 // --------------------------------------------------------------------
2838 // Postconditions
2839
2840 // The returned flags are empty
2841 EXPECT_EQ(0u, flags);
2842
2843 // The current display state is unchanged
2844 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2845 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2846}
2847
2848TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2849 using Case = SimplePrimaryDisplayCase;
2850 constexpr uint32_t initialWidth = 0;
2851 constexpr uint32_t desiredWidth = 1024;
2852
2853 // --------------------------------------------------------------------
2854 // Preconditions
2855
2856 // A display is set up
2857 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2858 display.inject();
2859
2860 // The display does not yet have a width
2861 display.mutableCurrentDisplayState().width = initialWidth;
2862
2863 // The incoming request sets a display width
2864 DisplayState state;
2865 state.what = DisplayState::eDisplaySizeChanged;
2866 state.token = display.token();
2867 state.width = desiredWidth;
2868
2869 // --------------------------------------------------------------------
2870 // Invocation
2871
2872 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2873
2874 // --------------------------------------------------------------------
2875 // Postconditions
2876
2877 // The returned flags indicate a transaction is needed
2878 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2879
2880 // The current display state has the new value.
2881 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2882}
2883
2884TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2885 using Case = SimplePrimaryDisplayCase;
2886 constexpr uint32_t initialHeight = 0;
2887 constexpr uint32_t desiredHeight = 768;
2888
2889 // --------------------------------------------------------------------
2890 // Preconditions
2891
2892 // A display is set up
2893 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2894 display.inject();
2895
2896 // The display does not yet have a height
2897 display.mutableCurrentDisplayState().height = initialHeight;
2898
2899 // The incoming request sets a display height
2900 DisplayState state;
2901 state.what = DisplayState::eDisplaySizeChanged;
2902 state.token = display.token();
2903 state.height = desiredHeight;
2904
2905 // --------------------------------------------------------------------
2906 // Invocation
2907
2908 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2909
2910 // --------------------------------------------------------------------
2911 // Postconditions
2912
2913 // The returned flags indicate a transaction is needed
2914 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2915
2916 // The current display state has the new value.
2917 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2918}
2919
Lloyd Pique86016da2018-03-01 16:09:38 -08002920/* ------------------------------------------------------------------------
2921 * SurfaceFlinger::onInitializeDisplays
2922 */
2923
2924TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2925 using Case = SimplePrimaryDisplayCase;
2926
2927 // --------------------------------------------------------------------
2928 // Preconditions
2929
2930 // A primary display is set up
2931 Case::Display::injectHwcDisplay(this);
2932 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2933 primaryDisplay.inject();
2934
2935 // --------------------------------------------------------------------
2936 // Call Expectations
2937
2938 // We expect the surface interceptor to possibly be used, but we treat it as
2939 // disabled since it is called as a side effect rather than directly by this
2940 // function.
2941 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2942
2943 // We expect a call to get the active display config.
2944 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2945
2946 // We expect invalidate() to be invoked once to trigger display transaction
2947 // processing.
2948 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2949
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002950 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2951
Lloyd Pique86016da2018-03-01 16:09:38 -08002952 // --------------------------------------------------------------------
2953 // Invocation
2954
2955 mFlinger.onInitializeDisplays();
2956
2957 // --------------------------------------------------------------------
2958 // Postconditions
2959
2960 // The primary display should have a current state
2961 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2962 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2963 // The layer stack state should be set to zero
2964 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2965 // The orientation state should be set to zero
Dominik Laskowski718f9602019-11-09 20:01:35 -08002966 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
Lloyd Pique86016da2018-03-01 16:09:38 -08002967
2968 // The frame state should be set to INVALID
2969 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2970
2971 // The viewport state should be set to INVALID
2972 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2973
2974 // The width and height should both be zero
2975 EXPECT_EQ(0u, primaryDisplayState.width);
2976 EXPECT_EQ(0u, primaryDisplayState.height);
2977
2978 // The display should be set to HWC_POWER_MODE_NORMAL
2979 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2980 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2981 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2982
2983 // The display refresh period should be set in the frame tracker.
2984 FrameStats stats;
2985 mFlinger.getAnimFrameTracker().getStats(&stats);
2986 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2987
2988 // The display transaction needed flag should be set.
2989 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2990
2991 // The compositor timing should be set to default values
2992 const auto& compositorTiming = mFlinger.getCompositorTiming();
2993 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2994 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2995 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2996}
2997
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002998/* ------------------------------------------------------------------------
2999 * SurfaceFlinger::setPowerModeInternal
3000 */
3001
3002// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07003003template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003004struct DozeIsSupportedVariant {
3005 static constexpr bool DOZE_SUPPORTED = true;
3006 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3007 IComposerClient::PowerMode::DOZE;
3008 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3009 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07003010
3011 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3012 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
3013 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
3014 {Hwc2::DisplayCapability::DOZE})),
3015 Return(Error::NONE)));
3016 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003017};
3018
Peiyong Lined531a32018-10-26 18:27:56 -07003019template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003020// Used when we simulate a display that does not support doze.
3021struct DozeNotSupportedVariant {
3022 static constexpr bool DOZE_SUPPORTED = false;
3023 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3024 IComposerClient::PowerMode::ON;
3025 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3026 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07003027
3028 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3029 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
3030 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
3031 Return(Error::NONE)));
3032 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003033};
3034
3035struct EventThreadBaseSupportedVariant {
3036 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
3037 // The event control thread should not be notified.
3038 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
3039
3040 // The event thread should not be notified.
3041 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
3042 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
3043 }
3044};
3045
3046struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
3047 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3048 // These calls are only expected for the primary display.
3049
3050 // Instead expect no calls.
3051 setupEventAndEventControlThreadNoCallExpectations(test);
3052 }
3053
3054 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3055 // These calls are only expected for the primary display.
3056
3057 // Instead expect no calls.
3058 setupEventAndEventControlThreadNoCallExpectations(test);
3059 }
3060};
3061
3062struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
3063 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3064 // The event control thread should be notified to enable vsyncs
3065 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
3066
3067 // The event thread should be notified that the screen was acquired.
3068 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
3069 }
3070
3071 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3072 // There should be a call to setVsyncEnabled(false)
3073 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
3074
3075 // The event thread should not be notified that the screen was released.
3076 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
3077 }
3078};
3079
Lloyd Pique41be5d22018-06-21 13:11:48 -07003080struct DispSyncIsSupportedVariant {
3081 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique41be5d22018-06-21 13:11:48 -07003082 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
3083 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
3084 }
3085
3086 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
3087 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
3088 }
3089};
3090
3091struct DispSyncNotSupportedVariant {
3092 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3093
3094 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3095};
3096
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003097// --------------------------------------------------------------------
3098// Note:
3099//
3100// There are a large number of transitions we could test, however we only test a
3101// selected subset which provides complete test coverage of the implementation.
3102// --------------------------------------------------------------------
3103
3104template <int initialPowerMode, int targetPowerMode>
3105struct TransitionVariantCommon {
3106 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
3107 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
3108
3109 static void verifyPostconditions(DisplayTransactionTest*) {}
3110};
3111
3112struct TransitionOffToOnVariant
3113 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
3114 template <typename Case>
3115 static void setupCallExpectations(DisplayTransactionTest* test) {
3116 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3117 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003118 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003119 Case::setupRepaintEverythingCallExpectations(test);
3120 }
3121
3122 static void verifyPostconditions(DisplayTransactionTest* test) {
3123 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3124 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3125 }
3126};
3127
3128struct TransitionOffToDozeSuspendVariant
3129 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
3130 template <typename Case>
3131 static void setupCallExpectations(DisplayTransactionTest* test) {
3132 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3133 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3134 Case::setupRepaintEverythingCallExpectations(test);
3135 }
3136
3137 static void verifyPostconditions(DisplayTransactionTest* test) {
3138 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3139 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3140 }
3141};
3142
3143struct TransitionOnToOffVariant
3144 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
3145 template <typename Case>
3146 static void setupCallExpectations(DisplayTransactionTest* test) {
3147 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003148 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003149 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3150 }
3151
3152 static void verifyPostconditions(DisplayTransactionTest* test) {
3153 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3154 }
3155};
3156
3157struct TransitionDozeSuspendToOffVariant
3158 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
3159 template <typename Case>
3160 static void setupCallExpectations(DisplayTransactionTest* test) {
3161 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3162 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3163 }
3164
3165 static void verifyPostconditions(DisplayTransactionTest* test) {
3166 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3167 }
3168};
3169
3170struct TransitionOnToDozeVariant
3171 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
3172 template <typename Case>
3173 static void setupCallExpectations(DisplayTransactionTest* test) {
3174 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3175 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3176 }
3177};
3178
3179struct TransitionDozeSuspendToDozeVariant
3180 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
3181 template <typename Case>
3182 static void setupCallExpectations(DisplayTransactionTest* test) {
3183 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003184 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003185 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3186 }
3187};
3188
3189struct TransitionDozeToOnVariant
3190 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
3191 template <typename Case>
3192 static void setupCallExpectations(DisplayTransactionTest* test) {
3193 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3194 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3195 }
3196};
3197
3198struct TransitionDozeSuspendToOnVariant
3199 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
3200 template <typename Case>
3201 static void setupCallExpectations(DisplayTransactionTest* test) {
3202 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003203 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003204 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3205 }
3206};
3207
3208struct TransitionOnToDozeSuspendVariant
3209 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
3210 template <typename Case>
3211 static void setupCallExpectations(DisplayTransactionTest* test) {
3212 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003213 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003214 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3215 }
3216};
3217
3218struct TransitionOnToUnknownVariant
3219 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
3220 template <typename Case>
3221 static void setupCallExpectations(DisplayTransactionTest* test) {
3222 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3223 Case::setupNoComposerPowerModeCallExpectations(test);
3224 }
3225};
3226
3227// --------------------------------------------------------------------
3228// Note:
3229//
3230// Rather than testing the cartesian product of of
3231// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3232// display type, and the other for another display type.
3233// --------------------------------------------------------------------
3234
3235template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003236 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003237struct DisplayPowerCase {
3238 using Display = DisplayVariant;
3239 using Doze = DozeVariant;
3240 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003241 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003242 using Transition = TransitionVariant;
3243
3244 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003245 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003246 auto display = Display::makeFakeExistingDisplayInjector(test);
3247 display.inject();
3248 display.mutableDisplayDevice()->setPowerMode(mode);
3249 return display;
3250 }
3251
3252 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003253 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003254 }
3255
3256 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3257 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3258 }
3259
3260 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3261 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3262 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3263 }
3264
3265 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3266 IComposerClient::PowerMode mode) {
3267 // Any calls to get the active config will return a default value.
3268 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3269 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3270 Return(Error::NONE)));
3271
3272 // Any calls to get whether the display supports dozing will return the value set by the
3273 // policy variant.
3274 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3275 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3276
3277 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3278 }
3279
3280 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3281 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3282 }
3283};
3284
3285// A sample configuration for the primary display.
3286// In addition to having event thread support, we emulate doze support.
3287template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003288using PrimaryDisplayPowerCase =
3289 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3290 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3291 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003292
3293// A sample configuration for the external display.
3294// In addition to not having event thread support, we emulate not having doze
3295// support.
3296template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003297using ExternalDisplayPowerCase =
3298 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3299 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3300 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003301
3302class SetPowerModeInternalTest : public DisplayTransactionTest {
3303public:
3304 template <typename Case>
3305 void transitionDisplayCommon();
3306};
3307
3308template <int PowerMode>
3309struct PowerModeInitialVSyncEnabled : public std::false_type {};
3310
3311template <>
3312struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3313
3314template <>
3315struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3316
3317template <typename Case>
3318void SetPowerModeInternalTest::transitionDisplayCommon() {
3319 // --------------------------------------------------------------------
3320 // Preconditions
3321
Peiyong Lined531a32018-10-26 18:27:56 -07003322 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003323 auto display =
3324 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3325 Case::setInitialPrimaryHWVsyncEnabled(this,
3326 PowerModeInitialVSyncEnabled<
3327 Case::Transition::INITIAL_POWER_MODE>::value);
3328
3329 // --------------------------------------------------------------------
3330 // Call Expectations
3331
3332 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3333 Case::Transition::template setupCallExpectations<Case>(this);
3334
3335 // --------------------------------------------------------------------
3336 // Invocation
3337
3338 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3339 Case::Transition::TARGET_POWER_MODE);
3340
3341 // --------------------------------------------------------------------
3342 // Postconditions
3343
3344 Case::Transition::verifyPostconditions(this);
3345}
3346
3347TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3348 using Case = SimplePrimaryDisplayCase;
3349
3350 // --------------------------------------------------------------------
3351 // Preconditions
3352
3353 // A primary display device is set up
3354 Case::Display::injectHwcDisplay(this);
3355 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3356 display.inject();
3357
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003358 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003359 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3360
3361 // --------------------------------------------------------------------
3362 // Invocation
3363
3364 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3365
3366 // --------------------------------------------------------------------
3367 // Postconditions
3368
3369 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3370}
3371
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003372TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003373 using Case = HwcVirtualDisplayCase;
3374
3375 // --------------------------------------------------------------------
3376 // Preconditions
3377
Dominik Laskowski075d3172018-05-24 15:50:06 -07003378 // Insert display data so that the HWC thinks it created the virtual display.
3379 const auto displayId = Case::Display::DISPLAY_ID::get();
3380 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003381 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003382
3383 // A virtual display device is set up
3384 Case::Display::injectHwcDisplay(this);
3385 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3386 display.inject();
3387
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003388 // The display is set to HWC_POWER_MODE_NORMAL
3389 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003390
3391 // --------------------------------------------------------------------
3392 // Invocation
3393
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003394 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003395
3396 // --------------------------------------------------------------------
3397 // Postconditions
3398
3399 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3400}
3401
3402TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3403 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3404}
3405
3406TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3407 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3408}
3409
3410TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3411 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3412}
3413
3414TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3415 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3416}
3417
3418TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3419 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3420}
3421
3422TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3423 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3424}
3425
3426TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3427 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3428}
3429
3430TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3431 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3432}
3433
3434TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3435 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3436}
3437
3438TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3439 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3440}
3441
3442TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3443 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3444}
3445
3446TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3447 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3448}
3449
3450TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3451 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3452}
3453
3454TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3455 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3456}
3457
3458TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3459 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3460}
3461
3462TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3463 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3464}
3465
3466TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3467 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3468}
3469
3470TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3471 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3472}
3473
3474TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3475 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3476}
3477
3478TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3479 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3480}
3481
Lloyd Piquef58625d2017-12-19 13:22:33 -08003482} // namespace
3483} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08003484
3485// TODO(b/129481165): remove the #pragma below and fix conversion issues
3486#pragma clang diagnostic pop // ignored "-Wconversion"