blob: 4da064766cb1dbe990e79ee23070bffee1015ae4 [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, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
205 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800206
Lloyd Piquee39cad22017-12-20 17:01:29 -0800207 Mock::VerifyAndClear(mComposer);
208}
209
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800210void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800211 // This setup is only expected once per test.
212 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
213
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800214 mConsumer = new mock::GraphicBufferConsumer();
215 mProducer = new mock::GraphicBufferProducer();
216
217 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
218 *outProducer = mProducer;
219 *outConsumer = mConsumer;
220 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800221}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800222
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800223void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800224 // This setup is only expected once per test.
225 ASSERT_TRUE(mNativeWindowSurface == nullptr);
226
Lloyd Pique22098362018-09-13 11:46:49 -0700227 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800228
Lloyd Pique22098362018-09-13 11:46:49 -0700229 mFlinger.setCreateNativeWindowSurface([this](auto) {
230 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
231 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800232}
233
Dominik Laskowski075d3172018-05-24 15:50:06 -0700234bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) {
235 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800236}
237
238bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
239 return mFlinger.mutableTransactionFlags() & flag;
240}
241
242bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700243 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800244}
245
246sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700247 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800248}
249
250bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
251 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
252}
253
254const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
255 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
256}
257
258bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
259 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
260}
261
262const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
263 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
264}
265
266/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800267 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800268 */
269
Dominik Laskowski075d3172018-05-24 15:50:06 -0700270template <typename PhysicalDisplay>
271struct PhysicalDisplayId {};
272
Dominik Laskowski34157762018-10-31 13:07:19 -0700273template <DisplayId::Type displayId>
274using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700275
276struct NoDisplayId {};
277
278template <typename>
279struct IsPhysicalDisplayId : std::bool_constant<false> {};
280
281template <typename PhysicalDisplay>
282struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
283
284template <typename>
285struct DisplayIdGetter;
286
287template <typename PhysicalDisplay>
288struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
289 static std::optional<DisplayId> get() {
290 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
291 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
292 ? HWC_DISPLAY_PRIMARY
293 : HWC_DISPLAY_EXTERNAL);
294 }
295
296 const auto info =
297 parseDisplayIdentificationData(PhysicalDisplay::PORT,
298 PhysicalDisplay::GET_IDENTIFICATION_DATA());
299 return info ? std::make_optional(info->id) : std::nullopt;
300 }
301};
302
Dominik Laskowski34157762018-10-31 13:07:19 -0700303template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700304struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700305 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700306};
307
308template <>
309struct DisplayIdGetter<NoDisplayId> {
310 static std::optional<DisplayId> get() { return {}; }
311};
312
Dominik Laskowski55c85402020-01-21 16:25:47 -0800313template <typename>
314struct DisplayConnectionTypeGetter {
315 static constexpr std::optional<DisplayConnectionType> value;
316};
317
318template <typename PhysicalDisplay>
319struct DisplayConnectionTypeGetter<PhysicalDisplayId<PhysicalDisplay>> {
320 static constexpr std::optional<DisplayConnectionType> value = PhysicalDisplay::CONNECTION_TYPE;
321};
322
Dominik Laskowski075d3172018-05-24 15:50:06 -0700323// DisplayIdType can be:
324// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
325// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
326// 3) NoDisplayId for virtual display without HWC backing.
327template <typename DisplayIdType, int width, int height, Critical critical, Async async,
328 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800329struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700330 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800331 using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700332
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800333 // The display width and height
334 static constexpr int WIDTH = width;
335 static constexpr int HEIGHT = height;
336
337 static constexpr int GRALLOC_USAGE = grallocUsage;
338
Dominik Laskowski075d3172018-05-24 15:50:06 -0700339 // Whether the display is virtual or physical
340 static constexpr Virtual VIRTUAL =
341 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800342
343 // When creating native window surfaces for the framebuffer, whether those should be critical
344 static constexpr Critical CRITICAL = critical;
345
346 // When creating native window surfaces for the framebuffer, whether those should be async
347 static constexpr Async ASYNC = async;
348
349 // Whether the display should be treated as secure
350 static constexpr Secure SECURE = secure;
351
Dominik Laskowski075d3172018-05-24 15:50:06 -0700352 // Whether the display is primary
353 static constexpr Primary PRIMARY = primary;
354
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800355 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700356 auto injector =
Dominik Laskowski55c85402020-01-21 16:25:47 -0800357 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(), CONNECTION_TYPE::value,
358 static_cast<bool>(PRIMARY));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700359
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800360 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700361 injector.setNativeWindow(test->mNativeWindow);
362
363 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800364 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700365 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
366 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
367 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
368 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800369 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
370 .WillRepeatedly(Return(0));
371 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
372 .WillRepeatedly(Return(0));
373 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
374 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700375 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
376 .WillRepeatedly(Return(0));
377
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800378 return injector;
379 }
380
381 // Called by tests to set up any native window creation call expectations.
382 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
383 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
384 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800385
Alec Mouriba013fa2018-10-16 12:43:11 -0700386 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
387 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
388 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
389 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800390 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
391 .WillRepeatedly(Return(0));
392 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
393 .WillRepeatedly(Return(0));
394 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
395 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700396 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
397 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800398 }
399
400 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
401 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
402 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
403 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
404 .WillRepeatedly(Return(NO_ERROR));
405 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
406 .WillRepeatedly(Return(NO_ERROR));
407 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
408 .WillRepeatedly(Return(NO_ERROR));
409 }
410
411 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
412 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
413 }
414};
415
Dominik Laskowski075d3172018-05-24 15:50:06 -0700416template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
417 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800418struct HwcDisplayVariant {
419 // The display id supplied by the HWC
420 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
421
422 // The HWC display type
423 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
424
425 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700426 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700427 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800428
429 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
430 HWC2::Connection connection) {
431 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
432 HotplugEvent{HWC_DISPLAY_ID, connection});
433 }
434
435 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800436 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700437 const auto displayId = DisplayVariant::DISPLAY_ID::get();
438 ASSERT_TRUE(displayId);
439 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
440 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800441 .setHwcDisplayId(HWC_DISPLAY_ID)
442 .setWidth(DisplayVariant::WIDTH)
443 .setHeight(DisplayVariant::HEIGHT)
444 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700445 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800446 .inject(&test->mFlinger, test->mComposer);
447 }
448
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800449 // Called by tests to inject a HWC display setup
450 static void injectHwcDisplay(DisplayTransactionTest* test) {
451 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
452 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
453 Return(Error::NONE)));
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700454 EXPECT_CALL(*test->mComposer,
455 setPowerMode(HWC_DISPLAY_ID,
456 static_cast<Hwc2::IComposerClient::PowerMode>(INIT_POWER_MODE)))
457 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800458 injectHwcDisplayWithNoDefaultCapabilities(test);
459 }
460
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800461 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800462 constexpr auto CONNECTION_TYPE =
463 PhysicalDisplay::CONNECTION_TYPE == DisplayConnectionType::Internal
464 ? IComposerClient::DisplayConnectionType::INTERNAL
465 : IComposerClient::DisplayConnectionType::EXTERNAL;
466
467 EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _))
468 .WillOnce(
469 DoAll(SetArgPointee<1>(CONNECTION_TYPE), Return(Hwc2::V2_4::Error::NONE)));
470
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800471 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
472 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
473 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
474 Return(Error::NONE)));
475 EXPECT_CALL(*test->mComposer,
476 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
477 IComposerClient::Attribute::WIDTH, _))
478 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
479 EXPECT_CALL(*test->mComposer,
480 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
481 IComposerClient::Attribute::HEIGHT, _))
482 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
483 EXPECT_CALL(*test->mComposer,
484 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
485 IComposerClient::Attribute::VSYNC_PERIOD, _))
486 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
487 EXPECT_CALL(*test->mComposer,
488 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
489 IComposerClient::Attribute::DPI_X, _))
490 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
491 EXPECT_CALL(*test->mComposer,
492 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
493 IComposerClient::Attribute::DPI_Y, _))
494 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Ady Abraham7159f572019-10-11 11:10:18 -0700495 EXPECT_CALL(*test->mComposer,
496 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
497 IComposerClient::Attribute::CONFIG_GROUP, _))
498 .WillOnce(DoAll(SetArgPointee<3>(-1), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700499
500 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
501 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
502 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
503 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
504 Return(Error::NONE)));
505 } else {
506 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
507 .WillOnce(Return(Error::UNSUPPORTED));
508 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800509 }
510
511 // Called by tests to set up HWC call expectations
512 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
513 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700514 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800515 }
516};
517
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800518// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
519constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
520 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
521
Dominik Laskowski075d3172018-05-24 15:50:06 -0700522template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800523 Critical critical>
524struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700525 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
526 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
527 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
528 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
529 critical, Async::FALSE, Secure::TRUE,
530 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
531 PhysicalDisplay> {};
532
533template <bool hasIdentificationData>
534struct PrimaryDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800535 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::Internal;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700536 static constexpr Primary PRIMARY = Primary::TRUE;
537 static constexpr uint8_t PORT = 255;
538 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
539 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
540};
541
542template <bool hasIdentificationData>
543struct ExternalDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800544 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::External;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700545 static constexpr Primary PRIMARY = Primary::FALSE;
546 static constexpr uint8_t PORT = 254;
547 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
548 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
549};
550
551struct TertiaryDisplay {
552 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800553 static constexpr uint8_t PORT = 253;
554 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700555};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800556
557// A primary display is a physical display that is critical
558using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700559 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800560
561// An external display is physical display that is not critical.
562using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700563 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800564
565using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700566 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800567
568// A virtual display not supported by the HWC.
569constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
570
571template <int width, int height, Secure secure>
572struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700573 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
574 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
575 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
576 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
577
578 static void injectHwcDisplay(DisplayTransactionTest*) {}
579
580 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
581 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
582 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800583
584 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
585 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
586 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
587 }
588};
589
590// A virtual display supported by the HWC.
591constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
592
593template <int width, int height, Secure secure>
594struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700595 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
596 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
597 HwcDisplayVariant<
598 1010, HWC2::DisplayType::Virtual,
599 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
600 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
601 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
602 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800603 using Self = HwcVirtualDisplayVariant<width, height, secure>;
604
605 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
606 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
607 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
608 }
609
610 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
611 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
612 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
613 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
614 }
615};
616
617// For this variant, SurfaceFlinger should not configure itself with wide
618// display support, so the display should not be configured for wide-color
619// support.
620struct WideColorSupportNotConfiguredVariant {
621 static constexpr bool WIDE_COLOR_SUPPORTED = false;
622
623 static void injectConfigChange(DisplayTransactionTest* test) {
624 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700625 test->mFlinger.mutableUseColorManagement() = false;
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) {
630 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
631 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
632 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
633 }
634};
635
636// For this variant, SurfaceFlinger should configure itself with wide display
637// support, and the display should respond with an non-empty list of supported
638// color modes. Wide-color support should be configured.
639template <typename Display>
640struct WideColorP3ColorimetricSupportedVariant {
641 static constexpr bool WIDE_COLOR_SUPPORTED = true;
642
643 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700644 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800645 test->mFlinger.mutableHasWideColorDisplay() = true;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800646 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800647 }
648
649 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800650 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
651
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800652 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
653 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
654 Return(Error::NONE)));
655 EXPECT_CALL(*test->mComposer,
656 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
657 .WillOnce(DoAll(SetArgPointee<2>(
658 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
659 Return(Error::NONE)));
660 EXPECT_CALL(*test->mComposer,
661 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
662 RenderIntent::COLORIMETRIC))
663 .WillOnce(Return(Error::NONE));
664 }
665};
666
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800667// For this variant, SurfaceFlinger should configure itself with wide display
668// support, but the display should respond with an empty list of supported color
669// modes. Wide-color support for the display should not be configured.
670template <typename Display>
671struct WideColorNotSupportedVariant {
672 static constexpr bool WIDE_COLOR_SUPPORTED = false;
673
674 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700675 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800676 test->mFlinger.mutableHasWideColorDisplay() = true;
677 }
678
679 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
680 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
681 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700682 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800683 }
684};
685
686// For this variant, the display is not a HWC display, so no HDR support should
687// be configured.
688struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800689 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800690 static constexpr bool HDR10_SUPPORTED = false;
691 static constexpr bool HDR_HLG_SUPPORTED = false;
692 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
693 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
694 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
695 }
696};
697
Valerie Haue9e843a2018-12-18 13:39:23 -0800698template <typename Display>
699struct Hdr10PlusSupportedVariant {
700 static constexpr bool HDR10_PLUS_SUPPORTED = true;
701 static constexpr bool HDR10_SUPPORTED = true;
702 static constexpr bool HDR_HLG_SUPPORTED = false;
703 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
704 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
705 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
706 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
707 Hdr::HDR10_PLUS,
708 Hdr::HDR10,
709 })),
710 Return(Error::NONE)));
711 }
712};
713
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800714// For this variant, the composer should respond with a non-empty list of HDR
715// modes containing HDR10, so HDR10 support should be configured.
716template <typename Display>
717struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800718 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800719 static constexpr bool HDR10_SUPPORTED = true;
720 static constexpr bool HDR_HLG_SUPPORTED = false;
721 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
722 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
723 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
724 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
725 Return(Error::NONE)));
726 }
727};
728
729// For this variant, the composer should respond with a non-empty list of HDR
730// modes containing HLG, so HLG support should be configured.
731template <typename Display>
732struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800733 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800734 static constexpr bool HDR10_SUPPORTED = false;
735 static constexpr bool HDR_HLG_SUPPORTED = true;
736 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
737 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
738 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
739 .WillOnce(
740 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
741 }
742};
743
744// For this variant, the composer should respond with a non-empty list of HDR
745// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
746template <typename Display>
747struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800748 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800749 static constexpr bool HDR10_SUPPORTED = false;
750 static constexpr bool HDR_HLG_SUPPORTED = false;
751 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
752 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
753 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
754 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
755 Return(Error::NONE)));
756 }
757};
758
759// For this variant, the composer should respond with am empty list of HDR
760// modes, so no HDR support should be configured.
761template <typename Display>
762struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800763 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800764 static constexpr bool HDR10_SUPPORTED = false;
765 static constexpr bool HDR_HLG_SUPPORTED = false;
766 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
767 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
768 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
769 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
770 }
771};
772
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700773struct NonHwcPerFrameMetadataSupportVariant {
774 static constexpr int PER_FRAME_METADATA_KEYS = 0;
775 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800776 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700777 }
778};
779
780template <typename Display>
781struct NoPerFrameMetadataSupportVariant {
782 static constexpr int PER_FRAME_METADATA_KEYS = 0;
783 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800784 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
785 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700786 }
787};
788
789template <typename Display>
790struct Smpte2086PerFrameMetadataSupportVariant {
791 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
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::DISPLAY_RED_PRIMARY_X,
796 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
797 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
798 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
799 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
800 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
801 PerFrameMetadataKey::WHITE_POINT_X,
802 PerFrameMetadataKey::WHITE_POINT_Y,
803 PerFrameMetadataKey::MAX_LUMINANCE,
804 PerFrameMetadataKey::MIN_LUMINANCE,
805 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700806 }
807};
808
809template <typename Display>
810struct Cta861_3_PerFrameMetadataSupportVariant {
811 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
812 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800813 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
814 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800815 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
816 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
817 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700818 }
819};
820
Valerie Haue9e843a2018-12-18 13:39:23 -0800821template <typename Display>
822struct Hdr10_Plus_PerFrameMetadataSupportVariant {
823 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
824 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
825 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
826 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
827 PerFrameMetadataKey::HDR10_PLUS_SEI,
828 })));
829 }
830};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800831/* ------------------------------------------------------------------------
832 * Typical display configurations to test
833 */
834
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700835template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
836 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800837struct Case {
838 using Display = DisplayPolicy;
839 using WideColorSupport = WideColorSupportPolicy;
840 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700841 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800842};
843
844using SimplePrimaryDisplayCase =
845 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700846 HdrNotSupportedVariant<PrimaryDisplayVariant>,
847 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800848using SimpleExternalDisplayCase =
849 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700850 HdrNotSupportedVariant<ExternalDisplayVariant>,
851 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800852using SimpleTertiaryDisplayCase =
853 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700854 HdrNotSupportedVariant<TertiaryDisplayVariant>,
855 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800856using NonHwcVirtualDisplayCase =
857 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700858 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
859 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800860using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
861using HwcVirtualDisplayCase =
862 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700863 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800864 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800865using WideColorP3ColorimetricDisplayCase =
866 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700867 HdrNotSupportedVariant<PrimaryDisplayVariant>,
868 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800869using Hdr10PlusDisplayCase =
870 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
871 Hdr10SupportedVariant<PrimaryDisplayVariant>,
872 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800873using Hdr10DisplayCase =
874 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700875 Hdr10SupportedVariant<PrimaryDisplayVariant>,
876 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800877using HdrHlgDisplayCase =
878 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700879 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
880 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800881using HdrDolbyVisionDisplayCase =
882 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700883 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
884 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
885using HdrSmpte2086DisplayCase =
886 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
887 HdrNotSupportedVariant<PrimaryDisplayVariant>,
888 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
889using HdrCta861_3_DisplayCase =
890 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
891 HdrNotSupportedVariant<PrimaryDisplayVariant>,
892 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700893
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800894/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800895 *
896 * SurfaceFlinger::onHotplugReceived
897 */
898
899TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
900 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700901 constexpr hwc2_display_t hwcDisplayId1 = 456;
902 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800903
904 // --------------------------------------------------------------------
905 // Preconditions
906
907 // Set the current sequence id for accepted events
908 mFlinger.mutableComposerSequenceId() = currentSequenceId;
909
910 // Set the main thread id so that the current thread does not appear to be
911 // the main thread.
912 mFlinger.mutableMainThreadId() = std::thread::id();
913
914 // --------------------------------------------------------------------
915 // Call Expectations
916
917 // We expect invalidate() to be invoked once to trigger display transaction
918 // processing.
919 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
920
921 // --------------------------------------------------------------------
922 // Invocation
923
924 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700925 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
926 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800927
928 // --------------------------------------------------------------------
929 // Postconditions
930
931 // The display transaction needed flag should be set.
932 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
933
934 // All events should be in the pending event queue.
935 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
936 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700937 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800938 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700939 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800940 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
941}
942
943TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
944 constexpr int currentSequenceId = 123;
945 constexpr int otherSequenceId = 321;
946 constexpr hwc2_display_t displayId = 456;
947
948 // --------------------------------------------------------------------
949 // Preconditions
950
951 // Set the current sequence id for accepted events
952 mFlinger.mutableComposerSequenceId() = currentSequenceId;
953
954 // Set the main thread id so that the current thread does not appear to be
955 // the main thread.
956 mFlinger.mutableMainThreadId() = std::thread::id();
957
958 // --------------------------------------------------------------------
959 // Call Expectations
960
961 // We do not expect any calls to invalidate().
962 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
963
964 // --------------------------------------------------------------------
965 // Invocation
966
967 // Call with an unexpected sequence id
968 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
969
970 // --------------------------------------------------------------------
971 // Postconditions
972
973 // The display transaction needed flag should not be set
974 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
975
976 // There should be no pending events
977 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
978}
979
980TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
981 constexpr int currentSequenceId = 123;
982 constexpr hwc2_display_t displayId1 = 456;
983
984 // --------------------------------------------------------------------
985 // Note:
986 // --------------------------------------------------------------------
987 // This test case is a bit tricky. We want to verify that
988 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
989 // don't really want to provide coverage for everything the later function
990 // does as there are specific tests for it.
991 // --------------------------------------------------------------------
992
993 // --------------------------------------------------------------------
994 // Preconditions
995
996 // Set the current sequence id for accepted events
997 mFlinger.mutableComposerSequenceId() = currentSequenceId;
998
999 // Set the main thread id so that the current thread does appear to be the
1000 // main thread.
1001 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
1002
1003 // --------------------------------------------------------------------
1004 // Call Expectations
1005
1006 // We expect invalidate() to be invoked once to trigger display transaction
1007 // processing.
1008 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1009
1010 // --------------------------------------------------------------------
1011 // Invocation
1012
1013 // Simulate a disconnect on a display id that is not connected. This should
1014 // be enqueued by onHotplugReceived(), and dequeued by
1015 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
1016 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
1017
1018 // --------------------------------------------------------------------
1019 // Postconditions
1020
1021 // The display transaction needed flag should be set.
1022 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1023
1024 // There should be no event queued on return, as it should have been
1025 // processed.
1026 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1027}
1028
1029/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001030 * SurfaceFlinger::createDisplay
1031 */
1032
1033TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1034 const String8 name("virtual.test");
1035
1036 // --------------------------------------------------------------------
1037 // Call Expectations
1038
1039 // The call should notify the interceptor that a display was created.
1040 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1041
1042 // --------------------------------------------------------------------
1043 // Invocation
1044
1045 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1046
1047 // --------------------------------------------------------------------
1048 // Postconditions
1049
1050 // The display should have been added to the current state
1051 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1052 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001053 EXPECT_TRUE(display.isVirtual());
1054 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001055 EXPECT_EQ(name.string(), display.displayName);
1056
1057 // --------------------------------------------------------------------
1058 // Cleanup conditions
1059
1060 // Destroying the display invalidates the display state.
1061 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1062}
1063
1064TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1065 const String8 name("virtual.test");
1066
1067 // --------------------------------------------------------------------
1068 // Call Expectations
1069
1070 // The call should notify the interceptor that a display was created.
1071 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1072
1073 // --------------------------------------------------------------------
1074 // Invocation
1075
1076 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1077
1078 // --------------------------------------------------------------------
1079 // Postconditions
1080
1081 // The display should have been added to the current state
1082 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1083 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001084 EXPECT_TRUE(display.isVirtual());
1085 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001086 EXPECT_EQ(name.string(), display.displayName);
1087
1088 // --------------------------------------------------------------------
1089 // Cleanup conditions
1090
1091 // Destroying the display invalidates the display state.
1092 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1093}
1094
1095/* ------------------------------------------------------------------------
1096 * SurfaceFlinger::destroyDisplay
1097 */
1098
1099TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1100 using Case = NonHwcVirtualDisplayCase;
1101
1102 // --------------------------------------------------------------------
1103 // Preconditions
1104
1105 // A virtual display exists
1106 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1107 existing.inject();
1108
1109 // --------------------------------------------------------------------
1110 // Call Expectations
1111
1112 // The call should notify the interceptor that a display was created.
1113 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1114
1115 // Destroying the display invalidates the display state.
1116 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1117
1118 // --------------------------------------------------------------------
1119 // Invocation
1120
1121 mFlinger.destroyDisplay(existing.token());
1122
1123 // --------------------------------------------------------------------
1124 // Postconditions
1125
1126 // The display should have been removed from the current state
1127 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1128
1129 // Ths display should still exist in the drawing state
1130 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1131
1132 // The display transaction needed flasg should be set
1133 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1134}
1135
1136TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1137 // --------------------------------------------------------------------
1138 // Preconditions
1139
1140 sp<BBinder> displayToken = new BBinder();
1141
1142 // --------------------------------------------------------------------
1143 // Invocation
1144
1145 mFlinger.destroyDisplay(displayToken);
1146}
1147
1148/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001149 * SurfaceFlinger::resetDisplayState
1150 */
1151
1152TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1153 using Case = NonHwcVirtualDisplayCase;
1154
1155 // --------------------------------------------------------------------
1156 // Preconditions
1157
1158 // vsync is enabled and available
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001159 mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = true;
1160 mFlinger.scheduler()->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001161
1162 // A display exists
1163 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1164 existing.inject();
1165
1166 // --------------------------------------------------------------------
1167 // Call Expectations
1168
1169 // The call disable vsyncs
1170 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1171
Lloyd Pique41be5d22018-06-21 13:11:48 -07001172 // The call ends any display resyncs
1173 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1174
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001175 // --------------------------------------------------------------------
1176 // Invocation
1177
1178 mFlinger.resetDisplayState();
1179
1180 // --------------------------------------------------------------------
1181 // Postconditions
1182
1183 // vsyncs should be off and not available.
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001184 EXPECT_FALSE(mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled());
1185 EXPECT_FALSE(mFlinger.scheduler()->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001186
1187 // The display should have been removed from the display map.
1188 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1189
1190 // The display should still exist in the current state
1191 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1192
1193 // The display should have been removed from the drawing state
1194 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1195}
1196
1197/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001198 * DisplayDevice::GetBestColorMode
1199 */
1200class GetBestColorModeTest : public DisplayTransactionTest {
1201public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001202 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001203
Valerie Hau9758ae02018-10-09 16:05:09 -07001204 GetBestColorModeTest()
1205 : DisplayTransactionTest(),
Dominik Laskowski55c85402020-01-21 16:25:47 -08001206 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID,
1207 DisplayConnectionType::Internal,
Dominik Laskowski075d3172018-05-24 15:50:06 -07001208 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001209
1210 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1211
1212 void addHwcColorModesMapping(ui::ColorMode colorMode,
1213 std::vector<ui::RenderIntent> renderIntents) {
1214 mHwcColorModes[colorMode] = renderIntents;
1215 }
1216
1217 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1218
1219 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1220
1221 void getBestColorMode() {
1222 mInjector.setHwcColorModes(mHwcColorModes);
1223 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001224 mInjector.setNativeWindow(mNativeWindow);
1225
1226 // Creating a DisplayDevice requires getting default dimensions from the
1227 // native window.
1228 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1229 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1230 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1231 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001232 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1233 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1234 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07001235 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001236 auto displayDevice = mInjector.inject();
1237
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001238 displayDevice->getCompositionDisplay()
1239 ->getDisplayColorProfile()
1240 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1241 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001242 }
1243
1244 ui::Dataspace mOutDataspace;
1245 ui::ColorMode mOutColorMode;
1246 ui::RenderIntent mOutRenderIntent;
1247
1248private:
1249 ui::Dataspace mInputDataspace;
1250 ui::RenderIntent mInputRenderIntent;
1251 bool mHasWideColorGamut = false;
1252 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1253 FakeDisplayDeviceInjector mInjector;
1254};
1255
1256TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1257 addHwcColorModesMapping(ui::ColorMode::SRGB,
1258 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1259 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1260 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1261 setHasWideColorGamut(true);
1262
1263 getBestColorMode();
1264
Peiyong Lin14724e62018-12-05 07:27:30 -08001265 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001266 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1267 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1268}
1269
1270TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1271 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1272 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1273 addHwcColorModesMapping(ui::ColorMode::SRGB,
1274 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1275 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1276 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1277 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1278 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1279 setHasWideColorGamut(true);
1280
1281 getBestColorMode();
1282
1283 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1284 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1285 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1286}
1287
1288TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1289 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1290 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1291 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1292 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1293 setHasWideColorGamut(true);
1294
1295 getBestColorMode();
1296
1297 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1298 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1299 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1300}
1301
1302/* ------------------------------------------------------------------------
Lloyd Pique33050472019-12-19 17:12:44 -08001303 * DisplayDevice::setProjection
1304 */
1305
1306class DisplayDeviceSetProjectionTest : public DisplayTransactionTest {
1307public:
1308 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Lloyd Pique33050472019-12-19 17:12:44 -08001309 static constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1080; // arbitrary
1310 static constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1920; // arbitrary
1311
1312 static constexpr int32_t TRANSFORM_FLAGS_ROT_0 = 0;
1313 static constexpr int32_t TRANSFORM_FLAGS_ROT_90 = HAL_TRANSFORM_ROT_90;
1314 static constexpr int32_t TRANSFORM_FLAGS_ROT_180 = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V;
1315 static constexpr int32_t TRANSFORM_FLAGS_ROT_270 =
1316 HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
1317
1318 DisplayDeviceSetProjectionTest(ui::Size flingerDisplaySize, ui::Size hardwareDisplaySize,
1319 ui::Rotation physicalOrientation)
1320 : mFlingerDisplaySize(flingerDisplaySize),
1321 mHardwareDisplaySize(hardwareDisplaySize),
1322 mPhysicalOrientation(physicalOrientation),
1323 mDisplayDevice(createDisplayDevice()) {}
1324
1325 sp<DisplayDevice> createDisplayDevice() {
1326 // The DisplayDevice is required to have a framebuffer (behind the
1327 // ANativeWindow interface) which uses the actual hardware display
1328 // size.
1329 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1330 .WillRepeatedly(DoAll(SetArgPointee<1>(mHardwareDisplaySize.width), Return(0)));
1331 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1332 .WillRepeatedly(DoAll(SetArgPointee<1>(mHardwareDisplaySize.height), Return(0)));
1333 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT));
1334 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT));
1335 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64));
1336 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT));
1337
Dominik Laskowski55c85402020-01-21 16:25:47 -08001338 return FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID,
1339 DisplayConnectionType::Internal, true /* isPrimary */)
Lloyd Pique33050472019-12-19 17:12:44 -08001340 .setNativeWindow(mNativeWindow)
1341 .setPhysicalOrientation(mPhysicalOrientation)
1342 .inject();
1343 }
1344
1345 ui::Size SwapWH(const ui::Size size) const { return ui::Size(size.height, size.width); }
1346
1347 void setProjectionForRotation0() {
1348 // A logical rotation of 0 uses the SurfaceFlinger display size
1349 mDisplayDevice->setProjection(ui::ROTATION_0, Rect(mFlingerDisplaySize),
1350 Rect(mFlingerDisplaySize));
1351 }
1352
1353 void setProjectionForRotation90() {
1354 // A logical rotation of 90 uses the SurfaceFlinger display size with
1355 // the width/height swapped.
1356 mDisplayDevice->setProjection(ui::ROTATION_90, Rect(SwapWH(mFlingerDisplaySize)),
1357 Rect(SwapWH(mFlingerDisplaySize)));
1358 }
1359
1360 void setProjectionForRotation180() {
1361 // A logical rotation of 180 uses the SurfaceFlinger display size
1362 mDisplayDevice->setProjection(ui::ROTATION_180, Rect(mFlingerDisplaySize),
1363 Rect(mFlingerDisplaySize));
1364 }
1365
1366 void setProjectionForRotation270() {
1367 // A logical rotation of 270 uses the SurfaceFlinger display size with
1368 // the width/height swapped.
1369 mDisplayDevice->setProjection(ui::ROTATION_270, Rect(SwapWH(mFlingerDisplaySize)),
1370 Rect(SwapWH(mFlingerDisplaySize)));
1371 }
1372
1373 void expectStateForHardwareTransform0() {
1374 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1375 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_0, mHardwareDisplaySize.width,
1376 mHardwareDisplaySize.height),
1377 compositionState.transform);
1378 EXPECT_EQ(TRANSFORM_FLAGS_ROT_0, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001379 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1380 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001381 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1382 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1383 EXPECT_EQ(false, compositionState.needsFiltering);
1384 }
1385
1386 void expectStateForHardwareTransform90() {
1387 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1388 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width,
1389 mHardwareDisplaySize.height),
1390 compositionState.transform);
1391 EXPECT_EQ(TRANSFORM_FLAGS_ROT_90, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001392 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1393 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001394 // For 90, the frame and viewport have the hardware display size width and height swapped
1395 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1396 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1397 EXPECT_EQ(false, compositionState.needsFiltering);
1398 }
1399
1400 void expectStateForHardwareTransform180() {
1401 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1402 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width,
1403 mHardwareDisplaySize.height),
1404 compositionState.transform);
1405 EXPECT_EQ(TRANSFORM_FLAGS_ROT_180, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001406 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1407 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001408 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1409 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1410 EXPECT_EQ(false, compositionState.needsFiltering);
1411 }
1412
1413 void expectStateForHardwareTransform270() {
1414 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1415 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width,
1416 mHardwareDisplaySize.height),
1417 compositionState.transform);
1418 EXPECT_EQ(TRANSFORM_FLAGS_ROT_270, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001419 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1420 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001421 // For 270, the frame and viewport have the hardware display size width and height swapped
1422 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1423 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1424 EXPECT_EQ(false, compositionState.needsFiltering);
1425 }
1426
1427 const ui::Size mFlingerDisplaySize;
1428 const ui::Size mHardwareDisplaySize;
1429 const ui::Rotation mPhysicalOrientation;
1430 const sp<DisplayDevice> mDisplayDevice;
1431};
1432
1433struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest {
1434 DisplayDeviceSetProjectionTest_Installed0()
1435 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1436 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1437 ui::ROTATION_0) {}
1438};
1439
1440TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) {
1441 setProjectionForRotation0();
1442 expectStateForHardwareTransform0();
1443}
1444
1445TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) {
1446 setProjectionForRotation90();
1447 expectStateForHardwareTransform90();
1448}
1449
1450TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) {
1451 setProjectionForRotation180();
1452 expectStateForHardwareTransform180();
1453}
1454
1455TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) {
1456 setProjectionForRotation270();
1457 expectStateForHardwareTransform270();
1458}
1459
1460struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest {
1461 DisplayDeviceSetProjectionTest_Installed90()
1462 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1463 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1464 ui::ROTATION_90) {}
1465};
1466
1467TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) {
1468 setProjectionForRotation0();
1469 expectStateForHardwareTransform90();
1470}
1471
1472TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) {
1473 setProjectionForRotation90();
1474 expectStateForHardwareTransform180();
1475}
1476
1477TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) {
1478 setProjectionForRotation180();
1479 expectStateForHardwareTransform270();
1480}
1481
1482TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) {
1483 setProjectionForRotation270();
1484 expectStateForHardwareTransform0();
1485}
1486
1487struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest {
1488 DisplayDeviceSetProjectionTest_Installed180()
1489 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1490 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1491 ui::ROTATION_180) {}
1492};
1493
1494TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) {
1495 setProjectionForRotation0();
1496 expectStateForHardwareTransform180();
1497}
1498
1499TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) {
1500 setProjectionForRotation90();
1501 expectStateForHardwareTransform270();
1502}
1503
1504TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) {
1505 setProjectionForRotation180();
1506 expectStateForHardwareTransform0();
1507}
1508
1509TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) {
1510 setProjectionForRotation270();
1511 expectStateForHardwareTransform90();
1512}
1513
1514struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest {
1515 DisplayDeviceSetProjectionTest_Installed270()
1516 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1517 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1518 ui::ROTATION_270) {}
1519};
1520
1521TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) {
1522 setProjectionForRotation0();
1523 expectStateForHardwareTransform270();
1524}
1525
1526TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) {
1527 setProjectionForRotation90();
1528 expectStateForHardwareTransform0();
1529}
1530
1531TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) {
1532 setProjectionForRotation180();
1533 expectStateForHardwareTransform90();
1534}
1535
1536TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) {
1537 setProjectionForRotation270();
1538 expectStateForHardwareTransform180();
1539}
1540
1541/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001542 * SurfaceFlinger::getDisplayNativePrimaries
1543 */
1544
1545class GetDisplayNativePrimaries : public DisplayTransactionTest {
1546public:
1547 GetDisplayNativePrimaries();
1548 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1549 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1550
1551private:
1552 static constexpr float mStartingTestValue = 1.0f;
1553};
1554
1555GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1556 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1557 injectFakeNativeWindowSurfaceFactory();
1558}
1559
1560void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1561 ui::DisplayPrimaries& primaries) {
1562 float startingVal = mStartingTestValue;
1563 primaries.red.X = startingVal++;
1564 primaries.red.Y = startingVal++;
1565 primaries.red.Z = startingVal++;
1566 primaries.green.X = startingVal++;
1567 primaries.green.Y = startingVal++;
1568 primaries.green.Z = startingVal++;
1569 primaries.blue.X = startingVal++;
1570 primaries.blue.Y = startingVal++;
1571 primaries.blue.Z = startingVal++;
1572 primaries.white.X = startingVal++;
1573 primaries.white.Y = startingVal++;
1574 primaries.white.Z = startingVal++;
1575}
1576
1577void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1578 const ui::DisplayPrimaries& primaries) {
1579 float startingVal = mStartingTestValue;
1580 EXPECT_EQ(primaries.red.X, startingVal++);
1581 EXPECT_EQ(primaries.red.Y, startingVal++);
1582 EXPECT_EQ(primaries.red.Z, startingVal++);
1583 EXPECT_EQ(primaries.green.X, startingVal++);
1584 EXPECT_EQ(primaries.green.Y, startingVal++);
1585 EXPECT_EQ(primaries.green.Z, startingVal++);
1586 EXPECT_EQ(primaries.blue.X, startingVal++);
1587 EXPECT_EQ(primaries.blue.Y, startingVal++);
1588 EXPECT_EQ(primaries.blue.Z, startingVal++);
1589 EXPECT_EQ(primaries.white.X, startingVal++);
1590 EXPECT_EQ(primaries.white.Y, startingVal++);
1591 EXPECT_EQ(primaries.white.Z, startingVal++);
1592}
1593
1594TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1595 ui::DisplayPrimaries primaries;
1596 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1597}
1598
Daniel Solomon42d04562019-01-20 21:03:19 -08001599TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1600 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1601 injector.inject();
1602 auto internalDisplayToken = injector.token();
1603
1604 ui::DisplayPrimaries expectedPrimaries;
1605 populateDummyDisplayNativePrimaries(expectedPrimaries);
1606 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1607
1608 ui::DisplayPrimaries primaries;
1609 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1610
1611 checkDummyDisplayNativePrimaries(primaries);
1612}
1613
1614TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1615 sp<BBinder> notInternalDisplayToken = new BBinder();
1616
1617 ui::DisplayPrimaries primaries;
1618 populateDummyDisplayNativePrimaries(primaries);
1619 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1620
1621 // Check primaries argument wasn't modified in case of failure
1622 checkDummyDisplayNativePrimaries(primaries);
1623}
1624
1625/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001626 * SurfaceFlinger::setupNewDisplayDeviceInternal
1627 */
1628
1629class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1630public:
1631 template <typename T>
1632 void setupNewDisplayDeviceInternalTest();
1633};
1634
1635template <typename Case>
1636void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1637 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001638 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1639 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001640 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001641
1642 // --------------------------------------------------------------------
1643 // Preconditions
1644
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001645 // Wide color displays support is configured appropriately
1646 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001647
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001648 // The display is setup with the HWC.
1649 Case::Display::injectHwcDisplay(this);
1650
1651 // SurfaceFlinger will use a test-controlled factory for native window
1652 // surfaces.
1653 injectFakeNativeWindowSurfaceFactory();
1654
1655 // --------------------------------------------------------------------
1656 // Call Expectations
1657
1658 // Various native window calls will be made.
1659 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001660 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001661 Case::WideColorSupport::setupComposerCallExpectations(this);
1662 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001663 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001664
1665 // --------------------------------------------------------------------
1666 // Invocation
1667
1668 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -08001669 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1670 const auto displayId = Case::Display::DISPLAY_ID::get();
1671 ASSERT_TRUE(displayId);
1672 state.physical = {*displayId, *connectionType};
1673 }
1674
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001675 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1676
Dominik Laskowski075d3172018-05-24 15:50:06 -07001677 auto device =
1678 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1679 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001680
1681 // --------------------------------------------------------------------
1682 // Postconditions
1683
1684 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001685 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001686 EXPECT_EQ(Case::Display::CONNECTION_TYPE::value, device->getConnectionType());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001687 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001688 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001689 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001690 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1691 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1692 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001693 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001694 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1695 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1696 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001697 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1698 // remapped, and the test only ever sets up one config. If there were an error
1699 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
Ady Abraham2139f732019-11-13 18:56:40 -08001700 EXPECT_EQ(0, device->getActiveConfig().value());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001701 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1702 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001703}
1704
1705TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1706 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1707}
1708
1709TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1710 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1711}
1712
1713TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1714 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1715}
1716
1717TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001718 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001719
Dominik Laskowski075d3172018-05-24 15:50:06 -07001720 // Insert display data so that the HWC thinks it created the virtual display.
1721 const auto displayId = Case::Display::DISPLAY_ID::get();
1722 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001723 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001724
1725 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001726}
1727
1728TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1729 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1730}
1731
Valerie Haue9e843a2018-12-18 13:39:23 -08001732TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1733 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1734}
1735
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001736TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1737 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1738}
1739
1740TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1741 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1742}
1743
1744TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1745 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1746}
1747
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001748TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1749 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1750}
1751
1752TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1753 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1754}
1755
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001756/* ------------------------------------------------------------------------
1757 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1758 */
1759
1760class HandleTransactionLockedTest : public DisplayTransactionTest {
1761public:
1762 template <typename Case>
1763 void setupCommonPreconditions();
1764
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001765 template <typename Case, bool connected>
1766 static void expectHotplugReceived(mock::EventThread*);
1767
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001768 template <typename Case>
1769 void setupCommonCallExpectationsForConnectProcessing();
1770
1771 template <typename Case>
1772 void setupCommonCallExpectationsForDisconnectProcessing();
1773
1774 template <typename Case>
1775 void processesHotplugConnectCommon();
1776
1777 template <typename Case>
1778 void ignoresHotplugConnectCommon();
1779
1780 template <typename Case>
1781 void processesHotplugDisconnectCommon();
1782
1783 template <typename Case>
1784 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1785
1786 template <typename Case>
1787 void verifyPhysicalDisplayIsConnected();
1788
1789 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1790};
1791
1792template <typename Case>
1793void HandleTransactionLockedTest::setupCommonPreconditions() {
1794 // Wide color displays support is configured appropriately
1795 Case::WideColorSupport::injectConfigChange(this);
1796
1797 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1798 injectFakeBufferQueueFactory();
1799
1800 // SurfaceFlinger will use a test-controlled factory for native window
1801 // surfaces.
1802 injectFakeNativeWindowSurfaceFactory();
1803}
1804
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001805template <typename Case, bool connected>
1806void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1807 const auto convert = [](auto physicalDisplayId) {
1808 return std::make_optional(DisplayId{physicalDisplayId});
1809 };
1810
1811 EXPECT_CALL(*eventThread,
1812 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1813 .Times(1);
1814}
1815
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001816template <typename Case>
1817void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1818 Case::Display::setupHwcHotplugCallExpectations(this);
1819
1820 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1821 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1822 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1823 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1824
1825 Case::WideColorSupport::setupComposerCallExpectations(this);
1826 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001827 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001828
1829 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001830 expectHotplugReceived<Case, true>(mEventThread);
1831 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001832}
1833
1834template <typename Case>
1835void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1836 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001837
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001838 expectHotplugReceived<Case, false>(mEventThread);
1839 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001840}
1841
1842template <typename Case>
1843void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1844 // The display device should have been set up in the list of displays.
1845 ASSERT_TRUE(hasDisplayDevice(displayToken));
1846 const auto& device = getDisplayDevice(displayToken);
1847 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001848 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001849
Dominik Laskowski55c85402020-01-21 16:25:47 -08001850 std::optional<DisplayDeviceState::Physical> expectedPhysical;
1851 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1852 const auto displayId = Case::Display::DISPLAY_ID::get();
1853 ASSERT_TRUE(displayId);
1854 expectedPhysical = {*displayId, *connectionType};
1855 }
1856
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001857 // The display should have been set up in the current display state
1858 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1859 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001860 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001861 EXPECT_EQ(expectedPhysical, current.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001862
1863 // The display should have been set up in the drawing display state
1864 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1865 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001866 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001867 EXPECT_EQ(expectedPhysical, draw.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001868}
1869
1870template <typename Case>
1871void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1872 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001873 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001874
Dominik Laskowski075d3172018-05-24 15:50:06 -07001875 // SF should have a display token.
1876 const auto displayId = Case::Display::DISPLAY_ID::get();
1877 ASSERT_TRUE(displayId);
1878 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1879 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001880
1881 verifyDisplayIsConnected<Case>(displayToken);
1882}
1883
1884void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1885 EXPECT_FALSE(hasDisplayDevice(displayToken));
1886 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1887 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1888}
1889
1890template <typename Case>
1891void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1892 // --------------------------------------------------------------------
1893 // Preconditions
1894
1895 setupCommonPreconditions<Case>();
1896
1897 // A hotplug connect event is enqueued for a display
1898 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001899
1900 // --------------------------------------------------------------------
1901 // Call Expectations
1902
1903 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001904
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001905 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001906
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001907 // --------------------------------------------------------------------
1908 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001909
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001910 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001911
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001912 // --------------------------------------------------------------------
1913 // Postconditions
1914
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001915 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001916
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001917 // --------------------------------------------------------------------
1918 // Cleanup conditions
1919
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001920 EXPECT_CALL(*mComposer,
1921 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001922 .WillOnce(Return(Error::NONE));
1923 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001924}
1925
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001926template <typename Case>
1927void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1928 // --------------------------------------------------------------------
1929 // Preconditions
1930
1931 setupCommonPreconditions<Case>();
1932
1933 // A hotplug connect event is enqueued for a display
1934 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1935
1936 // --------------------------------------------------------------------
1937 // Invocation
1938
1939 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1940
1941 // --------------------------------------------------------------------
1942 // Postconditions
1943
1944 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001945 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001946}
1947
1948template <typename Case>
1949void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1950 // --------------------------------------------------------------------
1951 // Preconditions
1952
1953 setupCommonPreconditions<Case>();
1954
1955 // A hotplug disconnect event is enqueued for a display
1956 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1957
1958 // The display is already completely set up.
1959 Case::Display::injectHwcDisplay(this);
1960 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1961 existing.inject();
1962
1963 // --------------------------------------------------------------------
1964 // Call Expectations
1965
1966 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001967 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1968 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001969
1970 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1971
1972 // --------------------------------------------------------------------
1973 // Invocation
1974
1975 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1976
1977 // --------------------------------------------------------------------
1978 // Postconditions
1979
1980 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001981 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001982
Dominik Laskowski075d3172018-05-24 15:50:06 -07001983 // SF should not have a display token.
1984 const auto displayId = Case::Display::DISPLAY_ID::get();
1985 ASSERT_TRUE(displayId);
1986 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001987
1988 // The existing token should have been removed
1989 verifyDisplayIsNotConnected(existing.token());
1990}
1991
1992TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1993 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1994}
1995
1996TEST_F(HandleTransactionLockedTest,
1997 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1998 // Inject an external display.
1999 ExternalDisplayVariant::injectHwcDisplay(this);
2000
2001 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2002}
2003
2004TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
2005 // Inject a primary display.
2006 PrimaryDisplayVariant::injectHwcDisplay(this);
2007
2008 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
2009}
2010
2011TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
2012 // Inject both a primary and external display.
2013 PrimaryDisplayVariant::injectHwcDisplay(this);
2014 ExternalDisplayVariant::injectHwcDisplay(this);
2015
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002016 // TODO: This is an unnecessary call.
2017 EXPECT_CALL(*mComposer,
2018 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
2019 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
2020 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
2021 Return(Error::NONE)));
2022
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002023 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2024
2025 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
2026}
2027
2028TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
2029 // Inject a primary display.
2030 PrimaryDisplayVariant::injectHwcDisplay(this);
2031
2032 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
2033
2034 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
2035}
2036
2037TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
2038 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
2039}
2040
2041TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
2042 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
2043}
2044
2045TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
2046 using Case = SimplePrimaryDisplayCase;
2047
2048 // --------------------------------------------------------------------
2049 // Preconditions
2050
2051 setupCommonPreconditions<Case>();
2052
2053 // A hotplug connect event is enqueued for a display
2054 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
2055 // A hotplug disconnect event is also enqueued for the same display
2056 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
2057
2058 // --------------------------------------------------------------------
2059 // Call Expectations
2060
2061 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2062
2063 setupCommonCallExpectationsForConnectProcessing<Case>();
2064 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2065
2066 EXPECT_CALL(*mComposer,
2067 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2068 .WillOnce(Return(Error::NONE));
2069 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2070
2071 // --------------------------------------------------------------------
2072 // Invocation
2073
2074 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2075
2076 // --------------------------------------------------------------------
2077 // Postconditions
2078
2079 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002080 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002081
Dominik Laskowski075d3172018-05-24 15:50:06 -07002082 // SF should not have a display token.
2083 const auto displayId = Case::Display::DISPLAY_ID::get();
2084 ASSERT_TRUE(displayId);
2085 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002086}
2087
2088TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
2089 using Case = SimplePrimaryDisplayCase;
2090
2091 // --------------------------------------------------------------------
2092 // Preconditions
2093
2094 setupCommonPreconditions<Case>();
2095
2096 // The display is already completely set up.
2097 Case::Display::injectHwcDisplay(this);
2098 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2099 existing.inject();
2100
2101 // A hotplug disconnect event is enqueued for a display
2102 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
2103 // A hotplug connect event is also enqueued for the same display
2104 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
2105
2106 // --------------------------------------------------------------------
2107 // Call Expectations
2108
2109 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2110
2111 setupCommonCallExpectationsForConnectProcessing<Case>();
2112 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2113
2114 // --------------------------------------------------------------------
2115 // Invocation
2116
2117 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2118
2119 // --------------------------------------------------------------------
2120 // Postconditions
2121
2122 // The existing token should have been removed
2123 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07002124 const auto displayId = Case::Display::DISPLAY_ID::get();
2125 ASSERT_TRUE(displayId);
2126 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
2127 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002128
2129 // A new display should be connected in its place
2130
2131 verifyPhysicalDisplayIsConnected<Case>();
2132
2133 // --------------------------------------------------------------------
2134 // Cleanup conditions
2135
2136 EXPECT_CALL(*mComposer,
2137 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2138 .WillOnce(Return(Error::NONE));
2139 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2140}
2141
2142TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
2143 using Case = HwcVirtualDisplayCase;
2144
2145 // --------------------------------------------------------------------
2146 // Preconditions
2147
2148 // The HWC supports at least one virtual display
2149 injectMockComposer(1);
2150
2151 setupCommonPreconditions<Case>();
2152
2153 // A virtual display was added to the current state, and it has a
2154 // surface(producer)
2155 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07002156
Dominik Laskowski075d3172018-05-24 15:50:06 -07002157 DisplayDeviceState state;
2158 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002159
2160 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07002161 state.surface = surface;
2162 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002163
2164 // --------------------------------------------------------------------
2165 // Call Expectations
2166
2167 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
2168 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
2169
2170 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
2171 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
2172 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
2173 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
2174 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
2175 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
2176 Return(NO_ERROR)));
2177 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
2178 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
2179
2180 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
2181
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002182 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002183 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
2184
2185 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
2186 Case::WideColorSupport::setupComposerCallExpectations(this);
2187 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07002188 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002189
2190 // --------------------------------------------------------------------
2191 // Invocation
2192
2193 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2194
2195 // --------------------------------------------------------------------
2196 // Postconditions
2197
2198 // The display device should have been set up in the list of displays.
2199 verifyDisplayIsConnected<Case>(displayToken);
2200
2201 // --------------------------------------------------------------------
2202 // Cleanup conditions
2203
2204 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
2205 .WillOnce(Return(Error::NONE));
2206 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08002207
2208 // Cleanup
2209 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
2210 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002211}
2212
2213TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
2214 using Case = HwcVirtualDisplayCase;
2215
2216 // --------------------------------------------------------------------
2217 // Preconditions
2218
2219 // The HWC supports at least one virtual display
2220 injectMockComposer(1);
2221
2222 setupCommonPreconditions<Case>();
2223
2224 // A virtual display was added to the current state, but it does not have a
2225 // surface.
2226 sp<BBinder> displayToken = new BBinder();
2227
Dominik Laskowski075d3172018-05-24 15:50:06 -07002228 DisplayDeviceState state;
2229 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002230
Dominik Laskowski075d3172018-05-24 15:50:06 -07002231 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002232
2233 // --------------------------------------------------------------------
2234 // Call Expectations
2235
2236 // --------------------------------------------------------------------
2237 // Invocation
2238
2239 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2240
2241 // --------------------------------------------------------------------
2242 // Postconditions
2243
2244 // There will not be a display device set up.
2245 EXPECT_FALSE(hasDisplayDevice(displayToken));
2246
2247 // The drawing display state will be set from the current display state.
2248 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2249 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002250 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002251}
2252
2253TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
2254 using Case = HwcVirtualDisplayCase;
2255
2256 // --------------------------------------------------------------------
2257 // Preconditions
2258
2259 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002260 const auto displayId = Case::Display::DISPLAY_ID::get();
2261 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08002262 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002263 Case::Display::injectHwcDisplay(this);
2264 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2265 existing.inject();
2266 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2267
2268 // --------------------------------------------------------------------
2269 // Call Expectations
2270
2271 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2272
2273 // --------------------------------------------------------------------
2274 // Invocation
2275
2276 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2277
2278 // --------------------------------------------------------------------
2279 // Postconditions
2280
2281 // The existing token should have been removed
2282 verifyDisplayIsNotConnected(existing.token());
2283}
2284
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002285TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2286 using Case = NonHwcVirtualDisplayCase;
2287
2288 constexpr uint32_t oldLayerStack = 0u;
2289 constexpr uint32_t newLayerStack = 123u;
2290
2291 // --------------------------------------------------------------------
2292 // Preconditions
2293
2294 // A display is set up
2295 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2296 display.inject();
2297
2298 // There is a change to the layerStack state
2299 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2300 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2301
2302 // --------------------------------------------------------------------
2303 // Invocation
2304
2305 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2306
2307 // --------------------------------------------------------------------
2308 // Postconditions
2309
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002310 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002311}
2312
2313TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2314 using Case = NonHwcVirtualDisplayCase;
2315
Dominik Laskowski718f9602019-11-09 20:01:35 -08002316 constexpr ui::Rotation oldTransform = ui::ROTATION_0;
2317 constexpr ui::Rotation newTransform = ui::ROTATION_180;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002318
2319 // --------------------------------------------------------------------
2320 // Preconditions
2321
2322 // A display is set up
2323 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2324 display.inject();
2325
2326 // There is a change to the orientation state
2327 display.mutableDrawingDisplayState().orientation = oldTransform;
2328 display.mutableCurrentDisplayState().orientation = newTransform;
2329
2330 // --------------------------------------------------------------------
2331 // Invocation
2332
2333 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2334
2335 // --------------------------------------------------------------------
2336 // Postconditions
2337
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002338 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002339}
2340
2341TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2342 using Case = NonHwcVirtualDisplayCase;
2343
2344 const Rect oldViewport(0, 0, 0, 0);
2345 const Rect newViewport(0, 0, 123, 456);
2346
2347 // --------------------------------------------------------------------
2348 // Preconditions
2349
2350 // A display is set up
2351 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2352 display.inject();
2353
2354 // There is a change to the viewport state
2355 display.mutableDrawingDisplayState().viewport = oldViewport;
2356 display.mutableCurrentDisplayState().viewport = newViewport;
2357
2358 // --------------------------------------------------------------------
2359 // Invocation
2360
2361 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2362
2363 // --------------------------------------------------------------------
2364 // Postconditions
2365
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002366 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002367}
2368
2369TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2370 using Case = NonHwcVirtualDisplayCase;
2371
2372 const Rect oldFrame(0, 0, 0, 0);
2373 const Rect newFrame(0, 0, 123, 456);
2374
2375 // --------------------------------------------------------------------
2376 // Preconditions
2377
2378 // A display is set up
2379 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2380 display.inject();
2381
2382 // There is a change to the viewport state
2383 display.mutableDrawingDisplayState().frame = oldFrame;
2384 display.mutableCurrentDisplayState().frame = newFrame;
2385
2386 // --------------------------------------------------------------------
2387 // Invocation
2388
2389 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2390
2391 // --------------------------------------------------------------------
2392 // Postconditions
2393
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002394 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002395}
2396
2397TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2398 using Case = NonHwcVirtualDisplayCase;
2399
2400 constexpr int oldWidth = 0;
2401 constexpr int oldHeight = 10;
2402 constexpr int newWidth = 123;
2403
2404 // --------------------------------------------------------------------
2405 // Preconditions
2406
2407 // A display is set up
2408 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002409 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002410 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002411 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2412 display.setNativeWindow(nativeWindow);
2413 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002414 // Setup injection expections
2415 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2416 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2417 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2418 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002419 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2420 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2421 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002422 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002423 display.inject();
2424
2425 // There is a change to the viewport state
2426 display.mutableDrawingDisplayState().width = oldWidth;
2427 display.mutableDrawingDisplayState().height = oldHeight;
2428 display.mutableCurrentDisplayState().width = newWidth;
2429 display.mutableCurrentDisplayState().height = oldHeight;
2430
2431 // --------------------------------------------------------------------
2432 // Call Expectations
2433
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002434 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002435
2436 // --------------------------------------------------------------------
2437 // Invocation
2438
2439 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2440}
2441
2442TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2443 using Case = NonHwcVirtualDisplayCase;
2444
2445 constexpr int oldWidth = 0;
2446 constexpr int oldHeight = 10;
2447 constexpr int newHeight = 123;
2448
2449 // --------------------------------------------------------------------
2450 // Preconditions
2451
2452 // A display is set up
2453 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002454 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002455 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002456 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2457 display.setNativeWindow(nativeWindow);
2458 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002459 // Setup injection expections
2460 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2461 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2462 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2463 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002464 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2465 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2466 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002467 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002468 display.inject();
2469
2470 // There is a change to the viewport state
2471 display.mutableDrawingDisplayState().width = oldWidth;
2472 display.mutableDrawingDisplayState().height = oldHeight;
2473 display.mutableCurrentDisplayState().width = oldWidth;
2474 display.mutableCurrentDisplayState().height = newHeight;
2475
2476 // --------------------------------------------------------------------
2477 // Call Expectations
2478
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002479 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002480
2481 // --------------------------------------------------------------------
2482 // Invocation
2483
2484 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2485}
2486
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002487/* ------------------------------------------------------------------------
2488 * SurfaceFlinger::setDisplayStateLocked
2489 */
2490
2491TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2492 // --------------------------------------------------------------------
2493 // Preconditions
2494
2495 // We have an unknown display token not associated with a known display
2496 sp<BBinder> displayToken = new BBinder();
2497
2498 // The requested display state references the unknown display.
2499 DisplayState state;
2500 state.what = DisplayState::eLayerStackChanged;
2501 state.token = displayToken;
2502 state.layerStack = 456;
2503
2504 // --------------------------------------------------------------------
2505 // Invocation
2506
2507 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2508
2509 // --------------------------------------------------------------------
2510 // Postconditions
2511
2512 // The returned flags are empty
2513 EXPECT_EQ(0u, flags);
2514
2515 // The display token still doesn't match anything known.
2516 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2517}
2518
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002519TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2520 using Case = SimplePrimaryDisplayCase;
2521
2522 // --------------------------------------------------------------------
2523 // Preconditions
2524
2525 // A display is already set up
2526 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2527 display.inject();
2528
2529 // No changes are made to the display
2530 DisplayState state;
2531 state.what = 0;
2532 state.token = display.token();
2533
2534 // --------------------------------------------------------------------
2535 // Invocation
2536
2537 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2538
2539 // --------------------------------------------------------------------
2540 // Postconditions
2541
2542 // The returned flags are empty
2543 EXPECT_EQ(0u, flags);
2544}
2545
2546TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2547 using Case = SimplePrimaryDisplayCase;
2548
2549 // --------------------------------------------------------------------
2550 // Preconditions
2551
2552 // A display is already set up
2553 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2554 display.inject();
2555
2556 // There is a surface that can be set.
2557 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2558
2559 // The current display state has the surface set
2560 display.mutableCurrentDisplayState().surface = surface;
2561
2562 // The incoming request sets the same surface
2563 DisplayState state;
2564 state.what = DisplayState::eSurfaceChanged;
2565 state.token = display.token();
2566 state.surface = surface;
2567
2568 // --------------------------------------------------------------------
2569 // Invocation
2570
2571 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2572
2573 // --------------------------------------------------------------------
2574 // Postconditions
2575
2576 // The returned flags are empty
2577 EXPECT_EQ(0u, flags);
2578
2579 // The current display state is unchanged.
2580 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2581}
2582
2583TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2584 using Case = SimplePrimaryDisplayCase;
2585
2586 // --------------------------------------------------------------------
2587 // Preconditions
2588
2589 // A display is already set up
2590 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2591 display.inject();
2592
2593 // There is a surface that can be set.
2594 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2595
2596 // The current display state does not have a surface
2597 display.mutableCurrentDisplayState().surface = nullptr;
2598
2599 // The incoming request sets a surface
2600 DisplayState state;
2601 state.what = DisplayState::eSurfaceChanged;
2602 state.token = display.token();
2603 state.surface = surface;
2604
2605 // --------------------------------------------------------------------
2606 // Invocation
2607
2608 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2609
2610 // --------------------------------------------------------------------
2611 // Postconditions
2612
2613 // The returned flags indicate a transaction is needed
2614 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2615
2616 // The current display layer stack state is set to the new value
2617 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2618}
2619
2620TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2621 using Case = SimplePrimaryDisplayCase;
2622
2623 // --------------------------------------------------------------------
2624 // Preconditions
2625
2626 // A display is already set up
2627 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2628 display.inject();
2629
2630 // The display has a layer stack set
2631 display.mutableCurrentDisplayState().layerStack = 456u;
2632
2633 // The incoming request sets the same layer stack
2634 DisplayState state;
2635 state.what = DisplayState::eLayerStackChanged;
2636 state.token = display.token();
2637 state.layerStack = 456u;
2638
2639 // --------------------------------------------------------------------
2640 // Invocation
2641
2642 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2643
2644 // --------------------------------------------------------------------
2645 // Postconditions
2646
2647 // The returned flags are empty
2648 EXPECT_EQ(0u, flags);
2649
2650 // The current display state is unchanged
2651 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2652}
2653
2654TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2655 using Case = SimplePrimaryDisplayCase;
2656
2657 // --------------------------------------------------------------------
2658 // Preconditions
2659
2660 // A display is set up
2661 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2662 display.inject();
2663
2664 // The display has a layer stack set
2665 display.mutableCurrentDisplayState().layerStack = 654u;
2666
2667 // The incoming request sets a different layer stack
2668 DisplayState state;
2669 state.what = DisplayState::eLayerStackChanged;
2670 state.token = display.token();
2671 state.layerStack = 456u;
2672
2673 // --------------------------------------------------------------------
2674 // Invocation
2675
2676 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2677
2678 // --------------------------------------------------------------------
2679 // Postconditions
2680
2681 // The returned flags indicate a transaction is needed
2682 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2683
2684 // The desired display state has been set to the new value.
2685 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2686}
2687
2688TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2689 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002690 constexpr ui::Rotation initialOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002691 const Rect initialFrame = {1, 2, 3, 4};
2692 const Rect initialViewport = {5, 6, 7, 8};
2693
2694 // --------------------------------------------------------------------
2695 // Preconditions
2696
2697 // A display is set up
2698 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2699 display.inject();
2700
2701 // The current display state projection state is all set
2702 display.mutableCurrentDisplayState().orientation = initialOrientation;
2703 display.mutableCurrentDisplayState().frame = initialFrame;
2704 display.mutableCurrentDisplayState().viewport = initialViewport;
2705
2706 // The incoming request sets the same projection state
2707 DisplayState state;
2708 state.what = DisplayState::eDisplayProjectionChanged;
2709 state.token = display.token();
2710 state.orientation = initialOrientation;
2711 state.frame = initialFrame;
2712 state.viewport = initialViewport;
2713
2714 // --------------------------------------------------------------------
2715 // Invocation
2716
2717 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2718
2719 // --------------------------------------------------------------------
2720 // Postconditions
2721
2722 // The returned flags are empty
2723 EXPECT_EQ(0u, flags);
2724
2725 // The current display state is unchanged
2726 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2727
2728 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2729 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2730}
2731
2732TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2733 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002734 constexpr ui::Rotation initialOrientation = ui::ROTATION_90;
2735 constexpr ui::Rotation desiredOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002736
2737 // --------------------------------------------------------------------
2738 // Preconditions
2739
2740 // A display is set up
2741 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2742 display.inject();
2743
2744 // The current display state has an orientation set
2745 display.mutableCurrentDisplayState().orientation = initialOrientation;
2746
2747 // The incoming request sets a different orientation
2748 DisplayState state;
2749 state.what = DisplayState::eDisplayProjectionChanged;
2750 state.token = display.token();
2751 state.orientation = desiredOrientation;
2752
2753 // --------------------------------------------------------------------
2754 // Invocation
2755
2756 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2757
2758 // --------------------------------------------------------------------
2759 // Postconditions
2760
2761 // The returned flags indicate a transaction is needed
2762 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2763
2764 // The current display state has the new value.
2765 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2766}
2767
2768TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2769 using Case = SimplePrimaryDisplayCase;
2770 const Rect initialFrame = {0, 0, 0, 0};
2771 const Rect desiredFrame = {5, 6, 7, 8};
2772
2773 // --------------------------------------------------------------------
2774 // Preconditions
2775
2776 // A display is set up
2777 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2778 display.inject();
2779
2780 // The current display state does not have a frame
2781 display.mutableCurrentDisplayState().frame = initialFrame;
2782
2783 // The incoming request sets a frame
2784 DisplayState state;
2785 state.what = DisplayState::eDisplayProjectionChanged;
2786 state.token = display.token();
2787 state.frame = desiredFrame;
2788
2789 // --------------------------------------------------------------------
2790 // Invocation
2791
2792 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2793
2794 // --------------------------------------------------------------------
2795 // Postconditions
2796
2797 // The returned flags indicate a transaction is needed
2798 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2799
2800 // The current display state has the new value.
2801 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2802}
2803
2804TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2805 using Case = SimplePrimaryDisplayCase;
2806 const Rect initialViewport = {0, 0, 0, 0};
2807 const Rect desiredViewport = {5, 6, 7, 8};
2808
2809 // --------------------------------------------------------------------
2810 // Preconditions
2811
2812 // A display is set up
2813 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2814 display.inject();
2815
2816 // The current display state does not have a viewport
2817 display.mutableCurrentDisplayState().viewport = initialViewport;
2818
2819 // The incoming request sets a viewport
2820 DisplayState state;
2821 state.what = DisplayState::eDisplayProjectionChanged;
2822 state.token = display.token();
2823 state.viewport = desiredViewport;
2824
2825 // --------------------------------------------------------------------
2826 // Invocation
2827
2828 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2829
2830 // --------------------------------------------------------------------
2831 // Postconditions
2832
2833 // The returned flags indicate a transaction is needed
2834 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2835
2836 // The current display state has the new value.
2837 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2838}
2839
2840TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2841 using Case = SimplePrimaryDisplayCase;
2842 constexpr uint32_t initialWidth = 1024;
2843 constexpr uint32_t initialHeight = 768;
2844
2845 // --------------------------------------------------------------------
2846 // Preconditions
2847
2848 // A display is set up
2849 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2850 display.inject();
2851
2852 // The current display state has a size set
2853 display.mutableCurrentDisplayState().width = initialWidth;
2854 display.mutableCurrentDisplayState().height = initialHeight;
2855
2856 // The incoming request sets the same display size
2857 DisplayState state;
2858 state.what = DisplayState::eDisplaySizeChanged;
2859 state.token = display.token();
2860 state.width = initialWidth;
2861 state.height = initialHeight;
2862
2863 // --------------------------------------------------------------------
2864 // Invocation
2865
2866 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2867
2868 // --------------------------------------------------------------------
2869 // Postconditions
2870
2871 // The returned flags are empty
2872 EXPECT_EQ(0u, flags);
2873
2874 // The current display state is unchanged
2875 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2876 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2877}
2878
2879TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2880 using Case = SimplePrimaryDisplayCase;
2881 constexpr uint32_t initialWidth = 0;
2882 constexpr uint32_t desiredWidth = 1024;
2883
2884 // --------------------------------------------------------------------
2885 // Preconditions
2886
2887 // A display is set up
2888 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2889 display.inject();
2890
2891 // The display does not yet have a width
2892 display.mutableCurrentDisplayState().width = initialWidth;
2893
2894 // The incoming request sets a display width
2895 DisplayState state;
2896 state.what = DisplayState::eDisplaySizeChanged;
2897 state.token = display.token();
2898 state.width = desiredWidth;
2899
2900 // --------------------------------------------------------------------
2901 // Invocation
2902
2903 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2904
2905 // --------------------------------------------------------------------
2906 // Postconditions
2907
2908 // The returned flags indicate a transaction is needed
2909 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2910
2911 // The current display state has the new value.
2912 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2913}
2914
2915TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2916 using Case = SimplePrimaryDisplayCase;
2917 constexpr uint32_t initialHeight = 0;
2918 constexpr uint32_t desiredHeight = 768;
2919
2920 // --------------------------------------------------------------------
2921 // Preconditions
2922
2923 // A display is set up
2924 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2925 display.inject();
2926
2927 // The display does not yet have a height
2928 display.mutableCurrentDisplayState().height = initialHeight;
2929
2930 // The incoming request sets a display height
2931 DisplayState state;
2932 state.what = DisplayState::eDisplaySizeChanged;
2933 state.token = display.token();
2934 state.height = desiredHeight;
2935
2936 // --------------------------------------------------------------------
2937 // Invocation
2938
2939 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2940
2941 // --------------------------------------------------------------------
2942 // Postconditions
2943
2944 // The returned flags indicate a transaction is needed
2945 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2946
2947 // The current display state has the new value.
2948 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2949}
2950
Lloyd Pique86016da2018-03-01 16:09:38 -08002951/* ------------------------------------------------------------------------
2952 * SurfaceFlinger::onInitializeDisplays
2953 */
2954
2955TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2956 using Case = SimplePrimaryDisplayCase;
2957
2958 // --------------------------------------------------------------------
2959 // Preconditions
2960
2961 // A primary display is set up
2962 Case::Display::injectHwcDisplay(this);
2963 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2964 primaryDisplay.inject();
2965
2966 // --------------------------------------------------------------------
2967 // Call Expectations
2968
2969 // We expect the surface interceptor to possibly be used, but we treat it as
2970 // disabled since it is called as a side effect rather than directly by this
2971 // function.
2972 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2973
2974 // We expect a call to get the active display config.
2975 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2976
2977 // We expect invalidate() to be invoked once to trigger display transaction
2978 // processing.
2979 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2980
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002981 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2982
Lloyd Pique86016da2018-03-01 16:09:38 -08002983 // --------------------------------------------------------------------
2984 // Invocation
2985
2986 mFlinger.onInitializeDisplays();
2987
2988 // --------------------------------------------------------------------
2989 // Postconditions
2990
2991 // The primary display should have a current state
2992 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2993 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2994 // The layer stack state should be set to zero
2995 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2996 // The orientation state should be set to zero
Dominik Laskowski718f9602019-11-09 20:01:35 -08002997 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
Lloyd Pique86016da2018-03-01 16:09:38 -08002998
2999 // The frame state should be set to INVALID
3000 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
3001
3002 // The viewport state should be set to INVALID
3003 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
3004
3005 // The width and height should both be zero
3006 EXPECT_EQ(0u, primaryDisplayState.width);
3007 EXPECT_EQ(0u, primaryDisplayState.height);
3008
3009 // The display should be set to HWC_POWER_MODE_NORMAL
3010 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
3011 auto displayDevice = primaryDisplay.mutableDisplayDevice();
3012 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
3013
3014 // The display refresh period should be set in the frame tracker.
3015 FrameStats stats;
3016 mFlinger.getAnimFrameTracker().getStats(&stats);
3017 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
3018
3019 // The display transaction needed flag should be set.
3020 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
3021
3022 // The compositor timing should be set to default values
3023 const auto& compositorTiming = mFlinger.getCompositorTiming();
3024 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
3025 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
3026 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
3027}
3028
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003029/* ------------------------------------------------------------------------
3030 * SurfaceFlinger::setPowerModeInternal
3031 */
3032
3033// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07003034template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003035struct DozeIsSupportedVariant {
3036 static constexpr bool DOZE_SUPPORTED = true;
3037 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3038 IComposerClient::PowerMode::DOZE;
3039 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3040 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07003041
3042 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3043 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
3044 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
3045 {Hwc2::DisplayCapability::DOZE})),
3046 Return(Error::NONE)));
3047 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003048};
3049
Peiyong Lined531a32018-10-26 18:27:56 -07003050template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003051// Used when we simulate a display that does not support doze.
3052struct DozeNotSupportedVariant {
3053 static constexpr bool DOZE_SUPPORTED = false;
3054 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3055 IComposerClient::PowerMode::ON;
3056 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3057 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07003058
3059 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3060 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
3061 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
3062 Return(Error::NONE)));
3063 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003064};
3065
3066struct EventThreadBaseSupportedVariant {
3067 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
3068 // The event control thread should not be notified.
3069 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
3070
3071 // The event thread should not be notified.
3072 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
3073 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
3074 }
3075};
3076
3077struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
3078 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3079 // These calls are only expected for the primary display.
3080
3081 // Instead expect no calls.
3082 setupEventAndEventControlThreadNoCallExpectations(test);
3083 }
3084
3085 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3086 // These calls are only expected for the primary display.
3087
3088 // Instead expect no calls.
3089 setupEventAndEventControlThreadNoCallExpectations(test);
3090 }
3091};
3092
3093struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
3094 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3095 // The event control thread should be notified to enable vsyncs
3096 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
3097
3098 // The event thread should be notified that the screen was acquired.
3099 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
3100 }
3101
3102 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3103 // There should be a call to setVsyncEnabled(false)
3104 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
3105
3106 // The event thread should not be notified that the screen was released.
3107 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
3108 }
3109};
3110
Lloyd Pique41be5d22018-06-21 13:11:48 -07003111struct DispSyncIsSupportedVariant {
3112 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique41be5d22018-06-21 13:11:48 -07003113 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
3114 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
3115 }
3116
3117 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
3118 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
3119 }
3120};
3121
3122struct DispSyncNotSupportedVariant {
3123 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3124
3125 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3126};
3127
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003128// --------------------------------------------------------------------
3129// Note:
3130//
3131// There are a large number of transitions we could test, however we only test a
3132// selected subset which provides complete test coverage of the implementation.
3133// --------------------------------------------------------------------
3134
3135template <int initialPowerMode, int targetPowerMode>
3136struct TransitionVariantCommon {
3137 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
3138 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
3139
3140 static void verifyPostconditions(DisplayTransactionTest*) {}
3141};
3142
3143struct TransitionOffToOnVariant
3144 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
3145 template <typename Case>
3146 static void setupCallExpectations(DisplayTransactionTest* test) {
3147 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3148 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003149 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003150 Case::setupRepaintEverythingCallExpectations(test);
3151 }
3152
3153 static void verifyPostconditions(DisplayTransactionTest* test) {
3154 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3155 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3156 }
3157};
3158
3159struct TransitionOffToDozeSuspendVariant
3160 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
3161 template <typename Case>
3162 static void setupCallExpectations(DisplayTransactionTest* test) {
3163 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3164 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3165 Case::setupRepaintEverythingCallExpectations(test);
3166 }
3167
3168 static void verifyPostconditions(DisplayTransactionTest* test) {
3169 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3170 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3171 }
3172};
3173
3174struct TransitionOnToOffVariant
3175 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
3176 template <typename Case>
3177 static void setupCallExpectations(DisplayTransactionTest* test) {
3178 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003179 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003180 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3181 }
3182
3183 static void verifyPostconditions(DisplayTransactionTest* test) {
3184 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3185 }
3186};
3187
3188struct TransitionDozeSuspendToOffVariant
3189 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
3190 template <typename Case>
3191 static void setupCallExpectations(DisplayTransactionTest* test) {
3192 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3193 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3194 }
3195
3196 static void verifyPostconditions(DisplayTransactionTest* test) {
3197 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3198 }
3199};
3200
3201struct TransitionOnToDozeVariant
3202 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
3203 template <typename Case>
3204 static void setupCallExpectations(DisplayTransactionTest* test) {
3205 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3206 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3207 }
3208};
3209
3210struct TransitionDozeSuspendToDozeVariant
3211 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
3212 template <typename Case>
3213 static void setupCallExpectations(DisplayTransactionTest* test) {
3214 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003215 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003216 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3217 }
3218};
3219
3220struct TransitionDozeToOnVariant
3221 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
3222 template <typename Case>
3223 static void setupCallExpectations(DisplayTransactionTest* test) {
3224 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3225 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3226 }
3227};
3228
3229struct TransitionDozeSuspendToOnVariant
3230 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
3231 template <typename Case>
3232 static void setupCallExpectations(DisplayTransactionTest* test) {
3233 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003234 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003235 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3236 }
3237};
3238
3239struct TransitionOnToDozeSuspendVariant
3240 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
3241 template <typename Case>
3242 static void setupCallExpectations(DisplayTransactionTest* test) {
3243 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003244 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003245 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3246 }
3247};
3248
3249struct TransitionOnToUnknownVariant
3250 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
3251 template <typename Case>
3252 static void setupCallExpectations(DisplayTransactionTest* test) {
3253 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3254 Case::setupNoComposerPowerModeCallExpectations(test);
3255 }
3256};
3257
3258// --------------------------------------------------------------------
3259// Note:
3260//
3261// Rather than testing the cartesian product of of
3262// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3263// display type, and the other for another display type.
3264// --------------------------------------------------------------------
3265
3266template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003267 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003268struct DisplayPowerCase {
3269 using Display = DisplayVariant;
3270 using Doze = DozeVariant;
3271 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003272 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003273 using Transition = TransitionVariant;
3274
3275 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003276 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003277 auto display = Display::makeFakeExistingDisplayInjector(test);
3278 display.inject();
3279 display.mutableDisplayDevice()->setPowerMode(mode);
3280 return display;
3281 }
3282
3283 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003284 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003285 }
3286
3287 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3288 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3289 }
3290
3291 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3292 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3293 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3294 }
3295
3296 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3297 IComposerClient::PowerMode mode) {
3298 // Any calls to get the active config will return a default value.
3299 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3300 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3301 Return(Error::NONE)));
3302
3303 // Any calls to get whether the display supports dozing will return the value set by the
3304 // policy variant.
3305 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3306 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3307
3308 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3309 }
3310
3311 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3312 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3313 }
3314};
3315
3316// A sample configuration for the primary display.
3317// In addition to having event thread support, we emulate doze support.
3318template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003319using PrimaryDisplayPowerCase =
3320 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3321 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3322 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003323
3324// A sample configuration for the external display.
3325// In addition to not having event thread support, we emulate not having doze
3326// support.
3327template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003328using ExternalDisplayPowerCase =
3329 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3330 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3331 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003332
3333class SetPowerModeInternalTest : public DisplayTransactionTest {
3334public:
3335 template <typename Case>
3336 void transitionDisplayCommon();
3337};
3338
3339template <int PowerMode>
3340struct PowerModeInitialVSyncEnabled : public std::false_type {};
3341
3342template <>
3343struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3344
3345template <>
3346struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3347
3348template <typename Case>
3349void SetPowerModeInternalTest::transitionDisplayCommon() {
3350 // --------------------------------------------------------------------
3351 // Preconditions
3352
Peiyong Lined531a32018-10-26 18:27:56 -07003353 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003354 auto display =
3355 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3356 Case::setInitialPrimaryHWVsyncEnabled(this,
3357 PowerModeInitialVSyncEnabled<
3358 Case::Transition::INITIAL_POWER_MODE>::value);
3359
3360 // --------------------------------------------------------------------
3361 // Call Expectations
3362
3363 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3364 Case::Transition::template setupCallExpectations<Case>(this);
3365
3366 // --------------------------------------------------------------------
3367 // Invocation
3368
3369 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3370 Case::Transition::TARGET_POWER_MODE);
3371
3372 // --------------------------------------------------------------------
3373 // Postconditions
3374
3375 Case::Transition::verifyPostconditions(this);
3376}
3377
3378TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3379 using Case = SimplePrimaryDisplayCase;
3380
3381 // --------------------------------------------------------------------
3382 // Preconditions
3383
3384 // A primary display device is set up
3385 Case::Display::injectHwcDisplay(this);
3386 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3387 display.inject();
3388
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003389 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003390 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3391
3392 // --------------------------------------------------------------------
3393 // Invocation
3394
3395 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3396
3397 // --------------------------------------------------------------------
3398 // Postconditions
3399
3400 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3401}
3402
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003403TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003404 using Case = HwcVirtualDisplayCase;
3405
3406 // --------------------------------------------------------------------
3407 // Preconditions
3408
Dominik Laskowski075d3172018-05-24 15:50:06 -07003409 // Insert display data so that the HWC thinks it created the virtual display.
3410 const auto displayId = Case::Display::DISPLAY_ID::get();
3411 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003412 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003413
3414 // A virtual display device is set up
3415 Case::Display::injectHwcDisplay(this);
3416 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3417 display.inject();
3418
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003419 // The display is set to HWC_POWER_MODE_NORMAL
3420 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003421
3422 // --------------------------------------------------------------------
3423 // Invocation
3424
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003425 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003426
3427 // --------------------------------------------------------------------
3428 // Postconditions
3429
3430 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3431}
3432
3433TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3434 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3435}
3436
3437TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3438 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3439}
3440
3441TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3442 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3443}
3444
3445TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3446 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3447}
3448
3449TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3450 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3451}
3452
3453TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3454 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3455}
3456
3457TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3458 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3459}
3460
3461TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3462 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3463}
3464
3465TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3466 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3467}
3468
3469TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3470 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3471}
3472
3473TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3474 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3475}
3476
3477TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3478 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3479}
3480
3481TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3482 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3483}
3484
3485TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3486 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3487}
3488
3489TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3490 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3491}
3492
3493TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3494 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3495}
3496
3497TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3498 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3499}
3500
3501TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3502 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3503}
3504
3505TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3506 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3507}
3508
3509TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3510 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3511}
3512
Lloyd Piquef58625d2017-12-19 13:22:33 -08003513} // namespace
3514} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08003515
3516// TODO(b/129481165): remove the #pragma below and fix conversion issues
3517#pragma clang diagnostic pop // ignored "-Wconversion"