blob: 23d6df799d32b1a8afd554c315287ddd2732f80c [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 Piqueaad4ebf2019-10-03 17:58:30 -070028#include <compositionengine/impl/Display.h>
Lloyd Pique33050472019-12-19 17:12:44 -080029#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070030#include <compositionengine/mock/Display.h>
31#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070032#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070033#include <compositionengine/mock/RenderSurface.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080034#include <gmock/gmock.h>
35#include <gtest/gtest.h>
Lloyd Pique1ebe0902019-10-04 14:47:13 -070036#include <gui/mock/GraphicBufferConsumer.h>
37#include <gui/mock/GraphicBufferProducer.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080038#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070039#include <renderengine/mock/RenderEngine.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070040#include <ui/DebugUtils.h>
Dominik Laskowski075d3172018-05-24 15:50:06 -070041
42#include "DisplayIdentificationTest.h"
Ana Krulecafb45842019-02-13 13:33:03 -080043#include "TestableScheduler.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080044#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080045#include "mock/DisplayHardware/MockComposer.h"
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070046#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070047#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080048#include "mock/MockEventControlThread.h"
49#include "mock/MockEventThread.h"
50#include "mock/MockMessageQueue.h"
51#include "mock/MockNativeWindowSurface.h"
52#include "mock/MockSurfaceInterceptor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080053#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080054
55namespace android {
56namespace {
57
Peiyong Line9d809e2020-04-14 13:10:48 -070058namespace hal = android::hardware::graphics::composer::hal;
59
Lloyd Piquee39cad22017-12-20 17:01:29 -080060using testing::_;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070061using testing::AnyNumber;
Lloyd Piquee39cad22017-12-20 17:01:29 -080062using testing::DoAll;
63using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080064using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080065using testing::Return;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070066using testing::ReturnRefOfCopy;
Lloyd Piquee39cad22017-12-20 17:01:29 -080067using testing::SetArgPointee;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070068using testing::StrictMock;
Lloyd Piquee39cad22017-12-20 17:01:29 -080069
Peiyong Line9d809e2020-04-14 13:10:48 -070070using hal::ColorMode;
71using hal::Connection;
72using hal::DisplayCapability;
73using hal::DisplayType;
74using hal::Error;
75using hal::Hdr;
76using hal::HWDisplayId;
77using hal::IComposer;
78using hal::IComposerClient;
79using hal::PerFrameMetadataKey;
80using hal::PowerMode;
81using hal::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080082
Lloyd Piquec11e0d32018-01-22 18:44:59 -080083using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
84using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080085using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080086using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080087
Lloyd Piquec11e0d32018-01-22 18:44:59 -080088constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080089constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080090constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080091
Peiyong Lin65248e02020-04-18 21:15:07 -070092constexpr int POWER_MODE_LEET = 1337; // An out of range power mode value
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080093
Lloyd Piquec11e0d32018-01-22 18:44:59 -080094/* ------------------------------------------------------------------------
95 * Boolean avoidance
96 *
97 * To make calls and template instantiations more readable, we define some
98 * local enums along with an implicit bool conversion.
99 */
100
101#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
102
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800103BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700104BOOL_SUBSTITUTE(Critical);
105BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800106BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700107BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800108
109/* ------------------------------------------------------------------------
110 *
111 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800112
Lloyd Piquef58625d2017-12-19 13:22:33 -0800113class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800114public:
Lloyd Piquef58625d2017-12-19 13:22:33 -0800115 DisplayTransactionTest();
116 ~DisplayTransactionTest() override;
117
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800118 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800119 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800120
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700121 void injectMockScheduler();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800122 void injectMockComposer(int virtualDisplayCount);
123 void injectFakeBufferQueueFactory();
124 void injectFakeNativeWindowSurfaceFactory();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700125 sp<DisplayDevice> injectDefaultInternalDisplay(std::function<void(FakeDisplayDeviceInjector&)>);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800126
127 // --------------------------------------------------------------------
128 // Postcondition helpers
129
Peiyong Line9d809e2020-04-14 13:10:48 -0700130 bool hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800131 bool hasTransactionFlagSet(int flag);
132 bool hasDisplayDevice(sp<IBinder> displayToken);
133 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
134 bool hasCurrentDisplayState(sp<IBinder> displayToken);
135 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
136 bool hasDrawingDisplayState(sp<IBinder> displayToken);
137 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
138
139 // --------------------------------------------------------------------
140 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800141
Lloyd Piquef58625d2017-12-19 13:22:33 -0800142 TestableSurfaceFlinger mFlinger;
Alec Mouriba013fa2018-10-16 12:43:11 -0700143 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800144 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700145 Hwc2::mock::PowerAdvisor mPowerAdvisor;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800146
147 // These mocks are created by the test, but are destroyed by SurfaceFlinger
148 // by virtue of being stored into a std::unique_ptr. However we still need
149 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700150 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800151 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800152 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
153 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700154
155 mock::DispSync* mPrimaryDispSync = new mock::DispSync;
156 mock::EventControlThread* mEventControlThread = new mock::EventControlThread;
157 mock::EventThread* mEventThread = new mock::EventThread;
158 mock::EventThread* mSFEventThread = new mock::EventThread;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800159
160 // These mocks are created only when expected to be created via a factory.
161 sp<mock::GraphicBufferConsumer> mConsumer;
162 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700163 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800164};
165
166DisplayTransactionTest::DisplayTransactionTest() {
167 const ::testing::TestInfo* const test_info =
168 ::testing::UnitTest::GetInstance()->current_test_info();
169 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800170
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800171 // Default to no wide color display support configured
172 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700173 mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800174 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800175
176 // Default to using HWC virtual displays
177 mFlinger.mutableUseHwcVirtualDisplays() = true;
178
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800179 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
180 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
181 });
182
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800183 mFlinger.setCreateNativeWindowSurface([](auto) {
184 ADD_FAILURE() << "Unexpected request to create a native window surface.";
185 return nullptr;
186 });
187
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700188 injectMockScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800189 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700190 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800191 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800192
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800193 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800194}
195
196DisplayTransactionTest::~DisplayTransactionTest() {
197 const ::testing::TestInfo* const test_info =
198 ::testing::UnitTest::GetInstance()->current_test_info();
199 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
200}
201
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700202void DisplayTransactionTest::injectMockScheduler() {
Ana Krulecafb45842019-02-13 13:33:03 -0800203 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700204 EXPECT_CALL(*mEventThread, createEventConnection(_, _))
205 .WillOnce(Return(new EventThreadConnection(mEventThread, ResyncCallback(),
206 ISurfaceComposer::eConfigChangedSuppress)));
207
Ana Krulecafb45842019-02-13 13:33:03 -0800208 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700209 EXPECT_CALL(*mSFEventThread, createEventConnection(_, _))
210 .WillOnce(Return(new EventThreadConnection(mSFEventThread, ResyncCallback(),
211 ISurfaceComposer::eConfigChangedSuppress)));
Ana Krulecafb45842019-02-13 13:33:03 -0800212
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700213 mFlinger.setupScheduler(std::unique_ptr<DispSync>(mPrimaryDispSync),
214 std::unique_ptr<EventControlThread>(mEventControlThread),
215 std::unique_ptr<EventThread>(mEventThread),
216 std::unique_ptr<EventThread>(mSFEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800217}
218
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800219void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
220 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800221 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
222 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800223
Lloyd Piquee39cad22017-12-20 17:01:29 -0800224 Mock::VerifyAndClear(mComposer);
225}
226
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800227void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800228 // This setup is only expected once per test.
229 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
230
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800231 mConsumer = new mock::GraphicBufferConsumer();
232 mProducer = new mock::GraphicBufferProducer();
233
234 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
235 *outProducer = mProducer;
236 *outConsumer = mConsumer;
237 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800238}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800239
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800240void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800241 // This setup is only expected once per test.
242 ASSERT_TRUE(mNativeWindowSurface == nullptr);
243
Lloyd Pique22098362018-09-13 11:46:49 -0700244 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800245
Lloyd Pique22098362018-09-13 11:46:49 -0700246 mFlinger.setCreateNativeWindowSurface([this](auto) {
247 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
248 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800249}
250
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700251sp<DisplayDevice> DisplayTransactionTest::injectDefaultInternalDisplay(
252 std::function<void(FakeDisplayDeviceInjector&)> injectExtra) {
253 constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
254 constexpr int DEFAULT_DISPLAY_WIDTH = 1080;
255 constexpr int DEFAULT_DISPLAY_HEIGHT = 1920;
Peiyong Line9d809e2020-04-14 13:10:48 -0700256 constexpr HWDisplayId DEFAULT_DISPLAY_HWC_DISPLAY_ID = 0;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700257
258 // The DisplayDevice is required to have a framebuffer (behind the
259 // ANativeWindow interface) which uses the actual hardware display
260 // size.
261 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
262 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
263 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
264 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
265 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT));
266 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT));
267 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64));
268 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(AnyNumber());
269
270 auto compositionDisplay = compositionengine::impl::
271 createDisplay(mFlinger.getCompositionEngine(),
272 compositionengine::DisplayCreationArgsBuilder()
273 .setPhysical(
274 {DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal})
275 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
276 .setPowerAdvisor(&mPowerAdvisor)
277 .build());
278
279 auto injector =
280 FakeDisplayDeviceInjector(mFlinger, compositionDisplay, DisplayConnectionType::Internal,
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100281 DEFAULT_DISPLAY_HWC_DISPLAY_ID, true /* isPrimary */);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700282
283 injector.setNativeWindow(mNativeWindow);
284 if (injectExtra) {
285 injectExtra(injector);
286 }
287
288 auto displayDevice = injector.inject();
289
290 Mock::VerifyAndClear(mNativeWindow.get());
291
292 return displayDevice;
293}
294
Peiyong Line9d809e2020-04-14 13:10:48 -0700295bool DisplayTransactionTest::hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700296 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800297}
298
299bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
300 return mFlinger.mutableTransactionFlags() & flag;
301}
302
303bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700304 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800305}
306
307sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700308 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800309}
310
311bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
312 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
313}
314
315const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
316 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
317}
318
319bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
320 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
321}
322
323const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
324 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
325}
326
327/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800328 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800329 */
330
Dominik Laskowski075d3172018-05-24 15:50:06 -0700331template <typename PhysicalDisplay>
332struct PhysicalDisplayId {};
333
Dominik Laskowski34157762018-10-31 13:07:19 -0700334template <DisplayId::Type displayId>
335using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700336
337struct NoDisplayId {};
338
339template <typename>
340struct IsPhysicalDisplayId : std::bool_constant<false> {};
341
342template <typename PhysicalDisplay>
343struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
344
345template <typename>
346struct DisplayIdGetter;
347
348template <typename PhysicalDisplay>
349struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
350 static std::optional<DisplayId> get() {
351 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
352 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
Peiyong Lin65248e02020-04-18 21:15:07 -0700353 ? LEGACY_DISPLAY_TYPE_PRIMARY
354 : LEGACY_DISPLAY_TYPE_EXTERNAL);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700355 }
356
357 const auto info =
358 parseDisplayIdentificationData(PhysicalDisplay::PORT,
359 PhysicalDisplay::GET_IDENTIFICATION_DATA());
360 return info ? std::make_optional(info->id) : std::nullopt;
361 }
362};
363
Dominik Laskowski34157762018-10-31 13:07:19 -0700364template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700365struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700366 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700367};
368
369template <>
370struct DisplayIdGetter<NoDisplayId> {
371 static std::optional<DisplayId> get() { return {}; }
372};
373
Dominik Laskowski55c85402020-01-21 16:25:47 -0800374template <typename>
375struct DisplayConnectionTypeGetter {
376 static constexpr std::optional<DisplayConnectionType> value;
377};
378
379template <typename PhysicalDisplay>
380struct DisplayConnectionTypeGetter<PhysicalDisplayId<PhysicalDisplay>> {
381 static constexpr std::optional<DisplayConnectionType> value = PhysicalDisplay::CONNECTION_TYPE;
382};
383
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100384template <typename>
385struct HwcDisplayIdGetter {
Peiyong Line9d809e2020-04-14 13:10:48 -0700386 static constexpr std::optional<HWDisplayId> value;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100387};
388
Peiyong Line9d809e2020-04-14 13:10:48 -0700389constexpr HWDisplayId HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID = 1010;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100390
391template <DisplayId::Type displayId>
392struct HwcDisplayIdGetter<VirtualDisplayId<displayId>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700393 static constexpr std::optional<HWDisplayId> value = HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100394};
395
396template <typename PhysicalDisplay>
397struct HwcDisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700398 static constexpr std::optional<HWDisplayId> value = PhysicalDisplay::HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100399};
400
Dominik Laskowski075d3172018-05-24 15:50:06 -0700401// DisplayIdType can be:
402// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
403// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
404// 3) NoDisplayId for virtual display without HWC backing.
405template <typename DisplayIdType, int width, int height, Critical critical, Async async,
406 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800407struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700408 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800409 using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100410 using HWC_DISPLAY_ID_OPT = HwcDisplayIdGetter<DisplayIdType>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700411
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800412 // The display width and height
413 static constexpr int WIDTH = width;
414 static constexpr int HEIGHT = height;
415
416 static constexpr int GRALLOC_USAGE = grallocUsage;
417
Dominik Laskowski075d3172018-05-24 15:50:06 -0700418 // Whether the display is virtual or physical
419 static constexpr Virtual VIRTUAL =
420 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800421
422 // When creating native window surfaces for the framebuffer, whether those should be critical
423 static constexpr Critical CRITICAL = critical;
424
425 // When creating native window surfaces for the framebuffer, whether those should be async
426 static constexpr Async ASYNC = async;
427
428 // Whether the display should be treated as secure
429 static constexpr Secure SECURE = secure;
430
Dominik Laskowski075d3172018-05-24 15:50:06 -0700431 // Whether the display is primary
432 static constexpr Primary PRIMARY = primary;
433
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800434 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700435 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder();
436 if (auto displayId = DISPLAY_ID::get()) {
437 ceDisplayArgs.setPhysical({*displayId, DisplayConnectionType::Internal});
438 } else {
439 ceDisplayArgs.setUseHwcVirtualDisplays(false);
440 }
441 ceDisplayArgs.setPixels({WIDTH, HEIGHT}).setPowerAdvisor(&test->mPowerAdvisor).build();
442
443 auto compositionDisplay =
444 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
445 ceDisplayArgs.build());
446
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100447 auto injector = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
448 CONNECTION_TYPE::value, HWC_DISPLAY_ID_OPT::value,
449 static_cast<bool>(PRIMARY));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700450
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800451 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700452 injector.setNativeWindow(test->mNativeWindow);
453
454 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800455 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700456 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
457 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
458 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
459 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800460 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
461 .WillRepeatedly(Return(0));
462 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
463 .WillRepeatedly(Return(0));
464 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
465 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700466 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
467 .WillRepeatedly(Return(0));
468
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800469 return injector;
470 }
471
472 // Called by tests to set up any native window creation call expectations.
473 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
474 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
475 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800476
Alec Mouriba013fa2018-10-16 12:43:11 -0700477 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
478 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
479 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
480 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800481 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
482 .WillRepeatedly(Return(0));
483 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
484 .WillRepeatedly(Return(0));
485 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
486 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700487 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
488 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800489 }
490
491 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
492 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
493 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
494 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
495 .WillRepeatedly(Return(NO_ERROR));
496 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
497 .WillRepeatedly(Return(NO_ERROR));
498 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
499 .WillRepeatedly(Return(NO_ERROR));
500 }
501
502 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
503 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
504 }
505};
506
Peiyong Line9d809e2020-04-14 13:10:48 -0700507template <HWDisplayId hwcDisplayId, DisplayType hwcDisplayType, typename DisplayVariant,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700508 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800509struct HwcDisplayVariant {
510 // The display id supplied by the HWC
Peiyong Line9d809e2020-04-14 13:10:48 -0700511 static constexpr HWDisplayId HWC_DISPLAY_ID = hwcDisplayId;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800512
513 // The HWC display type
Peiyong Line9d809e2020-04-14 13:10:48 -0700514 static constexpr DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800515
516 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700517 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin65248e02020-04-18 21:15:07 -0700518 static constexpr PowerMode INIT_POWER_MODE = PowerMode::ON;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800519
Peiyong Line9d809e2020-04-14 13:10:48 -0700520 static void injectPendingHotplugEvent(DisplayTransactionTest* test, Connection connection) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800521 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
522 HotplugEvent{HWC_DISPLAY_ID, connection});
523 }
524
525 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800526 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700527 const auto displayId = DisplayVariant::DISPLAY_ID::get();
528 ASSERT_TRUE(displayId);
529 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
530 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800531 .setHwcDisplayId(HWC_DISPLAY_ID)
532 .setWidth(DisplayVariant::WIDTH)
533 .setHeight(DisplayVariant::HEIGHT)
534 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700535 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800536 .inject(&test->mFlinger, test->mComposer);
537 }
538
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800539 // Called by tests to inject a HWC display setup
540 static void injectHwcDisplay(DisplayTransactionTest* test) {
541 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700542 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800543 Return(Error::NONE)));
Peiyong Lin65248e02020-04-18 21:15:07 -0700544 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY_ID, INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700545 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800546 injectHwcDisplayWithNoDefaultCapabilities(test);
547 }
548
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700549 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
550 DisplayTransactionTest* test) {
551 const ::testing::TestInfo* const test_info =
552 ::testing::UnitTest::GetInstance()->current_test_info();
553
554 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
555 .setPhysical({*DisplayVariant::DISPLAY_ID::get(),
556 PhysicalDisplay::CONNECTION_TYPE})
557 .setPixels({DisplayVariant::WIDTH, DisplayVariant::HEIGHT})
558 .setIsSecure(static_cast<bool>(DisplayVariant::SECURE))
559 .setPowerAdvisor(&test->mPowerAdvisor)
560 .setName(std::string("Injected display for ") +
561 test_info->test_case_name() + "." + test_info->name())
562 .build();
563
564 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
565 ceDisplayArgs);
566 }
567
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800568 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800569 constexpr auto CONNECTION_TYPE =
570 PhysicalDisplay::CONNECTION_TYPE == DisplayConnectionType::Internal
571 ? IComposerClient::DisplayConnectionType::INTERNAL
572 : IComposerClient::DisplayConnectionType::EXTERNAL;
573
574 EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700575 .WillOnce(DoAll(SetArgPointee<1>(CONNECTION_TYPE), Return(hal::V2_4::Error::NONE)));
Dominik Laskowski55c85402020-01-21 16:25:47 -0800576
Peiyong Line9d809e2020-04-14 13:10:48 -0700577 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_))
578 .WillOnce(Return(hal::Error::NONE));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800579 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
580 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
581 Return(Error::NONE)));
582 EXPECT_CALL(*test->mComposer,
583 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
584 IComposerClient::Attribute::WIDTH, _))
585 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
586 EXPECT_CALL(*test->mComposer,
587 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
588 IComposerClient::Attribute::HEIGHT, _))
589 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
590 EXPECT_CALL(*test->mComposer,
591 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
592 IComposerClient::Attribute::VSYNC_PERIOD, _))
593 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
594 EXPECT_CALL(*test->mComposer,
595 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
596 IComposerClient::Attribute::DPI_X, _))
597 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
598 EXPECT_CALL(*test->mComposer,
599 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
600 IComposerClient::Attribute::DPI_Y, _))
601 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Ady Abraham7159f572019-10-11 11:10:18 -0700602 EXPECT_CALL(*test->mComposer,
603 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
604 IComposerClient::Attribute::CONFIG_GROUP, _))
605 .WillOnce(DoAll(SetArgPointee<3>(-1), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700606
607 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
608 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
609 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
610 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
611 Return(Error::NONE)));
612 } else {
613 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
614 .WillOnce(Return(Error::UNSUPPORTED));
615 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800616 }
617
618 // Called by tests to set up HWC call expectations
619 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
620 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700621 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800622 }
623};
624
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800625// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
626constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
627 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
628
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100629template <typename PhysicalDisplay, int width, int height, Critical critical>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800630struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700631 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
632 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
Peiyong Line9d809e2020-04-14 13:10:48 -0700633 HwcDisplayVariant<PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700634 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
635 critical, Async::FALSE, Secure::TRUE,
636 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
637 PhysicalDisplay> {};
638
639template <bool hasIdentificationData>
640struct PrimaryDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800641 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::Internal;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700642 static constexpr Primary PRIMARY = Primary::TRUE;
643 static constexpr uint8_t PORT = 255;
Peiyong Line9d809e2020-04-14 13:10:48 -0700644 static constexpr HWDisplayId HWC_DISPLAY_ID = 1001;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700645 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
646 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
647};
648
649template <bool hasIdentificationData>
650struct ExternalDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800651 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::External;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700652 static constexpr Primary PRIMARY = Primary::FALSE;
653 static constexpr uint8_t PORT = 254;
Peiyong Line9d809e2020-04-14 13:10:48 -0700654 static constexpr HWDisplayId HWC_DISPLAY_ID = 1002;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700655 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
656 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
657};
658
659struct TertiaryDisplay {
660 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800661 static constexpr uint8_t PORT = 253;
Peiyong Line9d809e2020-04-14 13:10:48 -0700662 static constexpr HWDisplayId HWC_DISPLAY_ID = 1003;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800663 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700664};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800665
666// A primary display is a physical display that is critical
667using PrimaryDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100668 PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800669
670// An external display is physical display that is not critical.
671using ExternalDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100672 PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800673
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100674using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800675
676// A virtual display not supported by the HWC.
677constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
678
679template <int width, int height, Secure secure>
680struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700681 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
682 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
683 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
684 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
685
686 static void injectHwcDisplay(DisplayTransactionTest*) {}
687
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700688 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
689 DisplayTransactionTest* test) {
690 const ::testing::TestInfo* const test_info =
691 ::testing::UnitTest::GetInstance()->current_test_info();
692
693 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
694 .setPixels({Base::WIDTH, Base::HEIGHT})
695 .setIsSecure(static_cast<bool>(Base::SECURE))
696 .setPowerAdvisor(&test->mPowerAdvisor)
697 .setName(std::string("Injected display for ") +
698 test_info->test_case_name() + "." + test_info->name())
699 .build();
700
701 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
702 ceDisplayArgs);
703 }
704
Dominik Laskowski075d3172018-05-24 15:50:06 -0700705 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
706 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
707 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800708
709 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
710 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
711 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
712 }
713};
714
715// A virtual display supported by the HWC.
716constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
717
718template <int width, int height, Secure secure>
719struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700720 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
721 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
722 HwcDisplayVariant<
Peiyong Line9d809e2020-04-14 13:10:48 -0700723 HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700724 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
725 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
726 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
727 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800728 using Self = HwcVirtualDisplayVariant<width, height, secure>;
729
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700730 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
731 DisplayTransactionTest* test) {
732 const ::testing::TestInfo* const test_info =
733 ::testing::UnitTest::GetInstance()->current_test_info();
734
735 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
736 .setUseHwcVirtualDisplays(false)
737 .setPixels({Base::WIDTH, Base::HEIGHT})
738 .setIsSecure(static_cast<bool>(Base::SECURE))
739 .setPowerAdvisor(&test->mPowerAdvisor)
740 .setName(std::string("Injected display for ") +
741 test_info->test_case_name() + "." + test_info->name())
742 .build();
743
744 auto compositionDisplay =
745 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
746 ceDisplayArgs);
747 compositionDisplay->setDisplayIdForTesting(Base::DISPLAY_ID::get());
748
749 // Insert display data so that the HWC thinks it created the virtual display.
750 if (const auto displayId = Base::DISPLAY_ID::get()) {
751 test->mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
752 }
753
754 return compositionDisplay;
755 }
756
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800757 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
758 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
759 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
760 }
761
762 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
763 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
764 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
765 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
766 }
767};
768
769// For this variant, SurfaceFlinger should not configure itself with wide
770// display support, so the display should not be configured for wide-color
771// support.
772struct WideColorSupportNotConfiguredVariant {
773 static constexpr bool WIDE_COLOR_SUPPORTED = false;
774
775 static void injectConfigChange(DisplayTransactionTest* test) {
776 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700777 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800778 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800779 }
780
781 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
782 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
783 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
784 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
785 }
786};
787
788// For this variant, SurfaceFlinger should configure itself with wide display
789// support, and the display should respond with an non-empty list of supported
790// color modes. Wide-color support should be configured.
791template <typename Display>
792struct WideColorP3ColorimetricSupportedVariant {
793 static constexpr bool WIDE_COLOR_SUPPORTED = true;
794
795 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700796 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800797 test->mFlinger.mutableHasWideColorDisplay() = true;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800798 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800799 }
800
801 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800802 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
803
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800804 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
805 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
806 Return(Error::NONE)));
807 EXPECT_CALL(*test->mComposer,
808 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
809 .WillOnce(DoAll(SetArgPointee<2>(
810 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
811 Return(Error::NONE)));
812 EXPECT_CALL(*test->mComposer,
813 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
814 RenderIntent::COLORIMETRIC))
815 .WillOnce(Return(Error::NONE));
816 }
817};
818
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800819// For this variant, SurfaceFlinger should configure itself with wide display
820// support, but the display should respond with an empty list of supported color
821// modes. Wide-color support for the display should not be configured.
822template <typename Display>
823struct WideColorNotSupportedVariant {
824 static constexpr bool WIDE_COLOR_SUPPORTED = false;
825
826 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700827 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800828 test->mFlinger.mutableHasWideColorDisplay() = true;
829 }
830
831 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
832 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
833 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700834 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800835 }
836};
837
838// For this variant, the display is not a HWC display, so no HDR support should
839// be configured.
840struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800841 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800842 static constexpr bool HDR10_SUPPORTED = false;
843 static constexpr bool HDR_HLG_SUPPORTED = false;
844 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
845 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
846 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
847 }
848};
849
Valerie Haue9e843a2018-12-18 13:39:23 -0800850template <typename Display>
851struct Hdr10PlusSupportedVariant {
852 static constexpr bool HDR10_PLUS_SUPPORTED = true;
853 static constexpr bool HDR10_SUPPORTED = true;
854 static constexpr bool HDR_HLG_SUPPORTED = false;
855 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
856 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
857 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
858 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
859 Hdr::HDR10_PLUS,
860 Hdr::HDR10,
861 })),
862 Return(Error::NONE)));
863 }
864};
865
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800866// For this variant, the composer should respond with a non-empty list of HDR
867// modes containing HDR10, so HDR10 support should be configured.
868template <typename Display>
869struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800870 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800871 static constexpr bool HDR10_SUPPORTED = true;
872 static constexpr bool HDR_HLG_SUPPORTED = false;
873 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
874 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
875 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
876 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
877 Return(Error::NONE)));
878 }
879};
880
881// For this variant, the composer should respond with a non-empty list of HDR
882// modes containing HLG, so HLG support should be configured.
883template <typename Display>
884struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800885 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800886 static constexpr bool HDR10_SUPPORTED = false;
887 static constexpr bool HDR_HLG_SUPPORTED = true;
888 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
889 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
890 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
891 .WillOnce(
892 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
893 }
894};
895
896// For this variant, the composer should respond with a non-empty list of HDR
897// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
898template <typename Display>
899struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800900 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800901 static constexpr bool HDR10_SUPPORTED = false;
902 static constexpr bool HDR_HLG_SUPPORTED = false;
903 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
904 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
905 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
906 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
907 Return(Error::NONE)));
908 }
909};
910
911// For this variant, the composer should respond with am empty list of HDR
912// modes, so no HDR support should be configured.
913template <typename Display>
914struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800915 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800916 static constexpr bool HDR10_SUPPORTED = false;
917 static constexpr bool HDR_HLG_SUPPORTED = false;
918 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
919 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
920 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
921 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
922 }
923};
924
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700925struct NonHwcPerFrameMetadataSupportVariant {
926 static constexpr int PER_FRAME_METADATA_KEYS = 0;
927 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800928 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700929 }
930};
931
932template <typename Display>
933struct NoPerFrameMetadataSupportVariant {
934 static constexpr int PER_FRAME_METADATA_KEYS = 0;
935 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800936 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
937 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700938 }
939};
940
941template <typename Display>
942struct Smpte2086PerFrameMetadataSupportVariant {
943 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
944 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800945 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
946 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800947 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
948 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
949 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
950 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
951 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
952 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
953 PerFrameMetadataKey::WHITE_POINT_X,
954 PerFrameMetadataKey::WHITE_POINT_Y,
955 PerFrameMetadataKey::MAX_LUMINANCE,
956 PerFrameMetadataKey::MIN_LUMINANCE,
957 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700958 }
959};
960
961template <typename Display>
962struct Cta861_3_PerFrameMetadataSupportVariant {
963 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
964 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800965 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
966 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800967 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
968 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
969 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700970 }
971};
972
Valerie Haue9e843a2018-12-18 13:39:23 -0800973template <typename Display>
974struct Hdr10_Plus_PerFrameMetadataSupportVariant {
975 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
976 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
977 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
978 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
979 PerFrameMetadataKey::HDR10_PLUS_SEI,
980 })));
981 }
982};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800983/* ------------------------------------------------------------------------
984 * Typical display configurations to test
985 */
986
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700987template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
988 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800989struct Case {
990 using Display = DisplayPolicy;
991 using WideColorSupport = WideColorSupportPolicy;
992 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700993 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800994};
995
996using SimplePrimaryDisplayCase =
997 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700998 HdrNotSupportedVariant<PrimaryDisplayVariant>,
999 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001000using SimpleExternalDisplayCase =
1001 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001002 HdrNotSupportedVariant<ExternalDisplayVariant>,
1003 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001004using SimpleTertiaryDisplayCase =
1005 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001006 HdrNotSupportedVariant<TertiaryDisplayVariant>,
1007 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001008using NonHwcVirtualDisplayCase =
1009 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001010 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
1011 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001012using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
1013using HwcVirtualDisplayCase =
1014 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -07001015 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +08001016 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001017using WideColorP3ColorimetricDisplayCase =
1018 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001019 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1020 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -08001021using Hdr10PlusDisplayCase =
1022 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1023 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1024 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001025using Hdr10DisplayCase =
1026 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001027 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1028 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001029using HdrHlgDisplayCase =
1030 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001031 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
1032 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001033using HdrDolbyVisionDisplayCase =
1034 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001035 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
1036 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1037using HdrSmpte2086DisplayCase =
1038 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1039 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1040 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1041using HdrCta861_3_DisplayCase =
1042 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1043 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1044 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -07001045
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001046/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -08001047 *
1048 * SurfaceFlinger::onHotplugReceived
1049 */
1050
1051TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
1052 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001053 constexpr HWDisplayId hwcDisplayId1 = 456;
1054 constexpr HWDisplayId hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001055
1056 // --------------------------------------------------------------------
1057 // Preconditions
1058
1059 // Set the current sequence id for accepted events
1060 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1061
1062 // Set the main thread id so that the current thread does not appear to be
1063 // the main thread.
1064 mFlinger.mutableMainThreadId() = std::thread::id();
1065
1066 // --------------------------------------------------------------------
1067 // Call Expectations
1068
1069 // We expect invalidate() to be invoked once to trigger display transaction
1070 // processing.
1071 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1072
1073 // --------------------------------------------------------------------
1074 // Invocation
1075
1076 // Simulate two hotplug events (a connect and a disconnect)
Peiyong Line9d809e2020-04-14 13:10:48 -07001077 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, Connection::CONNECTED);
1078 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001079
1080 // --------------------------------------------------------------------
1081 // Postconditions
1082
1083 // The display transaction needed flag should be set.
1084 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1085
1086 // All events should be in the pending event queue.
1087 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
1088 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001089 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001090 EXPECT_EQ(Connection::CONNECTED, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001091 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001092 EXPECT_EQ(Connection::DISCONNECTED, pendingEvents[1].connection);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001093}
1094
1095TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
1096 constexpr int currentSequenceId = 123;
1097 constexpr int otherSequenceId = 321;
Peiyong Line9d809e2020-04-14 13:10:48 -07001098 constexpr HWDisplayId displayId = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001099
1100 // --------------------------------------------------------------------
1101 // Preconditions
1102
1103 // Set the current sequence id for accepted events
1104 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1105
1106 // Set the main thread id so that the current thread does not appear to be
1107 // the main thread.
1108 mFlinger.mutableMainThreadId() = std::thread::id();
1109
1110 // --------------------------------------------------------------------
1111 // Call Expectations
1112
1113 // We do not expect any calls to invalidate().
1114 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
1115
1116 // --------------------------------------------------------------------
1117 // Invocation
1118
1119 // Call with an unexpected sequence id
Peiyong Line9d809e2020-04-14 13:10:48 -07001120 mFlinger.onHotplugReceived(otherSequenceId, displayId, Connection::INVALID);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001121
1122 // --------------------------------------------------------------------
1123 // Postconditions
1124
1125 // The display transaction needed flag should not be set
1126 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1127
1128 // There should be no pending events
1129 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1130}
1131
1132TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
1133 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001134 constexpr HWDisplayId displayId1 = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001135
1136 // --------------------------------------------------------------------
1137 // Note:
1138 // --------------------------------------------------------------------
1139 // This test case is a bit tricky. We want to verify that
1140 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
1141 // don't really want to provide coverage for everything the later function
1142 // does as there are specific tests for it.
1143 // --------------------------------------------------------------------
1144
1145 // --------------------------------------------------------------------
1146 // Preconditions
1147
1148 // Set the current sequence id for accepted events
1149 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1150
1151 // Set the main thread id so that the current thread does appear to be the
1152 // main thread.
1153 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
1154
1155 // --------------------------------------------------------------------
1156 // Call Expectations
1157
1158 // We expect invalidate() to be invoked once to trigger display transaction
1159 // processing.
1160 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1161
1162 // --------------------------------------------------------------------
1163 // Invocation
1164
1165 // Simulate a disconnect on a display id that is not connected. This should
1166 // be enqueued by onHotplugReceived(), and dequeued by
1167 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
Peiyong Line9d809e2020-04-14 13:10:48 -07001168 mFlinger.onHotplugReceived(currentSequenceId, displayId1, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001169
1170 // --------------------------------------------------------------------
1171 // Postconditions
1172
1173 // The display transaction needed flag should be set.
1174 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1175
1176 // There should be no event queued on return, as it should have been
1177 // processed.
1178 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1179}
1180
1181/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001182 * SurfaceFlinger::createDisplay
1183 */
1184
1185TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1186 const String8 name("virtual.test");
1187
1188 // --------------------------------------------------------------------
1189 // Call Expectations
1190
1191 // The call should notify the interceptor that a display was created.
1192 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1193
1194 // --------------------------------------------------------------------
1195 // Invocation
1196
1197 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1198
1199 // --------------------------------------------------------------------
1200 // Postconditions
1201
1202 // The display should have been added to the current state
1203 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1204 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001205 EXPECT_TRUE(display.isVirtual());
1206 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001207 EXPECT_EQ(name.string(), display.displayName);
1208
1209 // --------------------------------------------------------------------
1210 // Cleanup conditions
1211
1212 // Destroying the display invalidates the display state.
1213 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1214}
1215
1216TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1217 const String8 name("virtual.test");
1218
1219 // --------------------------------------------------------------------
1220 // Call Expectations
1221
1222 // The call should notify the interceptor that a display was created.
1223 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1224
1225 // --------------------------------------------------------------------
1226 // Invocation
1227
1228 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1229
1230 // --------------------------------------------------------------------
1231 // Postconditions
1232
1233 // The display should have been added to the current state
1234 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1235 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001236 EXPECT_TRUE(display.isVirtual());
1237 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001238 EXPECT_EQ(name.string(), display.displayName);
1239
1240 // --------------------------------------------------------------------
1241 // Cleanup conditions
1242
1243 // Destroying the display invalidates the display state.
1244 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1245}
1246
1247/* ------------------------------------------------------------------------
1248 * SurfaceFlinger::destroyDisplay
1249 */
1250
1251TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1252 using Case = NonHwcVirtualDisplayCase;
1253
1254 // --------------------------------------------------------------------
1255 // Preconditions
1256
1257 // A virtual display exists
1258 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1259 existing.inject();
1260
1261 // --------------------------------------------------------------------
1262 // Call Expectations
1263
1264 // The call should notify the interceptor that a display was created.
1265 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1266
1267 // Destroying the display invalidates the display state.
1268 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1269
1270 // --------------------------------------------------------------------
1271 // Invocation
1272
1273 mFlinger.destroyDisplay(existing.token());
1274
1275 // --------------------------------------------------------------------
1276 // Postconditions
1277
1278 // The display should have been removed from the current state
1279 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1280
1281 // Ths display should still exist in the drawing state
1282 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1283
1284 // The display transaction needed flasg should be set
1285 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1286}
1287
1288TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1289 // --------------------------------------------------------------------
1290 // Preconditions
1291
1292 sp<BBinder> displayToken = new BBinder();
1293
1294 // --------------------------------------------------------------------
1295 // Invocation
1296
1297 mFlinger.destroyDisplay(displayToken);
1298}
1299
1300/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001301 * SurfaceFlinger::resetDisplayState
1302 */
1303
1304TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1305 using Case = NonHwcVirtualDisplayCase;
1306
1307 // --------------------------------------------------------------------
1308 // Preconditions
1309
1310 // vsync is enabled and available
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001311 mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = true;
1312 mFlinger.scheduler()->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001313
1314 // A display exists
1315 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1316 existing.inject();
1317
1318 // --------------------------------------------------------------------
1319 // Call Expectations
1320
1321 // The call disable vsyncs
1322 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1323
Lloyd Pique41be5d22018-06-21 13:11:48 -07001324 // The call ends any display resyncs
1325 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1326
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001327 // --------------------------------------------------------------------
1328 // Invocation
1329
1330 mFlinger.resetDisplayState();
1331
1332 // --------------------------------------------------------------------
1333 // Postconditions
1334
1335 // vsyncs should be off and not available.
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001336 EXPECT_FALSE(mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled());
1337 EXPECT_FALSE(mFlinger.scheduler()->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001338
1339 // The display should have been removed from the display map.
1340 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1341
1342 // The display should still exist in the current state
1343 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1344
1345 // The display should have been removed from the drawing state
1346 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1347}
1348
1349/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001350 * DisplayDevice::GetBestColorMode
1351 */
1352class GetBestColorModeTest : public DisplayTransactionTest {
1353public:
Valerie Hau9758ae02018-10-09 16:05:09 -07001354 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1355
1356 void addHwcColorModesMapping(ui::ColorMode colorMode,
1357 std::vector<ui::RenderIntent> renderIntents) {
1358 mHwcColorModes[colorMode] = renderIntents;
1359 }
1360
1361 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1362
1363 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1364
1365 void getBestColorMode() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001366 auto displayDevice =
1367 injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1368 injector.setHwcColorModes(mHwcColorModes);
1369 injector.setHasWideColorGamut(mHasWideColorGamut);
1370 injector.setNativeWindow(mNativeWindow);
1371 });
Valerie Hau9758ae02018-10-09 16:05:09 -07001372
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001373 displayDevice->getCompositionDisplay()
1374 ->getDisplayColorProfile()
1375 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1376 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001377 }
1378
1379 ui::Dataspace mOutDataspace;
1380 ui::ColorMode mOutColorMode;
1381 ui::RenderIntent mOutRenderIntent;
1382
1383private:
1384 ui::Dataspace mInputDataspace;
1385 ui::RenderIntent mInputRenderIntent;
1386 bool mHasWideColorGamut = false;
1387 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
Valerie Hau9758ae02018-10-09 16:05:09 -07001388};
1389
1390TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1391 addHwcColorModesMapping(ui::ColorMode::SRGB,
1392 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1393 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1394 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1395 setHasWideColorGamut(true);
1396
1397 getBestColorMode();
1398
Peiyong Lin14724e62018-12-05 07:27:30 -08001399 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001400 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1401 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1402}
1403
1404TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1405 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1406 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1407 addHwcColorModesMapping(ui::ColorMode::SRGB,
1408 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1409 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1410 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1411 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1412 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1413 setHasWideColorGamut(true);
1414
1415 getBestColorMode();
1416
1417 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1418 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1419 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1420}
1421
1422TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1423 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1424 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1425 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1426 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1427 setHasWideColorGamut(true);
1428
1429 getBestColorMode();
1430
1431 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1432 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1433 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1434}
1435
1436/* ------------------------------------------------------------------------
Lloyd Pique33050472019-12-19 17:12:44 -08001437 * DisplayDevice::setProjection
1438 */
1439
1440class DisplayDeviceSetProjectionTest : public DisplayTransactionTest {
1441public:
Lloyd Pique33050472019-12-19 17:12:44 -08001442 static constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1080; // arbitrary
1443 static constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1920; // arbitrary
1444
1445 static constexpr int32_t TRANSFORM_FLAGS_ROT_0 = 0;
1446 static constexpr int32_t TRANSFORM_FLAGS_ROT_90 = HAL_TRANSFORM_ROT_90;
1447 static constexpr int32_t TRANSFORM_FLAGS_ROT_180 = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V;
1448 static constexpr int32_t TRANSFORM_FLAGS_ROT_270 =
1449 HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
1450
1451 DisplayDeviceSetProjectionTest(ui::Size flingerDisplaySize, ui::Size hardwareDisplaySize,
1452 ui::Rotation physicalOrientation)
1453 : mFlingerDisplaySize(flingerDisplaySize),
1454 mHardwareDisplaySize(hardwareDisplaySize),
1455 mPhysicalOrientation(physicalOrientation),
1456 mDisplayDevice(createDisplayDevice()) {}
1457
1458 sp<DisplayDevice> createDisplayDevice() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001459 return injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1460 injector.setPhysicalOrientation(mPhysicalOrientation);
1461 });
Lloyd Pique33050472019-12-19 17:12:44 -08001462 }
1463
1464 ui::Size SwapWH(const ui::Size size) const { return ui::Size(size.height, size.width); }
1465
1466 void setProjectionForRotation0() {
1467 // A logical rotation of 0 uses the SurfaceFlinger display size
1468 mDisplayDevice->setProjection(ui::ROTATION_0, Rect(mFlingerDisplaySize),
1469 Rect(mFlingerDisplaySize));
1470 }
1471
1472 void setProjectionForRotation90() {
1473 // A logical rotation of 90 uses the SurfaceFlinger display size with
1474 // the width/height swapped.
1475 mDisplayDevice->setProjection(ui::ROTATION_90, Rect(SwapWH(mFlingerDisplaySize)),
1476 Rect(SwapWH(mFlingerDisplaySize)));
1477 }
1478
1479 void setProjectionForRotation180() {
1480 // A logical rotation of 180 uses the SurfaceFlinger display size
1481 mDisplayDevice->setProjection(ui::ROTATION_180, Rect(mFlingerDisplaySize),
1482 Rect(mFlingerDisplaySize));
1483 }
1484
1485 void setProjectionForRotation270() {
1486 // A logical rotation of 270 uses the SurfaceFlinger display size with
1487 // the width/height swapped.
1488 mDisplayDevice->setProjection(ui::ROTATION_270, Rect(SwapWH(mFlingerDisplaySize)),
1489 Rect(SwapWH(mFlingerDisplaySize)));
1490 }
1491
1492 void expectStateForHardwareTransform0() {
1493 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1494 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_0, mHardwareDisplaySize.width,
1495 mHardwareDisplaySize.height),
1496 compositionState.transform);
1497 EXPECT_EQ(TRANSFORM_FLAGS_ROT_0, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001498 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1499 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001500 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1501 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1502 EXPECT_EQ(false, compositionState.needsFiltering);
1503 }
1504
1505 void expectStateForHardwareTransform90() {
1506 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1507 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width,
1508 mHardwareDisplaySize.height),
1509 compositionState.transform);
1510 EXPECT_EQ(TRANSFORM_FLAGS_ROT_90, compositionState.orientation);
Alec Mouri5a6d8572020-03-23 23:56:15 -07001511 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.sourceClip);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001512 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001513 // For 90, the frame and viewport have the hardware display size width and height swapped
1514 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1515 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1516 EXPECT_EQ(false, compositionState.needsFiltering);
1517 }
1518
1519 void expectStateForHardwareTransform180() {
1520 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1521 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width,
1522 mHardwareDisplaySize.height),
1523 compositionState.transform);
1524 EXPECT_EQ(TRANSFORM_FLAGS_ROT_180, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001525 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1526 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001527 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1528 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1529 EXPECT_EQ(false, compositionState.needsFiltering);
1530 }
1531
1532 void expectStateForHardwareTransform270() {
1533 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1534 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width,
1535 mHardwareDisplaySize.height),
1536 compositionState.transform);
1537 EXPECT_EQ(TRANSFORM_FLAGS_ROT_270, compositionState.orientation);
Alec Mouri5a6d8572020-03-23 23:56:15 -07001538 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.sourceClip);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001539 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001540 // For 270, the frame and viewport have the hardware display size width and height swapped
1541 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1542 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1543 EXPECT_EQ(false, compositionState.needsFiltering);
1544 }
1545
1546 const ui::Size mFlingerDisplaySize;
1547 const ui::Size mHardwareDisplaySize;
1548 const ui::Rotation mPhysicalOrientation;
1549 const sp<DisplayDevice> mDisplayDevice;
1550};
1551
1552struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest {
1553 DisplayDeviceSetProjectionTest_Installed0()
1554 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1555 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1556 ui::ROTATION_0) {}
1557};
1558
1559TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) {
1560 setProjectionForRotation0();
1561 expectStateForHardwareTransform0();
1562}
1563
1564TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) {
1565 setProjectionForRotation90();
1566 expectStateForHardwareTransform90();
1567}
1568
1569TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) {
1570 setProjectionForRotation180();
1571 expectStateForHardwareTransform180();
1572}
1573
1574TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) {
1575 setProjectionForRotation270();
1576 expectStateForHardwareTransform270();
1577}
1578
1579struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest {
1580 DisplayDeviceSetProjectionTest_Installed90()
1581 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1582 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1583 ui::ROTATION_90) {}
1584};
1585
1586TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) {
1587 setProjectionForRotation0();
1588 expectStateForHardwareTransform90();
1589}
1590
1591TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) {
1592 setProjectionForRotation90();
1593 expectStateForHardwareTransform180();
1594}
1595
1596TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) {
1597 setProjectionForRotation180();
1598 expectStateForHardwareTransform270();
1599}
1600
1601TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) {
1602 setProjectionForRotation270();
1603 expectStateForHardwareTransform0();
1604}
1605
1606struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest {
1607 DisplayDeviceSetProjectionTest_Installed180()
1608 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1609 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1610 ui::ROTATION_180) {}
1611};
1612
1613TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) {
1614 setProjectionForRotation0();
1615 expectStateForHardwareTransform180();
1616}
1617
1618TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) {
1619 setProjectionForRotation90();
1620 expectStateForHardwareTransform270();
1621}
1622
1623TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) {
1624 setProjectionForRotation180();
1625 expectStateForHardwareTransform0();
1626}
1627
1628TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) {
1629 setProjectionForRotation270();
1630 expectStateForHardwareTransform90();
1631}
1632
1633struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest {
1634 DisplayDeviceSetProjectionTest_Installed270()
1635 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1636 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1637 ui::ROTATION_270) {}
1638};
1639
1640TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) {
1641 setProjectionForRotation0();
1642 expectStateForHardwareTransform270();
1643}
1644
1645TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) {
1646 setProjectionForRotation90();
1647 expectStateForHardwareTransform0();
1648}
1649
1650TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) {
1651 setProjectionForRotation180();
1652 expectStateForHardwareTransform90();
1653}
1654
1655TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) {
1656 setProjectionForRotation270();
1657 expectStateForHardwareTransform180();
1658}
1659
1660/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001661 * SurfaceFlinger::getDisplayNativePrimaries
1662 */
1663
1664class GetDisplayNativePrimaries : public DisplayTransactionTest {
1665public:
1666 GetDisplayNativePrimaries();
1667 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1668 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1669
1670private:
1671 static constexpr float mStartingTestValue = 1.0f;
1672};
1673
1674GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1675 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1676 injectFakeNativeWindowSurfaceFactory();
1677}
1678
1679void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1680 ui::DisplayPrimaries& primaries) {
1681 float startingVal = mStartingTestValue;
1682 primaries.red.X = startingVal++;
1683 primaries.red.Y = startingVal++;
1684 primaries.red.Z = startingVal++;
1685 primaries.green.X = startingVal++;
1686 primaries.green.Y = startingVal++;
1687 primaries.green.Z = startingVal++;
1688 primaries.blue.X = startingVal++;
1689 primaries.blue.Y = startingVal++;
1690 primaries.blue.Z = startingVal++;
1691 primaries.white.X = startingVal++;
1692 primaries.white.Y = startingVal++;
1693 primaries.white.Z = startingVal++;
1694}
1695
1696void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1697 const ui::DisplayPrimaries& primaries) {
1698 float startingVal = mStartingTestValue;
1699 EXPECT_EQ(primaries.red.X, startingVal++);
1700 EXPECT_EQ(primaries.red.Y, startingVal++);
1701 EXPECT_EQ(primaries.red.Z, startingVal++);
1702 EXPECT_EQ(primaries.green.X, startingVal++);
1703 EXPECT_EQ(primaries.green.Y, startingVal++);
1704 EXPECT_EQ(primaries.green.Z, startingVal++);
1705 EXPECT_EQ(primaries.blue.X, startingVal++);
1706 EXPECT_EQ(primaries.blue.Y, startingVal++);
1707 EXPECT_EQ(primaries.blue.Z, startingVal++);
1708 EXPECT_EQ(primaries.white.X, startingVal++);
1709 EXPECT_EQ(primaries.white.Y, startingVal++);
1710 EXPECT_EQ(primaries.white.Z, startingVal++);
1711}
1712
1713TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1714 ui::DisplayPrimaries primaries;
1715 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1716}
1717
Daniel Solomon42d04562019-01-20 21:03:19 -08001718TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1719 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1720 injector.inject();
1721 auto internalDisplayToken = injector.token();
1722
1723 ui::DisplayPrimaries expectedPrimaries;
1724 populateDummyDisplayNativePrimaries(expectedPrimaries);
1725 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1726
1727 ui::DisplayPrimaries primaries;
1728 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1729
1730 checkDummyDisplayNativePrimaries(primaries);
1731}
1732
1733TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1734 sp<BBinder> notInternalDisplayToken = new BBinder();
1735
1736 ui::DisplayPrimaries primaries;
1737 populateDummyDisplayNativePrimaries(primaries);
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001738 EXPECT_EQ(NAME_NOT_FOUND,
1739 mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
Daniel Solomon42d04562019-01-20 21:03:19 -08001740
1741 // Check primaries argument wasn't modified in case of failure
1742 checkDummyDisplayNativePrimaries(primaries);
1743}
1744
1745/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001746 * SurfaceFlinger::setupNewDisplayDeviceInternal
1747 */
1748
1749class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1750public:
1751 template <typename T>
1752 void setupNewDisplayDeviceInternalTest();
1753};
1754
1755template <typename Case>
1756void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1757 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001758 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1759 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001760 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001761
1762 // --------------------------------------------------------------------
1763 // Preconditions
1764
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001765 // Wide color displays support is configured appropriately
1766 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001767
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001768 // The display is setup with the HWC.
1769 Case::Display::injectHwcDisplay(this);
1770
1771 // SurfaceFlinger will use a test-controlled factory for native window
1772 // surfaces.
1773 injectFakeNativeWindowSurfaceFactory();
1774
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001775 // A compositionengine::Display has already been created
1776 auto compositionDisplay = Case::Display::injectCompositionDisplay(this);
1777
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001778 // --------------------------------------------------------------------
1779 // Call Expectations
1780
1781 // Various native window calls will be made.
1782 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001783 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001784 Case::WideColorSupport::setupComposerCallExpectations(this);
1785 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001786 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001787
1788 // --------------------------------------------------------------------
1789 // Invocation
1790
1791 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -08001792 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1793 const auto displayId = Case::Display::DISPLAY_ID::get();
1794 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001795 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1796 ASSERT_TRUE(hwcDisplayId);
1797 state.physical = {*displayId, *connectionType, *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001798 }
1799
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001800 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1801
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001802 auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state,
1803 displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001804
1805 // --------------------------------------------------------------------
1806 // Postconditions
1807
1808 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001809 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001810 EXPECT_EQ(Case::Display::CONNECTION_TYPE::value, device->getConnectionType());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001811 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001812 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001813 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001814 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1815 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1816 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001817 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001818 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1819 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1820 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001821 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1822 // remapped, and the test only ever sets up one config. If there were an error
1823 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
Ady Abraham2139f732019-11-13 18:56:40 -08001824 EXPECT_EQ(0, device->getActiveConfig().value());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001825 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1826 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001827}
1828
1829TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1830 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1831}
1832
1833TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1834 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1835}
1836
1837TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1838 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1839}
1840
1841TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001842 setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001843}
1844
1845TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1846 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1847}
1848
Valerie Haue9e843a2018-12-18 13:39:23 -08001849TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1850 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1851}
1852
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001853TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1854 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1855}
1856
1857TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1858 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1859}
1860
1861TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1862 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1863}
1864
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001865TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1866 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1867}
1868
1869TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1870 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1871}
1872
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001873/* ------------------------------------------------------------------------
1874 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1875 */
1876
1877class HandleTransactionLockedTest : public DisplayTransactionTest {
1878public:
1879 template <typename Case>
1880 void setupCommonPreconditions();
1881
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001882 template <typename Case, bool connected>
1883 static void expectHotplugReceived(mock::EventThread*);
1884
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001885 template <typename Case>
1886 void setupCommonCallExpectationsForConnectProcessing();
1887
1888 template <typename Case>
1889 void setupCommonCallExpectationsForDisconnectProcessing();
1890
1891 template <typename Case>
1892 void processesHotplugConnectCommon();
1893
1894 template <typename Case>
1895 void ignoresHotplugConnectCommon();
1896
1897 template <typename Case>
1898 void processesHotplugDisconnectCommon();
1899
1900 template <typename Case>
1901 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1902
1903 template <typename Case>
1904 void verifyPhysicalDisplayIsConnected();
1905
1906 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1907};
1908
1909template <typename Case>
1910void HandleTransactionLockedTest::setupCommonPreconditions() {
1911 // Wide color displays support is configured appropriately
1912 Case::WideColorSupport::injectConfigChange(this);
1913
1914 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1915 injectFakeBufferQueueFactory();
1916
1917 // SurfaceFlinger will use a test-controlled factory for native window
1918 // surfaces.
1919 injectFakeNativeWindowSurfaceFactory();
1920}
1921
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001922template <typename Case, bool connected>
1923void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1924 const auto convert = [](auto physicalDisplayId) {
1925 return std::make_optional(DisplayId{physicalDisplayId});
1926 };
1927
1928 EXPECT_CALL(*eventThread,
1929 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1930 .Times(1);
1931}
1932
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001933template <typename Case>
1934void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1935 Case::Display::setupHwcHotplugCallExpectations(this);
1936
1937 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1938 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1939 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1940 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1941
1942 Case::WideColorSupport::setupComposerCallExpectations(this);
1943 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001944 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001945
1946 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001947 expectHotplugReceived<Case, true>(mEventThread);
1948 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001949}
1950
1951template <typename Case>
1952void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1953 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001954
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001955 expectHotplugReceived<Case, false>(mEventThread);
1956 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001957}
1958
1959template <typename Case>
1960void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1961 // The display device should have been set up in the list of displays.
1962 ASSERT_TRUE(hasDisplayDevice(displayToken));
1963 const auto& device = getDisplayDevice(displayToken);
1964 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001965 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001966
Dominik Laskowski55c85402020-01-21 16:25:47 -08001967 std::optional<DisplayDeviceState::Physical> expectedPhysical;
1968 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1969 const auto displayId = Case::Display::DISPLAY_ID::get();
1970 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001971 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1972 ASSERT_TRUE(hwcDisplayId);
1973 expectedPhysical = {*displayId, *connectionType, *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001974 }
1975
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001976 // The display should have been set up in the current display state
1977 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1978 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001979 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001980 EXPECT_EQ(expectedPhysical, current.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001981
1982 // The display should have been set up in the drawing display state
1983 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1984 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001985 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001986 EXPECT_EQ(expectedPhysical, draw.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001987}
1988
1989template <typename Case>
1990void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1991 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001992 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001993
Dominik Laskowski075d3172018-05-24 15:50:06 -07001994 // SF should have a display token.
1995 const auto displayId = Case::Display::DISPLAY_ID::get();
1996 ASSERT_TRUE(displayId);
1997 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1998 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001999
2000 verifyDisplayIsConnected<Case>(displayToken);
2001}
2002
2003void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
2004 EXPECT_FALSE(hasDisplayDevice(displayToken));
2005 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2006 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
2007}
2008
2009template <typename Case>
2010void HandleTransactionLockedTest::processesHotplugConnectCommon() {
2011 // --------------------------------------------------------------------
2012 // Preconditions
2013
2014 setupCommonPreconditions<Case>();
2015
2016 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002017 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002018
2019 // --------------------------------------------------------------------
2020 // Call Expectations
2021
2022 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002023
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002024 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002025
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002026 // --------------------------------------------------------------------
2027 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08002028
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002029 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08002030
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002031 // --------------------------------------------------------------------
2032 // Postconditions
2033
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002034 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002035
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002036 // --------------------------------------------------------------------
2037 // Cleanup conditions
2038
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002039 EXPECT_CALL(*mComposer,
2040 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002041 .WillOnce(Return(Error::NONE));
2042 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08002043}
2044
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002045template <typename Case>
2046void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
2047 // --------------------------------------------------------------------
2048 // Preconditions
2049
2050 setupCommonPreconditions<Case>();
2051
2052 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002053 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002054
2055 // --------------------------------------------------------------------
2056 // Invocation
2057
2058 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2059
2060 // --------------------------------------------------------------------
2061 // Postconditions
2062
2063 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002064 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002065}
2066
2067template <typename Case>
2068void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
2069 // --------------------------------------------------------------------
2070 // Preconditions
2071
2072 setupCommonPreconditions<Case>();
2073
2074 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002075 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002076
2077 // The display is already completely set up.
2078 Case::Display::injectHwcDisplay(this);
2079 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2080 existing.inject();
2081
2082 // --------------------------------------------------------------------
2083 // Call Expectations
2084
2085 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07002086 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
2087 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002088
2089 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2090
2091 // --------------------------------------------------------------------
2092 // Invocation
2093
2094 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2095
2096 // --------------------------------------------------------------------
2097 // Postconditions
2098
2099 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002100 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002101
Dominik Laskowski075d3172018-05-24 15:50:06 -07002102 // SF should not have a display token.
2103 const auto displayId = Case::Display::DISPLAY_ID::get();
2104 ASSERT_TRUE(displayId);
2105 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002106
2107 // The existing token should have been removed
2108 verifyDisplayIsNotConnected(existing.token());
2109}
2110
2111TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
2112 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2113}
2114
2115TEST_F(HandleTransactionLockedTest,
2116 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
2117 // Inject an external display.
2118 ExternalDisplayVariant::injectHwcDisplay(this);
2119
2120 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2121}
2122
2123TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
2124 // Inject a primary display.
2125 PrimaryDisplayVariant::injectHwcDisplay(this);
2126
2127 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
2128}
2129
2130TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
2131 // Inject both a primary and external display.
2132 PrimaryDisplayVariant::injectHwcDisplay(this);
2133 ExternalDisplayVariant::injectHwcDisplay(this);
2134
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002135 // TODO: This is an unnecessary call.
2136 EXPECT_CALL(*mComposer,
2137 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
2138 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
2139 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
2140 Return(Error::NONE)));
2141
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002142 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2143
2144 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
2145}
2146
2147TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
2148 // Inject a primary display.
2149 PrimaryDisplayVariant::injectHwcDisplay(this);
2150
2151 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
2152
2153 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
2154}
2155
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002156TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectPrimaryDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002157 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
2158}
2159
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002160TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectExternalDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002161 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
2162}
2163
2164TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
2165 using Case = SimplePrimaryDisplayCase;
2166
2167 // --------------------------------------------------------------------
2168 // Preconditions
2169
2170 setupCommonPreconditions<Case>();
2171
2172 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002173 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002174 // A hotplug disconnect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002175 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002176
2177 // --------------------------------------------------------------------
2178 // Call Expectations
2179
2180 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2181
2182 setupCommonCallExpectationsForConnectProcessing<Case>();
2183 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2184
2185 EXPECT_CALL(*mComposer,
2186 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2187 .WillOnce(Return(Error::NONE));
2188 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2189
2190 // --------------------------------------------------------------------
2191 // Invocation
2192
2193 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2194
2195 // --------------------------------------------------------------------
2196 // Postconditions
2197
2198 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002199 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002200
Dominik Laskowski075d3172018-05-24 15:50:06 -07002201 // SF should not have a display token.
2202 const auto displayId = Case::Display::DISPLAY_ID::get();
2203 ASSERT_TRUE(displayId);
2204 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002205}
2206
2207TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
2208 using Case = SimplePrimaryDisplayCase;
2209
2210 // --------------------------------------------------------------------
2211 // Preconditions
2212
2213 setupCommonPreconditions<Case>();
2214
2215 // The display is already completely set up.
2216 Case::Display::injectHwcDisplay(this);
2217 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2218 existing.inject();
2219
2220 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002221 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002222 // A hotplug connect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002223 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002224
2225 // --------------------------------------------------------------------
2226 // Call Expectations
2227
2228 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2229
2230 setupCommonCallExpectationsForConnectProcessing<Case>();
2231 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2232
2233 // --------------------------------------------------------------------
2234 // Invocation
2235
2236 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2237
2238 // --------------------------------------------------------------------
2239 // Postconditions
2240
2241 // The existing token should have been removed
2242 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07002243 const auto displayId = Case::Display::DISPLAY_ID::get();
2244 ASSERT_TRUE(displayId);
2245 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
2246 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002247
2248 // A new display should be connected in its place
2249
2250 verifyPhysicalDisplayIsConnected<Case>();
2251
2252 // --------------------------------------------------------------------
2253 // Cleanup conditions
2254
2255 EXPECT_CALL(*mComposer,
2256 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2257 .WillOnce(Return(Error::NONE));
2258 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2259}
2260
2261TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
2262 using Case = HwcVirtualDisplayCase;
2263
2264 // --------------------------------------------------------------------
2265 // Preconditions
2266
2267 // The HWC supports at least one virtual display
2268 injectMockComposer(1);
2269
2270 setupCommonPreconditions<Case>();
2271
2272 // A virtual display was added to the current state, and it has a
2273 // surface(producer)
2274 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07002275
Dominik Laskowski075d3172018-05-24 15:50:06 -07002276 DisplayDeviceState state;
2277 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002278
2279 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07002280 state.surface = surface;
2281 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002282
2283 // --------------------------------------------------------------------
2284 // Call Expectations
2285
2286 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
2287 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
2288
2289 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
2290 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
2291 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
2292 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
2293 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
2294 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
2295 Return(NO_ERROR)));
2296 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
2297 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
2298
2299 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
2300
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002301 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002302 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
2303
2304 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
2305 Case::WideColorSupport::setupComposerCallExpectations(this);
2306 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07002307 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002308
2309 // --------------------------------------------------------------------
2310 // Invocation
2311
2312 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2313
2314 // --------------------------------------------------------------------
2315 // Postconditions
2316
2317 // The display device should have been set up in the list of displays.
2318 verifyDisplayIsConnected<Case>(displayToken);
2319
2320 // --------------------------------------------------------------------
2321 // Cleanup conditions
2322
2323 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
2324 .WillOnce(Return(Error::NONE));
2325 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08002326
2327 // Cleanup
2328 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
2329 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002330}
2331
2332TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
2333 using Case = HwcVirtualDisplayCase;
2334
2335 // --------------------------------------------------------------------
2336 // Preconditions
2337
2338 // The HWC supports at least one virtual display
2339 injectMockComposer(1);
2340
2341 setupCommonPreconditions<Case>();
2342
2343 // A virtual display was added to the current state, but it does not have a
2344 // surface.
2345 sp<BBinder> displayToken = new BBinder();
2346
Dominik Laskowski075d3172018-05-24 15:50:06 -07002347 DisplayDeviceState state;
2348 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002349
Dominik Laskowski075d3172018-05-24 15:50:06 -07002350 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002351
2352 // --------------------------------------------------------------------
2353 // Call Expectations
2354
2355 // --------------------------------------------------------------------
2356 // Invocation
2357
2358 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2359
2360 // --------------------------------------------------------------------
2361 // Postconditions
2362
2363 // There will not be a display device set up.
2364 EXPECT_FALSE(hasDisplayDevice(displayToken));
2365
2366 // The drawing display state will be set from the current display state.
2367 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2368 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002369 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002370}
2371
2372TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
2373 using Case = HwcVirtualDisplayCase;
2374
2375 // --------------------------------------------------------------------
2376 // Preconditions
2377
2378 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002379 const auto displayId = Case::Display::DISPLAY_ID::get();
2380 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08002381 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002382 Case::Display::injectHwcDisplay(this);
2383 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2384 existing.inject();
2385 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2386
2387 // --------------------------------------------------------------------
2388 // Call Expectations
2389
2390 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2391
2392 // --------------------------------------------------------------------
2393 // Invocation
2394
2395 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2396
2397 // --------------------------------------------------------------------
2398 // Postconditions
2399
2400 // The existing token should have been removed
2401 verifyDisplayIsNotConnected(existing.token());
2402}
2403
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002404TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2405 using Case = NonHwcVirtualDisplayCase;
2406
2407 constexpr uint32_t oldLayerStack = 0u;
2408 constexpr uint32_t newLayerStack = 123u;
2409
2410 // --------------------------------------------------------------------
2411 // Preconditions
2412
2413 // A display is set up
2414 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2415 display.inject();
2416
2417 // There is a change to the layerStack state
2418 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2419 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2420
2421 // --------------------------------------------------------------------
2422 // Invocation
2423
2424 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2425
2426 // --------------------------------------------------------------------
2427 // Postconditions
2428
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002429 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002430}
2431
2432TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2433 using Case = NonHwcVirtualDisplayCase;
2434
Dominik Laskowski718f9602019-11-09 20:01:35 -08002435 constexpr ui::Rotation oldTransform = ui::ROTATION_0;
2436 constexpr ui::Rotation newTransform = ui::ROTATION_180;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002437
2438 // --------------------------------------------------------------------
2439 // Preconditions
2440
2441 // A display is set up
2442 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2443 display.inject();
2444
2445 // There is a change to the orientation state
2446 display.mutableDrawingDisplayState().orientation = oldTransform;
2447 display.mutableCurrentDisplayState().orientation = newTransform;
2448
2449 // --------------------------------------------------------------------
2450 // Invocation
2451
2452 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2453
2454 // --------------------------------------------------------------------
2455 // Postconditions
2456
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002457 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002458}
2459
2460TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2461 using Case = NonHwcVirtualDisplayCase;
2462
2463 const Rect oldViewport(0, 0, 0, 0);
2464 const Rect newViewport(0, 0, 123, 456);
2465
2466 // --------------------------------------------------------------------
2467 // Preconditions
2468
2469 // A display is set up
2470 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2471 display.inject();
2472
2473 // There is a change to the viewport state
2474 display.mutableDrawingDisplayState().viewport = oldViewport;
2475 display.mutableCurrentDisplayState().viewport = newViewport;
2476
2477 // --------------------------------------------------------------------
2478 // Invocation
2479
2480 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2481
2482 // --------------------------------------------------------------------
2483 // Postconditions
2484
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002485 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002486}
2487
2488TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2489 using Case = NonHwcVirtualDisplayCase;
2490
2491 const Rect oldFrame(0, 0, 0, 0);
2492 const Rect newFrame(0, 0, 123, 456);
2493
2494 // --------------------------------------------------------------------
2495 // Preconditions
2496
2497 // A display is set up
2498 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2499 display.inject();
2500
2501 // There is a change to the viewport state
2502 display.mutableDrawingDisplayState().frame = oldFrame;
2503 display.mutableCurrentDisplayState().frame = newFrame;
2504
2505 // --------------------------------------------------------------------
2506 // Invocation
2507
2508 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2509
2510 // --------------------------------------------------------------------
2511 // Postconditions
2512
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002513 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002514}
2515
2516TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2517 using Case = NonHwcVirtualDisplayCase;
2518
2519 constexpr int oldWidth = 0;
2520 constexpr int oldHeight = 10;
2521 constexpr int newWidth = 123;
2522
2523 // --------------------------------------------------------------------
2524 // Preconditions
2525
2526 // A display is set up
2527 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002528 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002529 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002530 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2531 display.setNativeWindow(nativeWindow);
2532 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002533 // Setup injection expections
2534 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2535 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2536 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2537 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002538 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2539 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2540 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002541 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002542 display.inject();
2543
2544 // There is a change to the viewport state
2545 display.mutableDrawingDisplayState().width = oldWidth;
2546 display.mutableDrawingDisplayState().height = oldHeight;
2547 display.mutableCurrentDisplayState().width = newWidth;
2548 display.mutableCurrentDisplayState().height = oldHeight;
2549
2550 // --------------------------------------------------------------------
2551 // Call Expectations
2552
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002553 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002554
2555 // --------------------------------------------------------------------
2556 // Invocation
2557
2558 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2559}
2560
2561TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2562 using Case = NonHwcVirtualDisplayCase;
2563
2564 constexpr int oldWidth = 0;
2565 constexpr int oldHeight = 10;
2566 constexpr int newHeight = 123;
2567
2568 // --------------------------------------------------------------------
2569 // Preconditions
2570
2571 // A display is set up
2572 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002573 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002574 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002575 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2576 display.setNativeWindow(nativeWindow);
2577 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002578 // Setup injection expections
2579 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2580 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2581 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2582 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002583 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2584 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2585 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002586 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002587 display.inject();
2588
2589 // There is a change to the viewport state
2590 display.mutableDrawingDisplayState().width = oldWidth;
2591 display.mutableDrawingDisplayState().height = oldHeight;
2592 display.mutableCurrentDisplayState().width = oldWidth;
2593 display.mutableCurrentDisplayState().height = newHeight;
2594
2595 // --------------------------------------------------------------------
2596 // Call Expectations
2597
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002598 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002599
2600 // --------------------------------------------------------------------
2601 // Invocation
2602
2603 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2604}
2605
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002606/* ------------------------------------------------------------------------
2607 * SurfaceFlinger::setDisplayStateLocked
2608 */
2609
2610TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2611 // --------------------------------------------------------------------
2612 // Preconditions
2613
2614 // We have an unknown display token not associated with a known display
2615 sp<BBinder> displayToken = new BBinder();
2616
2617 // The requested display state references the unknown display.
2618 DisplayState state;
2619 state.what = DisplayState::eLayerStackChanged;
2620 state.token = displayToken;
2621 state.layerStack = 456;
2622
2623 // --------------------------------------------------------------------
2624 // Invocation
2625
2626 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2627
2628 // --------------------------------------------------------------------
2629 // Postconditions
2630
2631 // The returned flags are empty
2632 EXPECT_EQ(0u, flags);
2633
2634 // The display token still doesn't match anything known.
2635 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2636}
2637
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002638TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2639 using Case = SimplePrimaryDisplayCase;
2640
2641 // --------------------------------------------------------------------
2642 // Preconditions
2643
2644 // A display is already set up
2645 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2646 display.inject();
2647
2648 // No changes are made to the display
2649 DisplayState state;
2650 state.what = 0;
2651 state.token = display.token();
2652
2653 // --------------------------------------------------------------------
2654 // Invocation
2655
2656 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2657
2658 // --------------------------------------------------------------------
2659 // Postconditions
2660
2661 // The returned flags are empty
2662 EXPECT_EQ(0u, flags);
2663}
2664
2665TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2666 using Case = SimplePrimaryDisplayCase;
2667
2668 // --------------------------------------------------------------------
2669 // Preconditions
2670
2671 // A display is already set up
2672 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2673 display.inject();
2674
2675 // There is a surface that can be set.
2676 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2677
2678 // The current display state has the surface set
2679 display.mutableCurrentDisplayState().surface = surface;
2680
2681 // The incoming request sets the same surface
2682 DisplayState state;
2683 state.what = DisplayState::eSurfaceChanged;
2684 state.token = display.token();
2685 state.surface = surface;
2686
2687 // --------------------------------------------------------------------
2688 // Invocation
2689
2690 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2691
2692 // --------------------------------------------------------------------
2693 // Postconditions
2694
2695 // The returned flags are empty
2696 EXPECT_EQ(0u, flags);
2697
2698 // The current display state is unchanged.
2699 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2700}
2701
2702TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2703 using Case = SimplePrimaryDisplayCase;
2704
2705 // --------------------------------------------------------------------
2706 // Preconditions
2707
2708 // A display is already set up
2709 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2710 display.inject();
2711
2712 // There is a surface that can be set.
2713 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2714
2715 // The current display state does not have a surface
2716 display.mutableCurrentDisplayState().surface = nullptr;
2717
2718 // The incoming request sets a surface
2719 DisplayState state;
2720 state.what = DisplayState::eSurfaceChanged;
2721 state.token = display.token();
2722 state.surface = surface;
2723
2724 // --------------------------------------------------------------------
2725 // Invocation
2726
2727 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2728
2729 // --------------------------------------------------------------------
2730 // Postconditions
2731
2732 // The returned flags indicate a transaction is needed
2733 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2734
2735 // The current display layer stack state is set to the new value
2736 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2737}
2738
2739TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2740 using Case = SimplePrimaryDisplayCase;
2741
2742 // --------------------------------------------------------------------
2743 // Preconditions
2744
2745 // A display is already set up
2746 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2747 display.inject();
2748
2749 // The display has a layer stack set
2750 display.mutableCurrentDisplayState().layerStack = 456u;
2751
2752 // The incoming request sets the same layer stack
2753 DisplayState state;
2754 state.what = DisplayState::eLayerStackChanged;
2755 state.token = display.token();
2756 state.layerStack = 456u;
2757
2758 // --------------------------------------------------------------------
2759 // Invocation
2760
2761 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2762
2763 // --------------------------------------------------------------------
2764 // Postconditions
2765
2766 // The returned flags are empty
2767 EXPECT_EQ(0u, flags);
2768
2769 // The current display state is unchanged
2770 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2771}
2772
2773TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2774 using Case = SimplePrimaryDisplayCase;
2775
2776 // --------------------------------------------------------------------
2777 // Preconditions
2778
2779 // A display is set up
2780 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2781 display.inject();
2782
2783 // The display has a layer stack set
2784 display.mutableCurrentDisplayState().layerStack = 654u;
2785
2786 // The incoming request sets a different layer stack
2787 DisplayState state;
2788 state.what = DisplayState::eLayerStackChanged;
2789 state.token = display.token();
2790 state.layerStack = 456u;
2791
2792 // --------------------------------------------------------------------
2793 // Invocation
2794
2795 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2796
2797 // --------------------------------------------------------------------
2798 // Postconditions
2799
2800 // The returned flags indicate a transaction is needed
2801 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2802
2803 // The desired display state has been set to the new value.
2804 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2805}
2806
2807TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2808 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002809 constexpr ui::Rotation initialOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002810 const Rect initialFrame = {1, 2, 3, 4};
2811 const Rect initialViewport = {5, 6, 7, 8};
2812
2813 // --------------------------------------------------------------------
2814 // Preconditions
2815
2816 // A display is set up
2817 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2818 display.inject();
2819
2820 // The current display state projection state is all set
2821 display.mutableCurrentDisplayState().orientation = initialOrientation;
2822 display.mutableCurrentDisplayState().frame = initialFrame;
2823 display.mutableCurrentDisplayState().viewport = initialViewport;
2824
2825 // The incoming request sets the same projection state
2826 DisplayState state;
2827 state.what = DisplayState::eDisplayProjectionChanged;
2828 state.token = display.token();
2829 state.orientation = initialOrientation;
2830 state.frame = initialFrame;
2831 state.viewport = initialViewport;
2832
2833 // --------------------------------------------------------------------
2834 // Invocation
2835
2836 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2837
2838 // --------------------------------------------------------------------
2839 // Postconditions
2840
2841 // The returned flags are empty
2842 EXPECT_EQ(0u, flags);
2843
2844 // The current display state is unchanged
2845 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2846
2847 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2848 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2849}
2850
2851TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2852 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002853 constexpr ui::Rotation initialOrientation = ui::ROTATION_90;
2854 constexpr ui::Rotation desiredOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002855
2856 // --------------------------------------------------------------------
2857 // Preconditions
2858
2859 // A display is set up
2860 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2861 display.inject();
2862
2863 // The current display state has an orientation set
2864 display.mutableCurrentDisplayState().orientation = initialOrientation;
2865
2866 // The incoming request sets a different orientation
2867 DisplayState state;
2868 state.what = DisplayState::eDisplayProjectionChanged;
2869 state.token = display.token();
2870 state.orientation = desiredOrientation;
2871
2872 // --------------------------------------------------------------------
2873 // Invocation
2874
2875 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2876
2877 // --------------------------------------------------------------------
2878 // Postconditions
2879
2880 // The returned flags indicate a transaction is needed
2881 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2882
2883 // The current display state has the new value.
2884 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2885}
2886
2887TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2888 using Case = SimplePrimaryDisplayCase;
2889 const Rect initialFrame = {0, 0, 0, 0};
2890 const Rect desiredFrame = {5, 6, 7, 8};
2891
2892 // --------------------------------------------------------------------
2893 // Preconditions
2894
2895 // A display is set up
2896 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2897 display.inject();
2898
2899 // The current display state does not have a frame
2900 display.mutableCurrentDisplayState().frame = initialFrame;
2901
2902 // The incoming request sets a frame
2903 DisplayState state;
2904 state.what = DisplayState::eDisplayProjectionChanged;
2905 state.token = display.token();
2906 state.frame = desiredFrame;
2907
2908 // --------------------------------------------------------------------
2909 // Invocation
2910
2911 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2912
2913 // --------------------------------------------------------------------
2914 // Postconditions
2915
2916 // The returned flags indicate a transaction is needed
2917 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2918
2919 // The current display state has the new value.
2920 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2921}
2922
2923TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2924 using Case = SimplePrimaryDisplayCase;
2925 const Rect initialViewport = {0, 0, 0, 0};
2926 const Rect desiredViewport = {5, 6, 7, 8};
2927
2928 // --------------------------------------------------------------------
2929 // Preconditions
2930
2931 // A display is set up
2932 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2933 display.inject();
2934
2935 // The current display state does not have a viewport
2936 display.mutableCurrentDisplayState().viewport = initialViewport;
2937
2938 // The incoming request sets a viewport
2939 DisplayState state;
2940 state.what = DisplayState::eDisplayProjectionChanged;
2941 state.token = display.token();
2942 state.viewport = desiredViewport;
2943
2944 // --------------------------------------------------------------------
2945 // Invocation
2946
2947 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2948
2949 // --------------------------------------------------------------------
2950 // Postconditions
2951
2952 // The returned flags indicate a transaction is needed
2953 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2954
2955 // The current display state has the new value.
2956 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2957}
2958
2959TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2960 using Case = SimplePrimaryDisplayCase;
2961 constexpr uint32_t initialWidth = 1024;
2962 constexpr uint32_t initialHeight = 768;
2963
2964 // --------------------------------------------------------------------
2965 // Preconditions
2966
2967 // A display is set up
2968 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2969 display.inject();
2970
2971 // The current display state has a size set
2972 display.mutableCurrentDisplayState().width = initialWidth;
2973 display.mutableCurrentDisplayState().height = initialHeight;
2974
2975 // The incoming request sets the same display size
2976 DisplayState state;
2977 state.what = DisplayState::eDisplaySizeChanged;
2978 state.token = display.token();
2979 state.width = initialWidth;
2980 state.height = initialHeight;
2981
2982 // --------------------------------------------------------------------
2983 // Invocation
2984
2985 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2986
2987 // --------------------------------------------------------------------
2988 // Postconditions
2989
2990 // The returned flags are empty
2991 EXPECT_EQ(0u, flags);
2992
2993 // The current display state is unchanged
2994 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2995 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2996}
2997
2998TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2999 using Case = SimplePrimaryDisplayCase;
3000 constexpr uint32_t initialWidth = 0;
3001 constexpr uint32_t desiredWidth = 1024;
3002
3003 // --------------------------------------------------------------------
3004 // Preconditions
3005
3006 // A display is set up
3007 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3008 display.inject();
3009
3010 // The display does not yet have a width
3011 display.mutableCurrentDisplayState().width = initialWidth;
3012
3013 // The incoming request sets a display width
3014 DisplayState state;
3015 state.what = DisplayState::eDisplaySizeChanged;
3016 state.token = display.token();
3017 state.width = desiredWidth;
3018
3019 // --------------------------------------------------------------------
3020 // Invocation
3021
3022 uint32_t flags = mFlinger.setDisplayStateLocked(state);
3023
3024 // --------------------------------------------------------------------
3025 // Postconditions
3026
3027 // The returned flags indicate a transaction is needed
3028 EXPECT_EQ(eDisplayTransactionNeeded, flags);
3029
3030 // The current display state has the new value.
3031 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
3032}
3033
3034TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
3035 using Case = SimplePrimaryDisplayCase;
3036 constexpr uint32_t initialHeight = 0;
3037 constexpr uint32_t desiredHeight = 768;
3038
3039 // --------------------------------------------------------------------
3040 // Preconditions
3041
3042 // A display is set up
3043 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3044 display.inject();
3045
3046 // The display does not yet have a height
3047 display.mutableCurrentDisplayState().height = initialHeight;
3048
3049 // The incoming request sets a display height
3050 DisplayState state;
3051 state.what = DisplayState::eDisplaySizeChanged;
3052 state.token = display.token();
3053 state.height = desiredHeight;
3054
3055 // --------------------------------------------------------------------
3056 // Invocation
3057
3058 uint32_t flags = mFlinger.setDisplayStateLocked(state);
3059
3060 // --------------------------------------------------------------------
3061 // Postconditions
3062
3063 // The returned flags indicate a transaction is needed
3064 EXPECT_EQ(eDisplayTransactionNeeded, flags);
3065
3066 // The current display state has the new value.
3067 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
3068}
3069
Lloyd Pique86016da2018-03-01 16:09:38 -08003070/* ------------------------------------------------------------------------
3071 * SurfaceFlinger::onInitializeDisplays
3072 */
3073
3074TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
3075 using Case = SimplePrimaryDisplayCase;
3076
3077 // --------------------------------------------------------------------
3078 // Preconditions
3079
3080 // A primary display is set up
3081 Case::Display::injectHwcDisplay(this);
3082 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
3083 primaryDisplay.inject();
3084
3085 // --------------------------------------------------------------------
3086 // Call Expectations
3087
3088 // We expect the surface interceptor to possibly be used, but we treat it as
3089 // disabled since it is called as a side effect rather than directly by this
3090 // function.
3091 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
3092
3093 // We expect a call to get the active display config.
3094 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
3095
3096 // We expect invalidate() to be invoked once to trigger display transaction
3097 // processing.
3098 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
3099
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003100 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
3101
Lloyd Pique86016da2018-03-01 16:09:38 -08003102 // --------------------------------------------------------------------
3103 // Invocation
3104
3105 mFlinger.onInitializeDisplays();
3106
3107 // --------------------------------------------------------------------
3108 // Postconditions
3109
3110 // The primary display should have a current state
3111 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
3112 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
3113 // The layer stack state should be set to zero
3114 EXPECT_EQ(0u, primaryDisplayState.layerStack);
3115 // The orientation state should be set to zero
Dominik Laskowski718f9602019-11-09 20:01:35 -08003116 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
Lloyd Pique86016da2018-03-01 16:09:38 -08003117
3118 // The frame state should be set to INVALID
3119 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
3120
3121 // The viewport state should be set to INVALID
3122 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
3123
3124 // The width and height should both be zero
3125 EXPECT_EQ(0u, primaryDisplayState.width);
3126 EXPECT_EQ(0u, primaryDisplayState.height);
3127
Peiyong Lin65248e02020-04-18 21:15:07 -07003128 // The display should be set to PowerMode::ON
Lloyd Pique86016da2018-03-01 16:09:38 -08003129 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
3130 auto displayDevice = primaryDisplay.mutableDisplayDevice();
Peiyong Lin65248e02020-04-18 21:15:07 -07003131 EXPECT_EQ(PowerMode::ON, displayDevice->getPowerMode());
Lloyd Pique86016da2018-03-01 16:09:38 -08003132
3133 // The display refresh period should be set in the frame tracker.
3134 FrameStats stats;
3135 mFlinger.getAnimFrameTracker().getStats(&stats);
3136 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
3137
3138 // The display transaction needed flag should be set.
3139 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
3140
3141 // The compositor timing should be set to default values
3142 const auto& compositorTiming = mFlinger.getCompositorTiming();
3143 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
3144 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
3145 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
3146}
3147
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003148/* ------------------------------------------------------------------------
3149 * SurfaceFlinger::setPowerModeInternal
3150 */
3151
3152// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07003153template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003154struct DozeIsSupportedVariant {
3155 static constexpr bool DOZE_SUPPORTED = true;
3156 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3157 IComposerClient::PowerMode::DOZE;
3158 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3159 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07003160
3161 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3162 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003163 .WillOnce(DoAll(SetArgPointee<1>(
3164 std::vector<DisplayCapability>({DisplayCapability::DOZE})),
Peiyong Lined531a32018-10-26 18:27:56 -07003165 Return(Error::NONE)));
3166 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003167};
3168
Peiyong Lined531a32018-10-26 18:27:56 -07003169template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003170// Used when we simulate a display that does not support doze.
3171struct DozeNotSupportedVariant {
3172 static constexpr bool DOZE_SUPPORTED = false;
3173 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3174 IComposerClient::PowerMode::ON;
3175 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3176 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07003177
3178 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3179 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003180 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Peiyong Lined531a32018-10-26 18:27:56 -07003181 Return(Error::NONE)));
3182 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003183};
3184
3185struct EventThreadBaseSupportedVariant {
3186 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
3187 // The event control thread should not be notified.
3188 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
3189
3190 // The event thread should not be notified.
3191 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
3192 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
3193 }
3194};
3195
3196struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
3197 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3198 // These calls are only expected for the primary display.
3199
3200 // Instead expect no calls.
3201 setupEventAndEventControlThreadNoCallExpectations(test);
3202 }
3203
3204 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3205 // These calls are only expected for the primary display.
3206
3207 // Instead expect no calls.
3208 setupEventAndEventControlThreadNoCallExpectations(test);
3209 }
3210};
3211
3212struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
3213 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3214 // The event control thread should be notified to enable vsyncs
3215 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
3216
3217 // The event thread should be notified that the screen was acquired.
3218 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
3219 }
3220
3221 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3222 // There should be a call to setVsyncEnabled(false)
3223 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
3224
3225 // The event thread should not be notified that the screen was released.
3226 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
3227 }
3228};
3229
Lloyd Pique41be5d22018-06-21 13:11:48 -07003230struct DispSyncIsSupportedVariant {
3231 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique41be5d22018-06-21 13:11:48 -07003232 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
3233 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
3234 }
3235
3236 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
3237 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
3238 }
3239};
3240
3241struct DispSyncNotSupportedVariant {
3242 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3243
3244 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3245};
3246
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003247// --------------------------------------------------------------------
3248// Note:
3249//
3250// There are a large number of transitions we could test, however we only test a
3251// selected subset which provides complete test coverage of the implementation.
3252// --------------------------------------------------------------------
3253
Peiyong Lin65248e02020-04-18 21:15:07 -07003254template <PowerMode initialPowerMode, PowerMode targetPowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003255struct TransitionVariantCommon {
3256 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
3257 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
3258
3259 static void verifyPostconditions(DisplayTransactionTest*) {}
3260};
3261
Peiyong Lin65248e02020-04-18 21:15:07 -07003262struct TransitionOffToOnVariant : public TransitionVariantCommon<PowerMode::OFF, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003263 template <typename Case>
3264 static void setupCallExpectations(DisplayTransactionTest* test) {
3265 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3266 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003267 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003268 Case::setupRepaintEverythingCallExpectations(test);
3269 }
3270
3271 static void verifyPostconditions(DisplayTransactionTest* test) {
3272 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3273 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3274 }
3275};
3276
3277struct TransitionOffToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003278 : public TransitionVariantCommon<PowerMode::OFF, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003279 template <typename Case>
3280 static void setupCallExpectations(DisplayTransactionTest* test) {
3281 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3282 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3283 Case::setupRepaintEverythingCallExpectations(test);
3284 }
3285
3286 static void verifyPostconditions(DisplayTransactionTest* test) {
3287 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3288 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3289 }
3290};
3291
Peiyong Lin65248e02020-04-18 21:15:07 -07003292struct TransitionOnToOffVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003293 template <typename Case>
3294 static void setupCallExpectations(DisplayTransactionTest* test) {
3295 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003296 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003297 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3298 }
3299
3300 static void verifyPostconditions(DisplayTransactionTest* test) {
3301 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3302 }
3303};
3304
3305struct TransitionDozeSuspendToOffVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003306 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003307 template <typename Case>
3308 static void setupCallExpectations(DisplayTransactionTest* test) {
3309 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3310 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3311 }
3312
3313 static void verifyPostconditions(DisplayTransactionTest* test) {
3314 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3315 }
3316};
3317
Peiyong Lin65248e02020-04-18 21:15:07 -07003318struct TransitionOnToDozeVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003319 template <typename Case>
3320 static void setupCallExpectations(DisplayTransactionTest* test) {
3321 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3322 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3323 }
3324};
3325
3326struct TransitionDozeSuspendToDozeVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003327 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003328 template <typename Case>
3329 static void setupCallExpectations(DisplayTransactionTest* test) {
3330 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003331 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003332 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3333 }
3334};
3335
Peiyong Lin65248e02020-04-18 21:15:07 -07003336struct TransitionDozeToOnVariant : public TransitionVariantCommon<PowerMode::DOZE, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003337 template <typename Case>
3338 static void setupCallExpectations(DisplayTransactionTest* test) {
3339 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3340 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3341 }
3342};
3343
3344struct TransitionDozeSuspendToOnVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003345 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003346 template <typename Case>
3347 static void setupCallExpectations(DisplayTransactionTest* test) {
3348 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003349 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003350 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3351 }
3352};
3353
3354struct TransitionOnToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003355 : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003356 template <typename Case>
3357 static void setupCallExpectations(DisplayTransactionTest* test) {
3358 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003359 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003360 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3361 }
3362};
3363
3364struct TransitionOnToUnknownVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003365 : public TransitionVariantCommon<PowerMode::ON, static_cast<PowerMode>(POWER_MODE_LEET)> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003366 template <typename Case>
3367 static void setupCallExpectations(DisplayTransactionTest* test) {
3368 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3369 Case::setupNoComposerPowerModeCallExpectations(test);
3370 }
3371};
3372
3373// --------------------------------------------------------------------
3374// Note:
3375//
3376// Rather than testing the cartesian product of of
3377// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3378// display type, and the other for another display type.
3379// --------------------------------------------------------------------
3380
3381template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003382 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003383struct DisplayPowerCase {
3384 using Display = DisplayVariant;
3385 using Doze = DozeVariant;
3386 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003387 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003388 using Transition = TransitionVariant;
3389
Peiyong Lin65248e02020-04-18 21:15:07 -07003390 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003391 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003392 auto display = Display::makeFakeExistingDisplayInjector(test);
3393 display.inject();
3394 display.mutableDisplayDevice()->setPowerMode(mode);
3395 return display;
3396 }
3397
3398 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003399 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003400 }
3401
3402 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3403 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3404 }
3405
Peiyong Lin65248e02020-04-18 21:15:07 -07003406 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test,
3407 PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003408 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
Peiyong Lin65248e02020-04-18 21:15:07 -07003409 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, static_cast<int32_t>(mode)))
3410 .Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003411 }
3412
Peiyong Lin65248e02020-04-18 21:15:07 -07003413 static void setupComposerCallExpectations(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003414 // Any calls to get the active config will return a default value.
3415 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3416 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3417 Return(Error::NONE)));
3418
3419 // Any calls to get whether the display supports dozing will return the value set by the
3420 // policy variant.
3421 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3422 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3423
3424 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3425 }
3426
3427 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3428 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3429 }
3430};
3431
3432// A sample configuration for the primary display.
3433// In addition to having event thread support, we emulate doze support.
3434template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003435using PrimaryDisplayPowerCase =
3436 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3437 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3438 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003439
3440// A sample configuration for the external display.
3441// In addition to not having event thread support, we emulate not having doze
3442// support.
3443template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003444using ExternalDisplayPowerCase =
3445 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3446 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3447 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003448
3449class SetPowerModeInternalTest : public DisplayTransactionTest {
3450public:
3451 template <typename Case>
3452 void transitionDisplayCommon();
3453};
3454
Peiyong Lin65248e02020-04-18 21:15:07 -07003455template <PowerMode PowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003456struct PowerModeInitialVSyncEnabled : public std::false_type {};
3457
3458template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003459struct PowerModeInitialVSyncEnabled<PowerMode::ON> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003460
3461template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003462struct PowerModeInitialVSyncEnabled<PowerMode::DOZE> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003463
3464template <typename Case>
3465void SetPowerModeInternalTest::transitionDisplayCommon() {
3466 // --------------------------------------------------------------------
3467 // Preconditions
3468
Peiyong Lined531a32018-10-26 18:27:56 -07003469 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003470 auto display =
3471 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3472 Case::setInitialPrimaryHWVsyncEnabled(this,
3473 PowerModeInitialVSyncEnabled<
3474 Case::Transition::INITIAL_POWER_MODE>::value);
3475
3476 // --------------------------------------------------------------------
3477 // Call Expectations
3478
3479 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3480 Case::Transition::template setupCallExpectations<Case>(this);
3481
3482 // --------------------------------------------------------------------
3483 // Invocation
3484
3485 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3486 Case::Transition::TARGET_POWER_MODE);
3487
3488 // --------------------------------------------------------------------
3489 // Postconditions
3490
3491 Case::Transition::verifyPostconditions(this);
3492}
3493
3494TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3495 using Case = SimplePrimaryDisplayCase;
3496
3497 // --------------------------------------------------------------------
3498 // Preconditions
3499
3500 // A primary display device is set up
3501 Case::Display::injectHwcDisplay(this);
3502 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3503 display.inject();
3504
Peiyong Lin65248e02020-04-18 21:15:07 -07003505 // The display is already set to PowerMode::ON
3506 display.mutableDisplayDevice()->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003507
3508 // --------------------------------------------------------------------
3509 // Invocation
3510
Peiyong Lin65248e02020-04-18 21:15:07 -07003511 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003512
3513 // --------------------------------------------------------------------
3514 // Postconditions
3515
Peiyong Lin65248e02020-04-18 21:15:07 -07003516 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003517}
3518
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003519TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003520 using Case = HwcVirtualDisplayCase;
3521
3522 // --------------------------------------------------------------------
3523 // Preconditions
3524
Dominik Laskowski075d3172018-05-24 15:50:06 -07003525 // Insert display data so that the HWC thinks it created the virtual display.
3526 const auto displayId = Case::Display::DISPLAY_ID::get();
3527 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003528 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003529
3530 // A virtual display device is set up
3531 Case::Display::injectHwcDisplay(this);
3532 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3533 display.inject();
3534
Peiyong Lin65248e02020-04-18 21:15:07 -07003535 // The display is set to PowerMode::ON
3536 getDisplayDevice(display.token())->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003537
3538 // --------------------------------------------------------------------
3539 // Invocation
3540
Peiyong Lin65248e02020-04-18 21:15:07 -07003541 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003542
3543 // --------------------------------------------------------------------
3544 // Postconditions
3545
Peiyong Lin65248e02020-04-18 21:15:07 -07003546 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003547}
3548
3549TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3550 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3551}
3552
3553TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3554 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3555}
3556
3557TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3558 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3559}
3560
3561TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3562 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3563}
3564
3565TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3566 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3567}
3568
3569TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3570 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3571}
3572
3573TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3574 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3575}
3576
3577TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3578 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3579}
3580
3581TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3582 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3583}
3584
3585TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3586 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3587}
3588
3589TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3590 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3591}
3592
3593TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3594 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3595}
3596
3597TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3598 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3599}
3600
3601TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3602 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3603}
3604
3605TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3606 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3607}
3608
3609TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3610 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3611}
3612
3613TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3614 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3615}
3616
3617TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3618 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3619}
3620
3621TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3622 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3623}
3624
3625TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3626 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3627}
3628
Lloyd Piquef58625d2017-12-19 13:22:33 -08003629} // namespace
3630} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08003631
3632// TODO(b/129481165): remove the #pragma below and fix conversion issues
3633#pragma clang diagnostic pop // ignored "-Wconversion"