blob: 009de06aa459ca09a34d0893eff98605d98d23d0 [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
Lais Andrade3a6e47d2020-04-02 11:20:16 +010026#include <android/hardware/power/Boost.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070027#include <compositionengine/Display.h>
28#include <compositionengine/DisplayColorProfile.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070029#include <compositionengine/impl/Display.h>
Lloyd Pique33050472019-12-19 17:12:44 -080030#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070031#include <compositionengine/mock/Display.h>
32#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070033#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070034#include <compositionengine/mock/RenderSurface.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080035#include <gmock/gmock.h>
36#include <gtest/gtest.h>
Lloyd Pique1ebe0902019-10-04 14:47:13 -070037#include <gui/mock/GraphicBufferConsumer.h>
38#include <gui/mock/GraphicBufferProducer.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080039#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070040#include <renderengine/mock/RenderEngine.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070041#include <ui/DebugUtils.h>
Dominik Laskowski075d3172018-05-24 15:50:06 -070042
43#include "DisplayIdentificationTest.h"
Ana Krulecafb45842019-02-13 13:33:03 -080044#include "TestableScheduler.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080045#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080046#include "mock/DisplayHardware/MockComposer.h"
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070047#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070048#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080049#include "mock/MockEventControlThread.h"
50#include "mock/MockEventThread.h"
51#include "mock/MockMessageQueue.h"
52#include "mock/MockNativeWindowSurface.h"
53#include "mock/MockSurfaceInterceptor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080054#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080055
56namespace android {
57namespace {
58
Peiyong Line9d809e2020-04-14 13:10:48 -070059namespace hal = android::hardware::graphics::composer::hal;
60
Lais Andrade3a6e47d2020-04-02 11:20:16 +010061using android::hardware::power::Boost;
62
Lloyd Piquee39cad22017-12-20 17:01:29 -080063using testing::_;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070064using testing::AnyNumber;
Lloyd Piquee39cad22017-12-20 17:01:29 -080065using testing::DoAll;
66using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080067using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080068using testing::Return;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070069using testing::ReturnRefOfCopy;
Lloyd Piquee39cad22017-12-20 17:01:29 -080070using testing::SetArgPointee;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070071using testing::StrictMock;
Lloyd Piquee39cad22017-12-20 17:01:29 -080072
Peiyong Line9d809e2020-04-14 13:10:48 -070073using hal::ColorMode;
74using hal::Connection;
75using hal::DisplayCapability;
76using hal::DisplayType;
77using hal::Error;
78using hal::Hdr;
79using hal::HWDisplayId;
80using hal::IComposer;
81using hal::IComposerClient;
82using hal::PerFrameMetadataKey;
83using hal::PowerMode;
84using hal::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080085
Lloyd Piquec11e0d32018-01-22 18:44:59 -080086using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
87using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080088using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080089using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080090
Lloyd Piquec11e0d32018-01-22 18:44:59 -080091constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080092constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080093constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080094
Peiyong Lin65248e02020-04-18 21:15:07 -070095constexpr int POWER_MODE_LEET = 1337; // An out of range power mode value
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080096
Lloyd Piquec11e0d32018-01-22 18:44:59 -080097/* ------------------------------------------------------------------------
98 * Boolean avoidance
99 *
100 * To make calls and template instantiations more readable, we define some
101 * local enums along with an implicit bool conversion.
102 */
103
104#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
105
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800106BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700107BOOL_SUBSTITUTE(Critical);
108BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800109BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700110BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800111
112/* ------------------------------------------------------------------------
113 *
114 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800115
Lloyd Piquef58625d2017-12-19 13:22:33 -0800116class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800117public:
Lloyd Piquef58625d2017-12-19 13:22:33 -0800118 DisplayTransactionTest();
119 ~DisplayTransactionTest() override;
120
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800121 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800122 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800123
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700124 void injectMockScheduler();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800125 void injectMockComposer(int virtualDisplayCount);
126 void injectFakeBufferQueueFactory();
127 void injectFakeNativeWindowSurfaceFactory();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700128 sp<DisplayDevice> injectDefaultInternalDisplay(std::function<void(FakeDisplayDeviceInjector&)>);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800129
130 // --------------------------------------------------------------------
131 // Postcondition helpers
132
Peiyong Line9d809e2020-04-14 13:10:48 -0700133 bool hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800134 bool hasTransactionFlagSet(int flag);
135 bool hasDisplayDevice(sp<IBinder> displayToken);
136 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
137 bool hasCurrentDisplayState(sp<IBinder> displayToken);
138 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
139 bool hasDrawingDisplayState(sp<IBinder> displayToken);
140 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
141
142 // --------------------------------------------------------------------
143 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800144
Lloyd Piquef58625d2017-12-19 13:22:33 -0800145 TestableSurfaceFlinger mFlinger;
Alec Mouriba013fa2018-10-16 12:43:11 -0700146 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800147 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700148 Hwc2::mock::PowerAdvisor mPowerAdvisor;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800149
150 // These mocks are created by the test, but are destroyed by SurfaceFlinger
151 // by virtue of being stored into a std::unique_ptr. However we still need
152 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700153 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800154 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800155 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
156 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700157
158 mock::DispSync* mPrimaryDispSync = new mock::DispSync;
159 mock::EventControlThread* mEventControlThread = new mock::EventControlThread;
160 mock::EventThread* mEventThread = new mock::EventThread;
161 mock::EventThread* mSFEventThread = new mock::EventThread;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800162
163 // These mocks are created only when expected to be created via a factory.
164 sp<mock::GraphicBufferConsumer> mConsumer;
165 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700166 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800167};
168
169DisplayTransactionTest::DisplayTransactionTest() {
170 const ::testing::TestInfo* const test_info =
171 ::testing::UnitTest::GetInstance()->current_test_info();
172 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800173
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800174 // Default to no wide color display support configured
175 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700176 mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800177 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800178
179 // Default to using HWC virtual displays
180 mFlinger.mutableUseHwcVirtualDisplays() = true;
181
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800182 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
183 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
184 });
185
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800186 mFlinger.setCreateNativeWindowSurface([](auto) {
187 ADD_FAILURE() << "Unexpected request to create a native window surface.";
188 return nullptr;
189 });
190
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700191 injectMockScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800192 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700193 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800194 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800195
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800196 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800197}
198
199DisplayTransactionTest::~DisplayTransactionTest() {
200 const ::testing::TestInfo* const test_info =
201 ::testing::UnitTest::GetInstance()->current_test_info();
202 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
203}
204
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700205void DisplayTransactionTest::injectMockScheduler() {
Ana Krulecafb45842019-02-13 13:33:03 -0800206 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700207 EXPECT_CALL(*mEventThread, createEventConnection(_, _))
208 .WillOnce(Return(new EventThreadConnection(mEventThread, ResyncCallback(),
209 ISurfaceComposer::eConfigChangedSuppress)));
210
Ana Krulecafb45842019-02-13 13:33:03 -0800211 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700212 EXPECT_CALL(*mSFEventThread, createEventConnection(_, _))
213 .WillOnce(Return(new EventThreadConnection(mSFEventThread, ResyncCallback(),
214 ISurfaceComposer::eConfigChangedSuppress)));
Ana Krulecafb45842019-02-13 13:33:03 -0800215
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700216 mFlinger.setupScheduler(std::unique_ptr<DispSync>(mPrimaryDispSync),
217 std::unique_ptr<EventControlThread>(mEventControlThread),
218 std::unique_ptr<EventThread>(mEventThread),
219 std::unique_ptr<EventThread>(mSFEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800220}
221
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800222void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
223 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800224 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
225 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800226
Lloyd Piquee39cad22017-12-20 17:01:29 -0800227 Mock::VerifyAndClear(mComposer);
228}
229
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800230void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800231 // This setup is only expected once per test.
232 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
233
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800234 mConsumer = new mock::GraphicBufferConsumer();
235 mProducer = new mock::GraphicBufferProducer();
236
237 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
238 *outProducer = mProducer;
239 *outConsumer = mConsumer;
240 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800241}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800242
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800243void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800244 // This setup is only expected once per test.
245 ASSERT_TRUE(mNativeWindowSurface == nullptr);
246
Lloyd Pique22098362018-09-13 11:46:49 -0700247 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800248
Lloyd Pique22098362018-09-13 11:46:49 -0700249 mFlinger.setCreateNativeWindowSurface([this](auto) {
250 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
251 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800252}
253
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700254sp<DisplayDevice> DisplayTransactionTest::injectDefaultInternalDisplay(
255 std::function<void(FakeDisplayDeviceInjector&)> injectExtra) {
256 constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
257 constexpr int DEFAULT_DISPLAY_WIDTH = 1080;
258 constexpr int DEFAULT_DISPLAY_HEIGHT = 1920;
Peiyong Line9d809e2020-04-14 13:10:48 -0700259 constexpr HWDisplayId DEFAULT_DISPLAY_HWC_DISPLAY_ID = 0;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700260
261 // The DisplayDevice is required to have a framebuffer (behind the
262 // ANativeWindow interface) which uses the actual hardware display
263 // size.
264 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
265 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
266 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
267 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
268 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT));
269 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT));
270 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64));
271 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(AnyNumber());
272
273 auto compositionDisplay = compositionengine::impl::
274 createDisplay(mFlinger.getCompositionEngine(),
275 compositionengine::DisplayCreationArgsBuilder()
276 .setPhysical(
277 {DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal})
278 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
279 .setPowerAdvisor(&mPowerAdvisor)
280 .build());
281
282 auto injector =
283 FakeDisplayDeviceInjector(mFlinger, compositionDisplay, DisplayConnectionType::Internal,
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100284 DEFAULT_DISPLAY_HWC_DISPLAY_ID, true /* isPrimary */);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700285
286 injector.setNativeWindow(mNativeWindow);
287 if (injectExtra) {
288 injectExtra(injector);
289 }
290
291 auto displayDevice = injector.inject();
292
293 Mock::VerifyAndClear(mNativeWindow.get());
294
295 return displayDevice;
296}
297
Peiyong Line9d809e2020-04-14 13:10:48 -0700298bool DisplayTransactionTest::hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700299 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800300}
301
302bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
303 return mFlinger.mutableTransactionFlags() & flag;
304}
305
306bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700307 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800308}
309
310sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700311 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800312}
313
314bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
315 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
316}
317
318const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
319 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
320}
321
322bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
323 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
324}
325
326const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
327 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
328}
329
330/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800331 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800332 */
333
Dominik Laskowski075d3172018-05-24 15:50:06 -0700334template <typename PhysicalDisplay>
335struct PhysicalDisplayId {};
336
Dominik Laskowski34157762018-10-31 13:07:19 -0700337template <DisplayId::Type displayId>
338using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700339
340struct NoDisplayId {};
341
342template <typename>
343struct IsPhysicalDisplayId : std::bool_constant<false> {};
344
345template <typename PhysicalDisplay>
346struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
347
348template <typename>
349struct DisplayIdGetter;
350
351template <typename PhysicalDisplay>
352struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
353 static std::optional<DisplayId> get() {
354 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
355 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
Peiyong Lin65248e02020-04-18 21:15:07 -0700356 ? LEGACY_DISPLAY_TYPE_PRIMARY
357 : LEGACY_DISPLAY_TYPE_EXTERNAL);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700358 }
359
360 const auto info =
361 parseDisplayIdentificationData(PhysicalDisplay::PORT,
362 PhysicalDisplay::GET_IDENTIFICATION_DATA());
363 return info ? std::make_optional(info->id) : std::nullopt;
364 }
365};
366
Dominik Laskowski34157762018-10-31 13:07:19 -0700367template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700368struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700369 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700370};
371
372template <>
373struct DisplayIdGetter<NoDisplayId> {
374 static std::optional<DisplayId> get() { return {}; }
375};
376
Dominik Laskowski55c85402020-01-21 16:25:47 -0800377template <typename>
378struct DisplayConnectionTypeGetter {
379 static constexpr std::optional<DisplayConnectionType> value;
380};
381
382template <typename PhysicalDisplay>
383struct DisplayConnectionTypeGetter<PhysicalDisplayId<PhysicalDisplay>> {
384 static constexpr std::optional<DisplayConnectionType> value = PhysicalDisplay::CONNECTION_TYPE;
385};
386
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100387template <typename>
388struct HwcDisplayIdGetter {
Peiyong Line9d809e2020-04-14 13:10:48 -0700389 static constexpr std::optional<HWDisplayId> value;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100390};
391
Peiyong Line9d809e2020-04-14 13:10:48 -0700392constexpr HWDisplayId HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID = 1010;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100393
394template <DisplayId::Type displayId>
395struct HwcDisplayIdGetter<VirtualDisplayId<displayId>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700396 static constexpr std::optional<HWDisplayId> value = HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100397};
398
399template <typename PhysicalDisplay>
400struct HwcDisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700401 static constexpr std::optional<HWDisplayId> value = PhysicalDisplay::HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100402};
403
Dominik Laskowski075d3172018-05-24 15:50:06 -0700404// DisplayIdType can be:
405// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
406// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
407// 3) NoDisplayId for virtual display without HWC backing.
408template <typename DisplayIdType, int width, int height, Critical critical, Async async,
409 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800410struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700411 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800412 using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100413 using HWC_DISPLAY_ID_OPT = HwcDisplayIdGetter<DisplayIdType>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700414
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800415 // The display width and height
416 static constexpr int WIDTH = width;
417 static constexpr int HEIGHT = height;
418
419 static constexpr int GRALLOC_USAGE = grallocUsage;
420
Dominik Laskowski075d3172018-05-24 15:50:06 -0700421 // Whether the display is virtual or physical
422 static constexpr Virtual VIRTUAL =
423 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800424
425 // When creating native window surfaces for the framebuffer, whether those should be critical
426 static constexpr Critical CRITICAL = critical;
427
428 // When creating native window surfaces for the framebuffer, whether those should be async
429 static constexpr Async ASYNC = async;
430
431 // Whether the display should be treated as secure
432 static constexpr Secure SECURE = secure;
433
Dominik Laskowski075d3172018-05-24 15:50:06 -0700434 // Whether the display is primary
435 static constexpr Primary PRIMARY = primary;
436
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800437 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700438 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder();
439 if (auto displayId = DISPLAY_ID::get()) {
440 ceDisplayArgs.setPhysical({*displayId, DisplayConnectionType::Internal});
441 } else {
442 ceDisplayArgs.setUseHwcVirtualDisplays(false);
443 }
444 ceDisplayArgs.setPixels({WIDTH, HEIGHT}).setPowerAdvisor(&test->mPowerAdvisor).build();
445
446 auto compositionDisplay =
447 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
448 ceDisplayArgs.build());
449
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100450 auto injector = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
451 CONNECTION_TYPE::value, HWC_DISPLAY_ID_OPT::value,
452 static_cast<bool>(PRIMARY));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700453
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800454 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700455 injector.setNativeWindow(test->mNativeWindow);
456
457 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800458 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700459 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
460 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
461 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
462 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800463 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
464 .WillRepeatedly(Return(0));
465 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
466 .WillRepeatedly(Return(0));
467 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
468 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700469 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
470 .WillRepeatedly(Return(0));
471
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800472 return injector;
473 }
474
475 // Called by tests to set up any native window creation call expectations.
476 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
477 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
478 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800479
Alec Mouriba013fa2018-10-16 12:43:11 -0700480 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
481 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
482 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
483 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800484 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
485 .WillRepeatedly(Return(0));
486 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
487 .WillRepeatedly(Return(0));
488 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
489 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700490 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
491 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800492 }
493
494 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
495 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
496 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
497 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
498 .WillRepeatedly(Return(NO_ERROR));
499 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
500 .WillRepeatedly(Return(NO_ERROR));
501 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
502 .WillRepeatedly(Return(NO_ERROR));
503 }
504
505 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
506 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
507 }
508};
509
Peiyong Line9d809e2020-04-14 13:10:48 -0700510template <HWDisplayId hwcDisplayId, DisplayType hwcDisplayType, typename DisplayVariant,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700511 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800512struct HwcDisplayVariant {
513 // The display id supplied by the HWC
Peiyong Line9d809e2020-04-14 13:10:48 -0700514 static constexpr HWDisplayId HWC_DISPLAY_ID = hwcDisplayId;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800515
516 // The HWC display type
Peiyong Line9d809e2020-04-14 13:10:48 -0700517 static constexpr DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800518
519 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700520 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin65248e02020-04-18 21:15:07 -0700521 static constexpr PowerMode INIT_POWER_MODE = PowerMode::ON;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800522
Peiyong Line9d809e2020-04-14 13:10:48 -0700523 static void injectPendingHotplugEvent(DisplayTransactionTest* test, Connection connection) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800524 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
525 HotplugEvent{HWC_DISPLAY_ID, connection});
526 }
527
528 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800529 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700530 const auto displayId = DisplayVariant::DISPLAY_ID::get();
531 ASSERT_TRUE(displayId);
532 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
533 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800534 .setHwcDisplayId(HWC_DISPLAY_ID)
535 .setWidth(DisplayVariant::WIDTH)
536 .setHeight(DisplayVariant::HEIGHT)
537 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700538 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800539 .inject(&test->mFlinger, test->mComposer);
540 }
541
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800542 // Called by tests to inject a HWC display setup
543 static void injectHwcDisplay(DisplayTransactionTest* test) {
544 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700545 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800546 Return(Error::NONE)));
Peiyong Lin65248e02020-04-18 21:15:07 -0700547 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY_ID, INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700548 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800549 injectHwcDisplayWithNoDefaultCapabilities(test);
550 }
551
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700552 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
553 DisplayTransactionTest* test) {
554 const ::testing::TestInfo* const test_info =
555 ::testing::UnitTest::GetInstance()->current_test_info();
556
557 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
558 .setPhysical({*DisplayVariant::DISPLAY_ID::get(),
559 PhysicalDisplay::CONNECTION_TYPE})
560 .setPixels({DisplayVariant::WIDTH, DisplayVariant::HEIGHT})
561 .setIsSecure(static_cast<bool>(DisplayVariant::SECURE))
562 .setPowerAdvisor(&test->mPowerAdvisor)
563 .setName(std::string("Injected display for ") +
564 test_info->test_case_name() + "." + test_info->name())
565 .build();
566
567 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
568 ceDisplayArgs);
569 }
570
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800571 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800572 constexpr auto CONNECTION_TYPE =
573 PhysicalDisplay::CONNECTION_TYPE == DisplayConnectionType::Internal
574 ? IComposerClient::DisplayConnectionType::INTERNAL
575 : IComposerClient::DisplayConnectionType::EXTERNAL;
576
577 EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700578 .WillOnce(DoAll(SetArgPointee<1>(CONNECTION_TYPE), Return(hal::V2_4::Error::NONE)));
Dominik Laskowski55c85402020-01-21 16:25:47 -0800579
Peiyong Line9d809e2020-04-14 13:10:48 -0700580 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_))
581 .WillOnce(Return(hal::Error::NONE));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800582 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
583 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
584 Return(Error::NONE)));
585 EXPECT_CALL(*test->mComposer,
586 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
587 IComposerClient::Attribute::WIDTH, _))
588 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
589 EXPECT_CALL(*test->mComposer,
590 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
591 IComposerClient::Attribute::HEIGHT, _))
592 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
593 EXPECT_CALL(*test->mComposer,
594 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
595 IComposerClient::Attribute::VSYNC_PERIOD, _))
596 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
597 EXPECT_CALL(*test->mComposer,
598 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
599 IComposerClient::Attribute::DPI_X, _))
600 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
601 EXPECT_CALL(*test->mComposer,
602 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
603 IComposerClient::Attribute::DPI_Y, _))
604 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Ady Abraham7159f572019-10-11 11:10:18 -0700605 EXPECT_CALL(*test->mComposer,
606 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
607 IComposerClient::Attribute::CONFIG_GROUP, _))
608 .WillOnce(DoAll(SetArgPointee<3>(-1), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700609
610 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
611 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200612 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
613 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
614 Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700615 } else {
616 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200617 .WillOnce(Return(Error::UNSUPPORTED));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700618 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800619 }
620
621 // Called by tests to set up HWC call expectations
622 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
623 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700624 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800625 }
626};
627
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800628// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
629constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
630 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
631
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100632template <typename PhysicalDisplay, int width, int height, Critical critical>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800633struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700634 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
635 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
Peiyong Line9d809e2020-04-14 13:10:48 -0700636 HwcDisplayVariant<PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700637 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
638 critical, Async::FALSE, Secure::TRUE,
639 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
640 PhysicalDisplay> {};
641
642template <bool hasIdentificationData>
643struct PrimaryDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800644 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::Internal;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700645 static constexpr Primary PRIMARY = Primary::TRUE;
646 static constexpr uint8_t PORT = 255;
Peiyong Line9d809e2020-04-14 13:10:48 -0700647 static constexpr HWDisplayId HWC_DISPLAY_ID = 1001;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700648 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
649 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
650};
651
652template <bool hasIdentificationData>
653struct ExternalDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800654 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::External;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700655 static constexpr Primary PRIMARY = Primary::FALSE;
656 static constexpr uint8_t PORT = 254;
Peiyong Line9d809e2020-04-14 13:10:48 -0700657 static constexpr HWDisplayId HWC_DISPLAY_ID = 1002;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700658 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
659 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
660};
661
662struct TertiaryDisplay {
663 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800664 static constexpr uint8_t PORT = 253;
Peiyong Line9d809e2020-04-14 13:10:48 -0700665 static constexpr HWDisplayId HWC_DISPLAY_ID = 1003;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800666 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700667};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800668
669// A primary display is a physical display that is critical
670using PrimaryDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100671 PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800672
673// An external display is physical display that is not critical.
674using ExternalDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100675 PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800676
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100677using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800678
679// A virtual display not supported by the HWC.
680constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
681
682template <int width, int height, Secure secure>
683struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700684 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
685 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
686 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
687 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
688
689 static void injectHwcDisplay(DisplayTransactionTest*) {}
690
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700691 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
692 DisplayTransactionTest* test) {
693 const ::testing::TestInfo* const test_info =
694 ::testing::UnitTest::GetInstance()->current_test_info();
695
696 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
697 .setPixels({Base::WIDTH, Base::HEIGHT})
698 .setIsSecure(static_cast<bool>(Base::SECURE))
699 .setPowerAdvisor(&test->mPowerAdvisor)
700 .setName(std::string("Injected display for ") +
701 test_info->test_case_name() + "." + test_info->name())
702 .build();
703
704 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
705 ceDisplayArgs);
706 }
707
Dominik Laskowski075d3172018-05-24 15:50:06 -0700708 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
709 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
710 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800711
712 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
713 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
714 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
715 }
716};
717
718// A virtual display supported by the HWC.
719constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
720
721template <int width, int height, Secure secure>
722struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700723 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
724 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
725 HwcDisplayVariant<
Peiyong Line9d809e2020-04-14 13:10:48 -0700726 HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700727 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
728 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
729 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
730 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800731 using Self = HwcVirtualDisplayVariant<width, height, secure>;
732
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700733 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
734 DisplayTransactionTest* test) {
735 const ::testing::TestInfo* const test_info =
736 ::testing::UnitTest::GetInstance()->current_test_info();
737
738 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
739 .setUseHwcVirtualDisplays(false)
740 .setPixels({Base::WIDTH, Base::HEIGHT})
741 .setIsSecure(static_cast<bool>(Base::SECURE))
742 .setPowerAdvisor(&test->mPowerAdvisor)
743 .setName(std::string("Injected display for ") +
744 test_info->test_case_name() + "." + test_info->name())
745 .build();
746
747 auto compositionDisplay =
748 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
749 ceDisplayArgs);
750 compositionDisplay->setDisplayIdForTesting(Base::DISPLAY_ID::get());
751
752 // Insert display data so that the HWC thinks it created the virtual display.
753 if (const auto displayId = Base::DISPLAY_ID::get()) {
754 test->mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
755 }
756
757 return compositionDisplay;
758 }
759
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800760 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
761 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
762 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
763 }
764
765 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
766 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
767 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
768 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
769 }
770};
771
772// For this variant, SurfaceFlinger should not configure itself with wide
773// display support, so the display should not be configured for wide-color
774// support.
775struct WideColorSupportNotConfiguredVariant {
776 static constexpr bool WIDE_COLOR_SUPPORTED = false;
777
778 static void injectConfigChange(DisplayTransactionTest* test) {
779 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700780 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800781 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800782 }
783
784 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
785 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
786 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
787 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
788 }
789};
790
791// For this variant, SurfaceFlinger should configure itself with wide display
792// support, and the display should respond with an non-empty list of supported
793// color modes. Wide-color support should be configured.
794template <typename Display>
795struct WideColorP3ColorimetricSupportedVariant {
796 static constexpr bool WIDE_COLOR_SUPPORTED = true;
797
798 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700799 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800800 test->mFlinger.mutableHasWideColorDisplay() = true;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800801 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800802 }
803
804 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800805 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
806
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800807 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
808 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
809 Return(Error::NONE)));
810 EXPECT_CALL(*test->mComposer,
811 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
812 .WillOnce(DoAll(SetArgPointee<2>(
813 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
814 Return(Error::NONE)));
815 EXPECT_CALL(*test->mComposer,
816 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
817 RenderIntent::COLORIMETRIC))
818 .WillOnce(Return(Error::NONE));
819 }
820};
821
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800822// For this variant, SurfaceFlinger should configure itself with wide display
823// support, but the display should respond with an empty list of supported color
824// modes. Wide-color support for the display should not be configured.
825template <typename Display>
826struct WideColorNotSupportedVariant {
827 static constexpr bool WIDE_COLOR_SUPPORTED = false;
828
829 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700830 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800831 test->mFlinger.mutableHasWideColorDisplay() = true;
832 }
833
834 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
835 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
836 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700837 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800838 }
839};
840
841// For this variant, the display is not a HWC display, so no HDR support should
842// be configured.
843struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800844 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800845 static constexpr bool HDR10_SUPPORTED = false;
846 static constexpr bool HDR_HLG_SUPPORTED = false;
847 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
848 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
849 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
850 }
851};
852
Valerie Haue9e843a2018-12-18 13:39:23 -0800853template <typename Display>
854struct Hdr10PlusSupportedVariant {
855 static constexpr bool HDR10_PLUS_SUPPORTED = true;
856 static constexpr bool HDR10_SUPPORTED = true;
857 static constexpr bool HDR_HLG_SUPPORTED = false;
858 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
859 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
860 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
861 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
862 Hdr::HDR10_PLUS,
863 Hdr::HDR10,
864 })),
865 Return(Error::NONE)));
866 }
867};
868
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800869// For this variant, the composer should respond with a non-empty list of HDR
870// modes containing HDR10, so HDR10 support should be configured.
871template <typename Display>
872struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800873 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800874 static constexpr bool HDR10_SUPPORTED = true;
875 static constexpr bool HDR_HLG_SUPPORTED = false;
876 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
877 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
878 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
879 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
880 Return(Error::NONE)));
881 }
882};
883
884// For this variant, the composer should respond with a non-empty list of HDR
885// modes containing HLG, so HLG support should be configured.
886template <typename Display>
887struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800888 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800889 static constexpr bool HDR10_SUPPORTED = false;
890 static constexpr bool HDR_HLG_SUPPORTED = true;
891 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
892 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
893 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
894 .WillOnce(
895 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
896 }
897};
898
899// For this variant, the composer should respond with a non-empty list of HDR
900// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
901template <typename Display>
902struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800903 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800904 static constexpr bool HDR10_SUPPORTED = false;
905 static constexpr bool HDR_HLG_SUPPORTED = false;
906 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
907 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
908 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
909 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
910 Return(Error::NONE)));
911 }
912};
913
914// For this variant, the composer should respond with am empty list of HDR
915// modes, so no HDR support should be configured.
916template <typename Display>
917struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800918 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800919 static constexpr bool HDR10_SUPPORTED = false;
920 static constexpr bool HDR_HLG_SUPPORTED = false;
921 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
922 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
923 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
924 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
925 }
926};
927
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700928struct NonHwcPerFrameMetadataSupportVariant {
929 static constexpr int PER_FRAME_METADATA_KEYS = 0;
930 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800931 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700932 }
933};
934
935template <typename Display>
936struct NoPerFrameMetadataSupportVariant {
937 static constexpr int PER_FRAME_METADATA_KEYS = 0;
938 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800939 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
940 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700941 }
942};
943
944template <typename Display>
945struct Smpte2086PerFrameMetadataSupportVariant {
946 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
947 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800948 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
949 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800950 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
951 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
952 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
953 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
954 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
955 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
956 PerFrameMetadataKey::WHITE_POINT_X,
957 PerFrameMetadataKey::WHITE_POINT_Y,
958 PerFrameMetadataKey::MAX_LUMINANCE,
959 PerFrameMetadataKey::MIN_LUMINANCE,
960 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700961 }
962};
963
964template <typename Display>
965struct Cta861_3_PerFrameMetadataSupportVariant {
966 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
967 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800968 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
969 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800970 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
971 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
972 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700973 }
974};
975
Valerie Haue9e843a2018-12-18 13:39:23 -0800976template <typename Display>
977struct Hdr10_Plus_PerFrameMetadataSupportVariant {
978 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
979 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
980 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
981 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
982 PerFrameMetadataKey::HDR10_PLUS_SEI,
983 })));
984 }
985};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800986/* ------------------------------------------------------------------------
987 * Typical display configurations to test
988 */
989
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700990template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
991 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800992struct Case {
993 using Display = DisplayPolicy;
994 using WideColorSupport = WideColorSupportPolicy;
995 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700996 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800997};
998
999using SimplePrimaryDisplayCase =
1000 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001001 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1002 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001003using SimpleExternalDisplayCase =
1004 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001005 HdrNotSupportedVariant<ExternalDisplayVariant>,
1006 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001007using SimpleTertiaryDisplayCase =
1008 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001009 HdrNotSupportedVariant<TertiaryDisplayVariant>,
1010 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001011using NonHwcVirtualDisplayCase =
1012 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001013 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
1014 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001015using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
1016using HwcVirtualDisplayCase =
1017 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -07001018 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +08001019 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001020using WideColorP3ColorimetricDisplayCase =
1021 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001022 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1023 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -08001024using Hdr10PlusDisplayCase =
1025 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1026 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1027 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001028using Hdr10DisplayCase =
1029 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001030 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1031 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001032using HdrHlgDisplayCase =
1033 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001034 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
1035 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001036using HdrDolbyVisionDisplayCase =
1037 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001038 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
1039 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1040using HdrSmpte2086DisplayCase =
1041 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1042 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1043 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1044using HdrCta861_3_DisplayCase =
1045 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1046 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1047 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -07001048
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001049/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -08001050 *
1051 * SurfaceFlinger::onHotplugReceived
1052 */
1053
1054TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
1055 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001056 constexpr HWDisplayId hwcDisplayId1 = 456;
1057 constexpr HWDisplayId hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001058
1059 // --------------------------------------------------------------------
1060 // Preconditions
1061
1062 // Set the current sequence id for accepted events
1063 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1064
1065 // Set the main thread id so that the current thread does not appear to be
1066 // the main thread.
1067 mFlinger.mutableMainThreadId() = std::thread::id();
1068
1069 // --------------------------------------------------------------------
1070 // Call Expectations
1071
1072 // We expect invalidate() to be invoked once to trigger display transaction
1073 // processing.
1074 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1075
1076 // --------------------------------------------------------------------
1077 // Invocation
1078
1079 // Simulate two hotplug events (a connect and a disconnect)
Peiyong Line9d809e2020-04-14 13:10:48 -07001080 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, Connection::CONNECTED);
1081 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001082
1083 // --------------------------------------------------------------------
1084 // Postconditions
1085
1086 // The display transaction needed flag should be set.
1087 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1088
1089 // All events should be in the pending event queue.
1090 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
1091 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001092 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001093 EXPECT_EQ(Connection::CONNECTED, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001094 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001095 EXPECT_EQ(Connection::DISCONNECTED, pendingEvents[1].connection);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001096}
1097
1098TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
1099 constexpr int currentSequenceId = 123;
1100 constexpr int otherSequenceId = 321;
Peiyong Line9d809e2020-04-14 13:10:48 -07001101 constexpr HWDisplayId displayId = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001102
1103 // --------------------------------------------------------------------
1104 // Preconditions
1105
1106 // Set the current sequence id for accepted events
1107 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1108
1109 // Set the main thread id so that the current thread does not appear to be
1110 // the main thread.
1111 mFlinger.mutableMainThreadId() = std::thread::id();
1112
1113 // --------------------------------------------------------------------
1114 // Call Expectations
1115
1116 // We do not expect any calls to invalidate().
1117 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
1118
1119 // --------------------------------------------------------------------
1120 // Invocation
1121
1122 // Call with an unexpected sequence id
Peiyong Line9d809e2020-04-14 13:10:48 -07001123 mFlinger.onHotplugReceived(otherSequenceId, displayId, Connection::INVALID);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001124
1125 // --------------------------------------------------------------------
1126 // Postconditions
1127
1128 // The display transaction needed flag should not be set
1129 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1130
1131 // There should be no pending events
1132 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1133}
1134
1135TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
1136 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001137 constexpr HWDisplayId displayId1 = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001138
1139 // --------------------------------------------------------------------
1140 // Note:
1141 // --------------------------------------------------------------------
1142 // This test case is a bit tricky. We want to verify that
1143 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
1144 // don't really want to provide coverage for everything the later function
1145 // does as there are specific tests for it.
1146 // --------------------------------------------------------------------
1147
1148 // --------------------------------------------------------------------
1149 // Preconditions
1150
1151 // Set the current sequence id for accepted events
1152 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1153
1154 // Set the main thread id so that the current thread does appear to be the
1155 // main thread.
1156 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
1157
1158 // --------------------------------------------------------------------
1159 // Call Expectations
1160
1161 // We expect invalidate() to be invoked once to trigger display transaction
1162 // processing.
1163 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1164
1165 // --------------------------------------------------------------------
1166 // Invocation
1167
1168 // Simulate a disconnect on a display id that is not connected. This should
1169 // be enqueued by onHotplugReceived(), and dequeued by
1170 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
Peiyong Line9d809e2020-04-14 13:10:48 -07001171 mFlinger.onHotplugReceived(currentSequenceId, displayId1, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001172
1173 // --------------------------------------------------------------------
1174 // Postconditions
1175
1176 // The display transaction needed flag should be set.
1177 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1178
1179 // There should be no event queued on return, as it should have been
1180 // processed.
1181 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1182}
1183
1184/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001185 * SurfaceFlinger::createDisplay
1186 */
1187
1188TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1189 const String8 name("virtual.test");
1190
1191 // --------------------------------------------------------------------
1192 // Call Expectations
1193
1194 // The call should notify the interceptor that a display was created.
1195 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1196
1197 // --------------------------------------------------------------------
1198 // Invocation
1199
1200 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1201
1202 // --------------------------------------------------------------------
1203 // Postconditions
1204
1205 // The display should have been added to the current state
1206 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1207 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001208 EXPECT_TRUE(display.isVirtual());
1209 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001210 EXPECT_EQ(name.string(), display.displayName);
1211
1212 // --------------------------------------------------------------------
1213 // Cleanup conditions
1214
1215 // Destroying the display invalidates the display state.
1216 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1217}
1218
1219TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1220 const String8 name("virtual.test");
1221
1222 // --------------------------------------------------------------------
1223 // Call Expectations
1224
1225 // The call should notify the interceptor that a display was created.
1226 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1227
1228 // --------------------------------------------------------------------
1229 // Invocation
1230
1231 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1232
1233 // --------------------------------------------------------------------
1234 // Postconditions
1235
1236 // The display should have been added to the current state
1237 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1238 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001239 EXPECT_TRUE(display.isVirtual());
1240 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001241 EXPECT_EQ(name.string(), display.displayName);
1242
1243 // --------------------------------------------------------------------
1244 // Cleanup conditions
1245
1246 // Destroying the display invalidates the display state.
1247 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1248}
1249
1250/* ------------------------------------------------------------------------
1251 * SurfaceFlinger::destroyDisplay
1252 */
1253
1254TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1255 using Case = NonHwcVirtualDisplayCase;
1256
1257 // --------------------------------------------------------------------
1258 // Preconditions
1259
1260 // A virtual display exists
1261 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1262 existing.inject();
1263
1264 // --------------------------------------------------------------------
1265 // Call Expectations
1266
1267 // The call should notify the interceptor that a display was created.
1268 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1269
1270 // Destroying the display invalidates the display state.
1271 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1272
1273 // --------------------------------------------------------------------
1274 // Invocation
1275
1276 mFlinger.destroyDisplay(existing.token());
1277
1278 // --------------------------------------------------------------------
1279 // Postconditions
1280
1281 // The display should have been removed from the current state
1282 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1283
1284 // Ths display should still exist in the drawing state
1285 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1286
1287 // The display transaction needed flasg should be set
1288 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1289}
1290
1291TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1292 // --------------------------------------------------------------------
1293 // Preconditions
1294
1295 sp<BBinder> displayToken = new BBinder();
1296
1297 // --------------------------------------------------------------------
1298 // Invocation
1299
1300 mFlinger.destroyDisplay(displayToken);
1301}
1302
1303/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001304 * SurfaceFlinger::resetDisplayState
1305 */
1306
1307TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1308 using Case = NonHwcVirtualDisplayCase;
1309
1310 // --------------------------------------------------------------------
1311 // Preconditions
1312
1313 // vsync is enabled and available
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001314 mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = true;
1315 mFlinger.scheduler()->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001316
1317 // A display exists
1318 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1319 existing.inject();
1320
1321 // --------------------------------------------------------------------
1322 // Call Expectations
1323
1324 // The call disable vsyncs
1325 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1326
Lloyd Pique41be5d22018-06-21 13:11:48 -07001327 // The call ends any display resyncs
1328 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1329
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001330 // --------------------------------------------------------------------
1331 // Invocation
1332
1333 mFlinger.resetDisplayState();
1334
1335 // --------------------------------------------------------------------
1336 // Postconditions
1337
1338 // vsyncs should be off and not available.
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001339 EXPECT_FALSE(mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled());
1340 EXPECT_FALSE(mFlinger.scheduler()->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001341
1342 // The display should have been removed from the display map.
1343 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1344
1345 // The display should still exist in the current state
1346 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1347
1348 // The display should have been removed from the drawing state
1349 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1350}
1351
1352/* ------------------------------------------------------------------------
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001353 * SurfaceFlinger::notifyPowerBoost
1354 */
1355
1356TEST_F(DisplayTransactionTest, notifyPowerBoostNotifiesTouchEvent) {
1357 mFlinger.scheduler()->replaceTouchTimer(100);
1358 std::this_thread::sleep_for(10ms); // wait for callback to be triggered
1359 EXPECT_TRUE(mFlinger.scheduler()->isTouchActive()); // Starting timer activates touch
1360
1361 std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback
1362 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1363
1364 EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::CAMERA_SHOT)));
1365 std::this_thread::sleep_for(10ms); // wait for callback to maybe be triggered
1366 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1367
1368 std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback
1369 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1370
1371 EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::INTERACTION)));
1372 std::this_thread::sleep_for(10ms); // wait for callback to be triggered.
1373 EXPECT_TRUE(mFlinger.scheduler()->isTouchActive());
1374}
1375
1376/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001377 * DisplayDevice::GetBestColorMode
1378 */
1379class GetBestColorModeTest : public DisplayTransactionTest {
1380public:
Valerie Hau9758ae02018-10-09 16:05:09 -07001381 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1382
1383 void addHwcColorModesMapping(ui::ColorMode colorMode,
1384 std::vector<ui::RenderIntent> renderIntents) {
1385 mHwcColorModes[colorMode] = renderIntents;
1386 }
1387
1388 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1389
1390 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1391
1392 void getBestColorMode() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001393 auto displayDevice =
1394 injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1395 injector.setHwcColorModes(mHwcColorModes);
1396 injector.setHasWideColorGamut(mHasWideColorGamut);
1397 injector.setNativeWindow(mNativeWindow);
1398 });
Valerie Hau9758ae02018-10-09 16:05:09 -07001399
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001400 displayDevice->getCompositionDisplay()
1401 ->getDisplayColorProfile()
1402 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1403 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001404 }
1405
1406 ui::Dataspace mOutDataspace;
1407 ui::ColorMode mOutColorMode;
1408 ui::RenderIntent mOutRenderIntent;
1409
1410private:
1411 ui::Dataspace mInputDataspace;
1412 ui::RenderIntent mInputRenderIntent;
1413 bool mHasWideColorGamut = false;
1414 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
Valerie Hau9758ae02018-10-09 16:05:09 -07001415};
1416
1417TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1418 addHwcColorModesMapping(ui::ColorMode::SRGB,
1419 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1420 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1421 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1422 setHasWideColorGamut(true);
1423
1424 getBestColorMode();
1425
Peiyong Lin14724e62018-12-05 07:27:30 -08001426 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001427 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1428 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1429}
1430
1431TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1432 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1433 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1434 addHwcColorModesMapping(ui::ColorMode::SRGB,
1435 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1436 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1437 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1438 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1439 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1440 setHasWideColorGamut(true);
1441
1442 getBestColorMode();
1443
1444 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1445 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1446 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1447}
1448
1449TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1450 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1451 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1452 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1453 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1454 setHasWideColorGamut(true);
1455
1456 getBestColorMode();
1457
1458 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1459 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1460 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1461}
1462
1463/* ------------------------------------------------------------------------
Lloyd Pique33050472019-12-19 17:12:44 -08001464 * DisplayDevice::setProjection
1465 */
1466
1467class DisplayDeviceSetProjectionTest : public DisplayTransactionTest {
1468public:
Lloyd Pique33050472019-12-19 17:12:44 -08001469 static constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1080; // arbitrary
1470 static constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1920; // arbitrary
1471
1472 static constexpr int32_t TRANSFORM_FLAGS_ROT_0 = 0;
1473 static constexpr int32_t TRANSFORM_FLAGS_ROT_90 = HAL_TRANSFORM_ROT_90;
1474 static constexpr int32_t TRANSFORM_FLAGS_ROT_180 = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V;
1475 static constexpr int32_t TRANSFORM_FLAGS_ROT_270 =
1476 HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
1477
1478 DisplayDeviceSetProjectionTest(ui::Size flingerDisplaySize, ui::Size hardwareDisplaySize,
1479 ui::Rotation physicalOrientation)
1480 : mFlingerDisplaySize(flingerDisplaySize),
1481 mHardwareDisplaySize(hardwareDisplaySize),
1482 mPhysicalOrientation(physicalOrientation),
1483 mDisplayDevice(createDisplayDevice()) {}
1484
1485 sp<DisplayDevice> createDisplayDevice() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001486 return injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1487 injector.setPhysicalOrientation(mPhysicalOrientation);
1488 });
Lloyd Pique33050472019-12-19 17:12:44 -08001489 }
1490
1491 ui::Size SwapWH(const ui::Size size) const { return ui::Size(size.height, size.width); }
1492
1493 void setProjectionForRotation0() {
1494 // A logical rotation of 0 uses the SurfaceFlinger display size
1495 mDisplayDevice->setProjection(ui::ROTATION_0, Rect(mFlingerDisplaySize),
1496 Rect(mFlingerDisplaySize));
1497 }
1498
1499 void setProjectionForRotation90() {
1500 // A logical rotation of 90 uses the SurfaceFlinger display size with
1501 // the width/height swapped.
1502 mDisplayDevice->setProjection(ui::ROTATION_90, Rect(SwapWH(mFlingerDisplaySize)),
1503 Rect(SwapWH(mFlingerDisplaySize)));
1504 }
1505
1506 void setProjectionForRotation180() {
1507 // A logical rotation of 180 uses the SurfaceFlinger display size
1508 mDisplayDevice->setProjection(ui::ROTATION_180, Rect(mFlingerDisplaySize),
1509 Rect(mFlingerDisplaySize));
1510 }
1511
1512 void setProjectionForRotation270() {
1513 // A logical rotation of 270 uses the SurfaceFlinger display size with
1514 // the width/height swapped.
1515 mDisplayDevice->setProjection(ui::ROTATION_270, Rect(SwapWH(mFlingerDisplaySize)),
1516 Rect(SwapWH(mFlingerDisplaySize)));
1517 }
1518
1519 void expectStateForHardwareTransform0() {
1520 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1521 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_0, mHardwareDisplaySize.width,
1522 mHardwareDisplaySize.height),
1523 compositionState.transform);
1524 EXPECT_EQ(TRANSFORM_FLAGS_ROT_0, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001525 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001526 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1527 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1528 EXPECT_EQ(false, compositionState.needsFiltering);
1529 }
1530
1531 void expectStateForHardwareTransform90() {
1532 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1533 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width,
1534 mHardwareDisplaySize.height),
1535 compositionState.transform);
1536 EXPECT_EQ(TRANSFORM_FLAGS_ROT_90, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001537 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001538 // For 90, the frame and viewport have the hardware display size width and height swapped
1539 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1540 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1541 EXPECT_EQ(false, compositionState.needsFiltering);
1542 }
1543
1544 void expectStateForHardwareTransform180() {
1545 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1546 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width,
1547 mHardwareDisplaySize.height),
1548 compositionState.transform);
1549 EXPECT_EQ(TRANSFORM_FLAGS_ROT_180, compositionState.orientation);
Lloyd Pique33050472019-12-19 17:12:44 -08001550 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1551 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1552 EXPECT_EQ(false, compositionState.needsFiltering);
1553 }
1554
1555 void expectStateForHardwareTransform270() {
1556 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1557 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width,
1558 mHardwareDisplaySize.height),
1559 compositionState.transform);
1560 EXPECT_EQ(TRANSFORM_FLAGS_ROT_270, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001561 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001562 // For 270, the frame and viewport have the hardware display size width and height swapped
1563 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1564 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1565 EXPECT_EQ(false, compositionState.needsFiltering);
1566 }
1567
1568 const ui::Size mFlingerDisplaySize;
1569 const ui::Size mHardwareDisplaySize;
1570 const ui::Rotation mPhysicalOrientation;
1571 const sp<DisplayDevice> mDisplayDevice;
1572};
1573
1574struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest {
1575 DisplayDeviceSetProjectionTest_Installed0()
1576 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1577 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1578 ui::ROTATION_0) {}
1579};
1580
1581TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) {
1582 setProjectionForRotation0();
1583 expectStateForHardwareTransform0();
1584}
1585
1586TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) {
1587 setProjectionForRotation90();
1588 expectStateForHardwareTransform90();
1589}
1590
1591TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) {
1592 setProjectionForRotation180();
1593 expectStateForHardwareTransform180();
1594}
1595
1596TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) {
1597 setProjectionForRotation270();
1598 expectStateForHardwareTransform270();
1599}
1600
1601struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest {
1602 DisplayDeviceSetProjectionTest_Installed90()
1603 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1604 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1605 ui::ROTATION_90) {}
1606};
1607
1608TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) {
1609 setProjectionForRotation0();
1610 expectStateForHardwareTransform90();
1611}
1612
1613TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) {
1614 setProjectionForRotation90();
1615 expectStateForHardwareTransform180();
1616}
1617
1618TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) {
1619 setProjectionForRotation180();
1620 expectStateForHardwareTransform270();
1621}
1622
1623TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) {
1624 setProjectionForRotation270();
1625 expectStateForHardwareTransform0();
1626}
1627
1628struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest {
1629 DisplayDeviceSetProjectionTest_Installed180()
1630 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1631 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1632 ui::ROTATION_180) {}
1633};
1634
1635TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) {
1636 setProjectionForRotation0();
1637 expectStateForHardwareTransform180();
1638}
1639
1640TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) {
1641 setProjectionForRotation90();
1642 expectStateForHardwareTransform270();
1643}
1644
1645TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) {
1646 setProjectionForRotation180();
1647 expectStateForHardwareTransform0();
1648}
1649
1650TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) {
1651 setProjectionForRotation270();
1652 expectStateForHardwareTransform90();
1653}
1654
1655struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest {
1656 DisplayDeviceSetProjectionTest_Installed270()
1657 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1658 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1659 ui::ROTATION_270) {}
1660};
1661
1662TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) {
1663 setProjectionForRotation0();
1664 expectStateForHardwareTransform270();
1665}
1666
1667TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) {
1668 setProjectionForRotation90();
1669 expectStateForHardwareTransform0();
1670}
1671
1672TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) {
1673 setProjectionForRotation180();
1674 expectStateForHardwareTransform90();
1675}
1676
1677TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) {
1678 setProjectionForRotation270();
1679 expectStateForHardwareTransform180();
1680}
1681
1682/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001683 * SurfaceFlinger::getDisplayNativePrimaries
1684 */
1685
1686class GetDisplayNativePrimaries : public DisplayTransactionTest {
1687public:
1688 GetDisplayNativePrimaries();
1689 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1690 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1691
1692private:
1693 static constexpr float mStartingTestValue = 1.0f;
1694};
1695
1696GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1697 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1698 injectFakeNativeWindowSurfaceFactory();
1699}
1700
1701void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1702 ui::DisplayPrimaries& primaries) {
1703 float startingVal = mStartingTestValue;
1704 primaries.red.X = startingVal++;
1705 primaries.red.Y = startingVal++;
1706 primaries.red.Z = startingVal++;
1707 primaries.green.X = startingVal++;
1708 primaries.green.Y = startingVal++;
1709 primaries.green.Z = startingVal++;
1710 primaries.blue.X = startingVal++;
1711 primaries.blue.Y = startingVal++;
1712 primaries.blue.Z = startingVal++;
1713 primaries.white.X = startingVal++;
1714 primaries.white.Y = startingVal++;
1715 primaries.white.Z = startingVal++;
1716}
1717
1718void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1719 const ui::DisplayPrimaries& primaries) {
1720 float startingVal = mStartingTestValue;
1721 EXPECT_EQ(primaries.red.X, startingVal++);
1722 EXPECT_EQ(primaries.red.Y, startingVal++);
1723 EXPECT_EQ(primaries.red.Z, startingVal++);
1724 EXPECT_EQ(primaries.green.X, startingVal++);
1725 EXPECT_EQ(primaries.green.Y, startingVal++);
1726 EXPECT_EQ(primaries.green.Z, startingVal++);
1727 EXPECT_EQ(primaries.blue.X, startingVal++);
1728 EXPECT_EQ(primaries.blue.Y, startingVal++);
1729 EXPECT_EQ(primaries.blue.Z, startingVal++);
1730 EXPECT_EQ(primaries.white.X, startingVal++);
1731 EXPECT_EQ(primaries.white.Y, startingVal++);
1732 EXPECT_EQ(primaries.white.Z, startingVal++);
1733}
1734
1735TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1736 ui::DisplayPrimaries primaries;
1737 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1738}
1739
Daniel Solomon42d04562019-01-20 21:03:19 -08001740TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1741 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1742 injector.inject();
1743 auto internalDisplayToken = injector.token();
1744
1745 ui::DisplayPrimaries expectedPrimaries;
1746 populateDummyDisplayNativePrimaries(expectedPrimaries);
1747 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1748
1749 ui::DisplayPrimaries primaries;
1750 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1751
1752 checkDummyDisplayNativePrimaries(primaries);
1753}
1754
1755TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1756 sp<BBinder> notInternalDisplayToken = new BBinder();
1757
1758 ui::DisplayPrimaries primaries;
1759 populateDummyDisplayNativePrimaries(primaries);
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001760 EXPECT_EQ(NAME_NOT_FOUND,
1761 mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
Daniel Solomon42d04562019-01-20 21:03:19 -08001762
1763 // Check primaries argument wasn't modified in case of failure
1764 checkDummyDisplayNativePrimaries(primaries);
1765}
1766
1767/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001768 * SurfaceFlinger::setupNewDisplayDeviceInternal
1769 */
1770
1771class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1772public:
1773 template <typename T>
1774 void setupNewDisplayDeviceInternalTest();
1775};
1776
1777template <typename Case>
1778void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1779 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001780 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1781 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001782 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001783
1784 // --------------------------------------------------------------------
1785 // Preconditions
1786
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001787 // Wide color displays support is configured appropriately
1788 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001789
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001790 // The display is setup with the HWC.
1791 Case::Display::injectHwcDisplay(this);
1792
1793 // SurfaceFlinger will use a test-controlled factory for native window
1794 // surfaces.
1795 injectFakeNativeWindowSurfaceFactory();
1796
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001797 // A compositionengine::Display has already been created
1798 auto compositionDisplay = Case::Display::injectCompositionDisplay(this);
1799
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001800 // --------------------------------------------------------------------
1801 // Call Expectations
1802
1803 // Various native window calls will be made.
1804 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001805 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001806 Case::WideColorSupport::setupComposerCallExpectations(this);
1807 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001808 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001809
1810 // --------------------------------------------------------------------
1811 // Invocation
1812
1813 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -08001814 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1815 const auto displayId = Case::Display::DISPLAY_ID::get();
1816 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001817 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1818 ASSERT_TRUE(hwcDisplayId);
Marin Shalamanov7ce87642020-05-06 13:45:58 +02001819 state.physical = {.id = *displayId, .type = *connectionType, .hwcDisplayId = *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001820 }
1821
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001822 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1823
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001824 auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state,
1825 displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001826
1827 // --------------------------------------------------------------------
1828 // Postconditions
1829
1830 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001831 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001832 EXPECT_EQ(Case::Display::CONNECTION_TYPE::value, device->getConnectionType());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001833 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001834 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001835 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001836 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1837 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1838 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001839 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001840 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1841 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1842 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001843 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1844 // remapped, and the test only ever sets up one config. If there were an error
1845 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
Ady Abraham2139f732019-11-13 18:56:40 -08001846 EXPECT_EQ(0, device->getActiveConfig().value());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001847 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1848 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001849}
1850
1851TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1852 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1853}
1854
1855TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1856 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1857}
1858
1859TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1860 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1861}
1862
1863TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001864 setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001865}
1866
1867TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1868 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1869}
1870
Valerie Haue9e843a2018-12-18 13:39:23 -08001871TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1872 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1873}
1874
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001875TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1876 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1877}
1878
1879TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1880 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1881}
1882
1883TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1884 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1885}
1886
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001887TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1888 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1889}
1890
1891TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1892 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1893}
1894
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001895/* ------------------------------------------------------------------------
1896 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1897 */
1898
1899class HandleTransactionLockedTest : public DisplayTransactionTest {
1900public:
1901 template <typename Case>
1902 void setupCommonPreconditions();
1903
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001904 template <typename Case, bool connected>
1905 static void expectHotplugReceived(mock::EventThread*);
1906
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001907 template <typename Case>
1908 void setupCommonCallExpectationsForConnectProcessing();
1909
1910 template <typename Case>
1911 void setupCommonCallExpectationsForDisconnectProcessing();
1912
1913 template <typename Case>
1914 void processesHotplugConnectCommon();
1915
1916 template <typename Case>
1917 void ignoresHotplugConnectCommon();
1918
1919 template <typename Case>
1920 void processesHotplugDisconnectCommon();
1921
1922 template <typename Case>
1923 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1924
1925 template <typename Case>
1926 void verifyPhysicalDisplayIsConnected();
1927
1928 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1929};
1930
1931template <typename Case>
1932void HandleTransactionLockedTest::setupCommonPreconditions() {
1933 // Wide color displays support is configured appropriately
1934 Case::WideColorSupport::injectConfigChange(this);
1935
1936 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1937 injectFakeBufferQueueFactory();
1938
1939 // SurfaceFlinger will use a test-controlled factory for native window
1940 // surfaces.
1941 injectFakeNativeWindowSurfaceFactory();
1942}
1943
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001944template <typename Case, bool connected>
1945void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1946 const auto convert = [](auto physicalDisplayId) {
1947 return std::make_optional(DisplayId{physicalDisplayId});
1948 };
1949
1950 EXPECT_CALL(*eventThread,
1951 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1952 .Times(1);
1953}
1954
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001955template <typename Case>
1956void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1957 Case::Display::setupHwcHotplugCallExpectations(this);
1958
1959 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1960 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1961 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1962 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1963
1964 Case::WideColorSupport::setupComposerCallExpectations(this);
1965 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001966 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001967
1968 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001969 expectHotplugReceived<Case, true>(mEventThread);
1970 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001971}
1972
1973template <typename Case>
1974void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1975 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001976
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001977 expectHotplugReceived<Case, false>(mEventThread);
1978 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001979}
1980
1981template <typename Case>
1982void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1983 // The display device should have been set up in the list of displays.
1984 ASSERT_TRUE(hasDisplayDevice(displayToken));
1985 const auto& device = getDisplayDevice(displayToken);
1986 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001987 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001988
Dominik Laskowski55c85402020-01-21 16:25:47 -08001989 std::optional<DisplayDeviceState::Physical> expectedPhysical;
1990 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1991 const auto displayId = Case::Display::DISPLAY_ID::get();
1992 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001993 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1994 ASSERT_TRUE(hwcDisplayId);
Marin Shalamanov7ce87642020-05-06 13:45:58 +02001995 expectedPhysical = {.id = *displayId,
1996 .type = *connectionType,
1997 .hwcDisplayId = *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001998 }
1999
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002000 // The display should have been set up in the current display state
2001 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
2002 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002003 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08002004 EXPECT_EQ(expectedPhysical, current.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002005
2006 // The display should have been set up in the drawing display state
2007 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2008 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002009 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08002010 EXPECT_EQ(expectedPhysical, draw.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002011}
2012
2013template <typename Case>
2014void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
2015 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002016 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002017
Dominik Laskowski075d3172018-05-24 15:50:06 -07002018 // SF should have a display token.
2019 const auto displayId = Case::Display::DISPLAY_ID::get();
2020 ASSERT_TRUE(displayId);
2021 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
2022 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002023
2024 verifyDisplayIsConnected<Case>(displayToken);
2025}
2026
2027void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
2028 EXPECT_FALSE(hasDisplayDevice(displayToken));
2029 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2030 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
2031}
2032
2033template <typename Case>
2034void HandleTransactionLockedTest::processesHotplugConnectCommon() {
2035 // --------------------------------------------------------------------
2036 // Preconditions
2037
2038 setupCommonPreconditions<Case>();
2039
2040 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002041 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002042
2043 // --------------------------------------------------------------------
2044 // Call Expectations
2045
2046 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002047
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002048 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002049
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002050 // --------------------------------------------------------------------
2051 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08002052
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002053 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08002054
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002055 // --------------------------------------------------------------------
2056 // Postconditions
2057
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002058 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002059
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002060 // --------------------------------------------------------------------
2061 // Cleanup conditions
2062
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002063 EXPECT_CALL(*mComposer,
2064 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002065 .WillOnce(Return(Error::NONE));
2066 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08002067}
2068
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002069template <typename Case>
2070void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
2071 // --------------------------------------------------------------------
2072 // Preconditions
2073
2074 setupCommonPreconditions<Case>();
2075
2076 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002077 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002078
2079 // --------------------------------------------------------------------
2080 // Invocation
2081
2082 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2083
2084 // --------------------------------------------------------------------
2085 // Postconditions
2086
2087 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002088 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002089}
2090
2091template <typename Case>
2092void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
2093 // --------------------------------------------------------------------
2094 // Preconditions
2095
2096 setupCommonPreconditions<Case>();
2097
2098 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002099 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002100
2101 // The display is already completely set up.
2102 Case::Display::injectHwcDisplay(this);
2103 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2104 existing.inject();
2105
2106 // --------------------------------------------------------------------
2107 // Call Expectations
2108
2109 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07002110 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
2111 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002112
2113 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2114
2115 // --------------------------------------------------------------------
2116 // Invocation
2117
2118 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2119
2120 // --------------------------------------------------------------------
2121 // Postconditions
2122
2123 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002124 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002125
Dominik Laskowski075d3172018-05-24 15:50:06 -07002126 // SF should not have a display token.
2127 const auto displayId = Case::Display::DISPLAY_ID::get();
2128 ASSERT_TRUE(displayId);
2129 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002130
2131 // The existing token should have been removed
2132 verifyDisplayIsNotConnected(existing.token());
2133}
2134
2135TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
2136 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2137}
2138
2139TEST_F(HandleTransactionLockedTest,
2140 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
2141 // Inject an external display.
2142 ExternalDisplayVariant::injectHwcDisplay(this);
2143
2144 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2145}
2146
2147TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
2148 // Inject a primary display.
2149 PrimaryDisplayVariant::injectHwcDisplay(this);
2150
2151 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
2152}
2153
2154TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
2155 // Inject both a primary and external display.
2156 PrimaryDisplayVariant::injectHwcDisplay(this);
2157 ExternalDisplayVariant::injectHwcDisplay(this);
2158
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002159 // TODO: This is an unnecessary call.
2160 EXPECT_CALL(*mComposer,
2161 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
2162 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
2163 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
2164 Return(Error::NONE)));
2165
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002166 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2167
2168 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
2169}
2170
2171TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
2172 // Inject a primary display.
2173 PrimaryDisplayVariant::injectHwcDisplay(this);
2174
2175 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
2176
2177 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
2178}
2179
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002180TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectPrimaryDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002181 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
2182}
2183
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002184TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectExternalDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002185 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
2186}
2187
2188TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
2189 using Case = SimplePrimaryDisplayCase;
2190
2191 // --------------------------------------------------------------------
2192 // Preconditions
2193
2194 setupCommonPreconditions<Case>();
2195
2196 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002197 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002198 // A hotplug disconnect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002199 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002200
2201 // --------------------------------------------------------------------
2202 // Call Expectations
2203
2204 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2205
2206 setupCommonCallExpectationsForConnectProcessing<Case>();
2207 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2208
2209 EXPECT_CALL(*mComposer,
2210 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2211 .WillOnce(Return(Error::NONE));
2212 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2213
2214 // --------------------------------------------------------------------
2215 // Invocation
2216
2217 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2218
2219 // --------------------------------------------------------------------
2220 // Postconditions
2221
2222 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002223 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002224
Dominik Laskowski075d3172018-05-24 15:50:06 -07002225 // SF should not have a display token.
2226 const auto displayId = Case::Display::DISPLAY_ID::get();
2227 ASSERT_TRUE(displayId);
2228 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002229}
2230
2231TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
2232 using Case = SimplePrimaryDisplayCase;
2233
2234 // --------------------------------------------------------------------
2235 // Preconditions
2236
2237 setupCommonPreconditions<Case>();
2238
2239 // The display is already completely set up.
2240 Case::Display::injectHwcDisplay(this);
2241 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2242 existing.inject();
2243
2244 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002245 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002246 // A hotplug connect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002247 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002248
2249 // --------------------------------------------------------------------
2250 // Call Expectations
2251
2252 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2253
2254 setupCommonCallExpectationsForConnectProcessing<Case>();
2255 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2256
2257 // --------------------------------------------------------------------
2258 // Invocation
2259
2260 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2261
2262 // --------------------------------------------------------------------
2263 // Postconditions
2264
2265 // The existing token should have been removed
2266 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07002267 const auto displayId = Case::Display::DISPLAY_ID::get();
2268 ASSERT_TRUE(displayId);
2269 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
2270 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002271
2272 // A new display should be connected in its place
2273
2274 verifyPhysicalDisplayIsConnected<Case>();
2275
2276 // --------------------------------------------------------------------
2277 // Cleanup conditions
2278
2279 EXPECT_CALL(*mComposer,
2280 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2281 .WillOnce(Return(Error::NONE));
2282 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2283}
2284
2285TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
2286 using Case = HwcVirtualDisplayCase;
2287
2288 // --------------------------------------------------------------------
2289 // Preconditions
2290
2291 // The HWC supports at least one virtual display
2292 injectMockComposer(1);
2293
2294 setupCommonPreconditions<Case>();
2295
2296 // A virtual display was added to the current state, and it has a
2297 // surface(producer)
2298 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07002299
Dominik Laskowski075d3172018-05-24 15:50:06 -07002300 DisplayDeviceState state;
2301 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002302
2303 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07002304 state.surface = surface;
2305 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002306
2307 // --------------------------------------------------------------------
2308 // Call Expectations
2309
2310 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
2311 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
2312
2313 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
2314 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
2315 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
2316 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
2317 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
2318 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
2319 Return(NO_ERROR)));
2320 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
2321 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
2322
2323 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
2324
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002325 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002326 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
2327
2328 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
2329 Case::WideColorSupport::setupComposerCallExpectations(this);
2330 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07002331 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002332
2333 // --------------------------------------------------------------------
2334 // Invocation
2335
2336 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2337
2338 // --------------------------------------------------------------------
2339 // Postconditions
2340
2341 // The display device should have been set up in the list of displays.
2342 verifyDisplayIsConnected<Case>(displayToken);
2343
2344 // --------------------------------------------------------------------
2345 // Cleanup conditions
2346
2347 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
2348 .WillOnce(Return(Error::NONE));
2349 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08002350
2351 // Cleanup
2352 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
2353 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002354}
2355
2356TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
2357 using Case = HwcVirtualDisplayCase;
2358
2359 // --------------------------------------------------------------------
2360 // Preconditions
2361
2362 // The HWC supports at least one virtual display
2363 injectMockComposer(1);
2364
2365 setupCommonPreconditions<Case>();
2366
2367 // A virtual display was added to the current state, but it does not have a
2368 // surface.
2369 sp<BBinder> displayToken = new BBinder();
2370
Dominik Laskowski075d3172018-05-24 15:50:06 -07002371 DisplayDeviceState state;
2372 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002373
Dominik Laskowski075d3172018-05-24 15:50:06 -07002374 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002375
2376 // --------------------------------------------------------------------
2377 // Call Expectations
2378
2379 // --------------------------------------------------------------------
2380 // Invocation
2381
2382 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2383
2384 // --------------------------------------------------------------------
2385 // Postconditions
2386
2387 // There will not be a display device set up.
2388 EXPECT_FALSE(hasDisplayDevice(displayToken));
2389
2390 // The drawing display state will be set from the current display state.
2391 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2392 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002393 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002394}
2395
2396TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
2397 using Case = HwcVirtualDisplayCase;
2398
2399 // --------------------------------------------------------------------
2400 // Preconditions
2401
2402 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002403 const auto displayId = Case::Display::DISPLAY_ID::get();
2404 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08002405 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002406 Case::Display::injectHwcDisplay(this);
2407 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2408 existing.inject();
2409 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2410
2411 // --------------------------------------------------------------------
2412 // Call Expectations
2413
2414 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2415
2416 // --------------------------------------------------------------------
2417 // Invocation
2418
2419 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2420
2421 // --------------------------------------------------------------------
2422 // Postconditions
2423
2424 // The existing token should have been removed
2425 verifyDisplayIsNotConnected(existing.token());
2426}
2427
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002428TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2429 using Case = NonHwcVirtualDisplayCase;
2430
2431 constexpr uint32_t oldLayerStack = 0u;
2432 constexpr uint32_t newLayerStack = 123u;
2433
2434 // --------------------------------------------------------------------
2435 // Preconditions
2436
2437 // A display is set up
2438 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2439 display.inject();
2440
2441 // There is a change to the layerStack state
2442 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2443 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2444
2445 // --------------------------------------------------------------------
2446 // Invocation
2447
2448 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2449
2450 // --------------------------------------------------------------------
2451 // Postconditions
2452
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002453 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002454}
2455
2456TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2457 using Case = NonHwcVirtualDisplayCase;
2458
Dominik Laskowski718f9602019-11-09 20:01:35 -08002459 constexpr ui::Rotation oldTransform = ui::ROTATION_0;
2460 constexpr ui::Rotation newTransform = ui::ROTATION_180;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002461
2462 // --------------------------------------------------------------------
2463 // Preconditions
2464
2465 // A display is set up
2466 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2467 display.inject();
2468
2469 // There is a change to the orientation state
2470 display.mutableDrawingDisplayState().orientation = oldTransform;
2471 display.mutableCurrentDisplayState().orientation = newTransform;
2472
2473 // --------------------------------------------------------------------
2474 // Invocation
2475
2476 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2477
2478 // --------------------------------------------------------------------
2479 // Postconditions
2480
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002481 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002482}
2483
2484TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2485 using Case = NonHwcVirtualDisplayCase;
2486
2487 const Rect oldViewport(0, 0, 0, 0);
2488 const Rect newViewport(0, 0, 123, 456);
2489
2490 // --------------------------------------------------------------------
2491 // Preconditions
2492
2493 // A display is set up
2494 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2495 display.inject();
2496
2497 // There is a change to the viewport state
2498 display.mutableDrawingDisplayState().viewport = oldViewport;
2499 display.mutableCurrentDisplayState().viewport = newViewport;
2500
2501 // --------------------------------------------------------------------
2502 // Invocation
2503
2504 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2505
2506 // --------------------------------------------------------------------
2507 // Postconditions
2508
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002509 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002510}
2511
2512TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2513 using Case = NonHwcVirtualDisplayCase;
2514
2515 const Rect oldFrame(0, 0, 0, 0);
2516 const Rect newFrame(0, 0, 123, 456);
2517
2518 // --------------------------------------------------------------------
2519 // Preconditions
2520
2521 // A display is set up
2522 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2523 display.inject();
2524
2525 // There is a change to the viewport state
2526 display.mutableDrawingDisplayState().frame = oldFrame;
2527 display.mutableCurrentDisplayState().frame = newFrame;
2528
2529 // --------------------------------------------------------------------
2530 // Invocation
2531
2532 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2533
2534 // --------------------------------------------------------------------
2535 // Postconditions
2536
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002537 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002538}
2539
2540TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2541 using Case = NonHwcVirtualDisplayCase;
2542
2543 constexpr int oldWidth = 0;
2544 constexpr int oldHeight = 10;
2545 constexpr int newWidth = 123;
2546
2547 // --------------------------------------------------------------------
2548 // Preconditions
2549
2550 // A display is set up
2551 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002552 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002553 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002554 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2555 display.setNativeWindow(nativeWindow);
2556 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002557 // Setup injection expections
2558 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2559 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2560 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2561 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002562 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2563 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2564 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002565 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002566 display.inject();
2567
2568 // There is a change to the viewport state
2569 display.mutableDrawingDisplayState().width = oldWidth;
2570 display.mutableDrawingDisplayState().height = oldHeight;
2571 display.mutableCurrentDisplayState().width = newWidth;
2572 display.mutableCurrentDisplayState().height = oldHeight;
2573
2574 // --------------------------------------------------------------------
2575 // Call Expectations
2576
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002577 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002578
2579 // --------------------------------------------------------------------
2580 // Invocation
2581
2582 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2583}
2584
2585TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2586 using Case = NonHwcVirtualDisplayCase;
2587
2588 constexpr int oldWidth = 0;
2589 constexpr int oldHeight = 10;
2590 constexpr int newHeight = 123;
2591
2592 // --------------------------------------------------------------------
2593 // Preconditions
2594
2595 // A display is set up
2596 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002597 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002598 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002599 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2600 display.setNativeWindow(nativeWindow);
2601 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002602 // Setup injection expections
2603 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2604 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2605 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2606 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002607 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2608 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2609 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002610 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002611 display.inject();
2612
2613 // There is a change to the viewport state
2614 display.mutableDrawingDisplayState().width = oldWidth;
2615 display.mutableDrawingDisplayState().height = oldHeight;
2616 display.mutableCurrentDisplayState().width = oldWidth;
2617 display.mutableCurrentDisplayState().height = newHeight;
2618
2619 // --------------------------------------------------------------------
2620 // Call Expectations
2621
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002622 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002623
2624 // --------------------------------------------------------------------
2625 // Invocation
2626
2627 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2628}
2629
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002630/* ------------------------------------------------------------------------
2631 * SurfaceFlinger::setDisplayStateLocked
2632 */
2633
2634TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2635 // --------------------------------------------------------------------
2636 // Preconditions
2637
2638 // We have an unknown display token not associated with a known display
2639 sp<BBinder> displayToken = new BBinder();
2640
2641 // The requested display state references the unknown display.
2642 DisplayState state;
2643 state.what = DisplayState::eLayerStackChanged;
2644 state.token = displayToken;
2645 state.layerStack = 456;
2646
2647 // --------------------------------------------------------------------
2648 // Invocation
2649
2650 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2651
2652 // --------------------------------------------------------------------
2653 // Postconditions
2654
2655 // The returned flags are empty
2656 EXPECT_EQ(0u, flags);
2657
2658 // The display token still doesn't match anything known.
2659 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2660}
2661
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002662TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2663 using Case = SimplePrimaryDisplayCase;
2664
2665 // --------------------------------------------------------------------
2666 // Preconditions
2667
2668 // A display is already set up
2669 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2670 display.inject();
2671
2672 // No changes are made to the display
2673 DisplayState state;
2674 state.what = 0;
2675 state.token = display.token();
2676
2677 // --------------------------------------------------------------------
2678 // Invocation
2679
2680 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2681
2682 // --------------------------------------------------------------------
2683 // Postconditions
2684
2685 // The returned flags are empty
2686 EXPECT_EQ(0u, flags);
2687}
2688
2689TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2690 using Case = SimplePrimaryDisplayCase;
2691
2692 // --------------------------------------------------------------------
2693 // Preconditions
2694
2695 // A display is already set up
2696 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2697 display.inject();
2698
2699 // There is a surface that can be set.
2700 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2701
2702 // The current display state has the surface set
2703 display.mutableCurrentDisplayState().surface = surface;
2704
2705 // The incoming request sets the same surface
2706 DisplayState state;
2707 state.what = DisplayState::eSurfaceChanged;
2708 state.token = display.token();
2709 state.surface = surface;
2710
2711 // --------------------------------------------------------------------
2712 // Invocation
2713
2714 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2715
2716 // --------------------------------------------------------------------
2717 // Postconditions
2718
2719 // The returned flags are empty
2720 EXPECT_EQ(0u, flags);
2721
2722 // The current display state is unchanged.
2723 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2724}
2725
2726TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2727 using Case = SimplePrimaryDisplayCase;
2728
2729 // --------------------------------------------------------------------
2730 // Preconditions
2731
2732 // A display is already set up
2733 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2734 display.inject();
2735
2736 // There is a surface that can be set.
2737 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2738
2739 // The current display state does not have a surface
2740 display.mutableCurrentDisplayState().surface = nullptr;
2741
2742 // The incoming request sets a surface
2743 DisplayState state;
2744 state.what = DisplayState::eSurfaceChanged;
2745 state.token = display.token();
2746 state.surface = surface;
2747
2748 // --------------------------------------------------------------------
2749 // Invocation
2750
2751 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2752
2753 // --------------------------------------------------------------------
2754 // Postconditions
2755
2756 // The returned flags indicate a transaction is needed
2757 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2758
2759 // The current display layer stack state is set to the new value
2760 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2761}
2762
2763TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2764 using Case = SimplePrimaryDisplayCase;
2765
2766 // --------------------------------------------------------------------
2767 // Preconditions
2768
2769 // A display is already set up
2770 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2771 display.inject();
2772
2773 // The display has a layer stack set
2774 display.mutableCurrentDisplayState().layerStack = 456u;
2775
2776 // The incoming request sets the same layer stack
2777 DisplayState state;
2778 state.what = DisplayState::eLayerStackChanged;
2779 state.token = display.token();
2780 state.layerStack = 456u;
2781
2782 // --------------------------------------------------------------------
2783 // Invocation
2784
2785 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2786
2787 // --------------------------------------------------------------------
2788 // Postconditions
2789
2790 // The returned flags are empty
2791 EXPECT_EQ(0u, flags);
2792
2793 // The current display state is unchanged
2794 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2795}
2796
2797TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2798 using Case = SimplePrimaryDisplayCase;
2799
2800 // --------------------------------------------------------------------
2801 // Preconditions
2802
2803 // A display is set up
2804 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2805 display.inject();
2806
2807 // The display has a layer stack set
2808 display.mutableCurrentDisplayState().layerStack = 654u;
2809
2810 // The incoming request sets a different layer stack
2811 DisplayState state;
2812 state.what = DisplayState::eLayerStackChanged;
2813 state.token = display.token();
2814 state.layerStack = 456u;
2815
2816 // --------------------------------------------------------------------
2817 // Invocation
2818
2819 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2820
2821 // --------------------------------------------------------------------
2822 // Postconditions
2823
2824 // The returned flags indicate a transaction is needed
2825 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2826
2827 // The desired display state has been set to the new value.
2828 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2829}
2830
2831TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2832 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002833 constexpr ui::Rotation initialOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002834 const Rect initialFrame = {1, 2, 3, 4};
2835 const Rect initialViewport = {5, 6, 7, 8};
2836
2837 // --------------------------------------------------------------------
2838 // Preconditions
2839
2840 // A display is set up
2841 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2842 display.inject();
2843
2844 // The current display state projection state is all set
2845 display.mutableCurrentDisplayState().orientation = initialOrientation;
2846 display.mutableCurrentDisplayState().frame = initialFrame;
2847 display.mutableCurrentDisplayState().viewport = initialViewport;
2848
2849 // The incoming request sets the same projection state
2850 DisplayState state;
2851 state.what = DisplayState::eDisplayProjectionChanged;
2852 state.token = display.token();
2853 state.orientation = initialOrientation;
2854 state.frame = initialFrame;
2855 state.viewport = initialViewport;
2856
2857 // --------------------------------------------------------------------
2858 // Invocation
2859
2860 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2861
2862 // --------------------------------------------------------------------
2863 // Postconditions
2864
2865 // The returned flags are empty
2866 EXPECT_EQ(0u, flags);
2867
2868 // The current display state is unchanged
2869 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2870
2871 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2872 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2873}
2874
2875TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2876 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002877 constexpr ui::Rotation initialOrientation = ui::ROTATION_90;
2878 constexpr ui::Rotation desiredOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002879
2880 // --------------------------------------------------------------------
2881 // Preconditions
2882
2883 // A display is set up
2884 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2885 display.inject();
2886
2887 // The current display state has an orientation set
2888 display.mutableCurrentDisplayState().orientation = initialOrientation;
2889
2890 // The incoming request sets a different orientation
2891 DisplayState state;
2892 state.what = DisplayState::eDisplayProjectionChanged;
2893 state.token = display.token();
2894 state.orientation = desiredOrientation;
2895
2896 // --------------------------------------------------------------------
2897 // Invocation
2898
2899 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2900
2901 // --------------------------------------------------------------------
2902 // Postconditions
2903
2904 // The returned flags indicate a transaction is needed
2905 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2906
2907 // The current display state has the new value.
2908 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2909}
2910
2911TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2912 using Case = SimplePrimaryDisplayCase;
2913 const Rect initialFrame = {0, 0, 0, 0};
2914 const Rect desiredFrame = {5, 6, 7, 8};
2915
2916 // --------------------------------------------------------------------
2917 // Preconditions
2918
2919 // A display is set up
2920 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2921 display.inject();
2922
2923 // The current display state does not have a frame
2924 display.mutableCurrentDisplayState().frame = initialFrame;
2925
2926 // The incoming request sets a frame
2927 DisplayState state;
2928 state.what = DisplayState::eDisplayProjectionChanged;
2929 state.token = display.token();
2930 state.frame = desiredFrame;
2931
2932 // --------------------------------------------------------------------
2933 // Invocation
2934
2935 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2936
2937 // --------------------------------------------------------------------
2938 // Postconditions
2939
2940 // The returned flags indicate a transaction is needed
2941 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2942
2943 // The current display state has the new value.
2944 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2945}
2946
2947TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2948 using Case = SimplePrimaryDisplayCase;
2949 const Rect initialViewport = {0, 0, 0, 0};
2950 const Rect desiredViewport = {5, 6, 7, 8};
2951
2952 // --------------------------------------------------------------------
2953 // Preconditions
2954
2955 // A display is set up
2956 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2957 display.inject();
2958
2959 // The current display state does not have a viewport
2960 display.mutableCurrentDisplayState().viewport = initialViewport;
2961
2962 // The incoming request sets a viewport
2963 DisplayState state;
2964 state.what = DisplayState::eDisplayProjectionChanged;
2965 state.token = display.token();
2966 state.viewport = desiredViewport;
2967
2968 // --------------------------------------------------------------------
2969 // Invocation
2970
2971 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2972
2973 // --------------------------------------------------------------------
2974 // Postconditions
2975
2976 // The returned flags indicate a transaction is needed
2977 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2978
2979 // The current display state has the new value.
2980 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2981}
2982
2983TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2984 using Case = SimplePrimaryDisplayCase;
2985 constexpr uint32_t initialWidth = 1024;
2986 constexpr uint32_t initialHeight = 768;
2987
2988 // --------------------------------------------------------------------
2989 // Preconditions
2990
2991 // A display is set up
2992 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2993 display.inject();
2994
2995 // The current display state has a size set
2996 display.mutableCurrentDisplayState().width = initialWidth;
2997 display.mutableCurrentDisplayState().height = initialHeight;
2998
2999 // The incoming request sets the same display size
3000 DisplayState state;
3001 state.what = DisplayState::eDisplaySizeChanged;
3002 state.token = display.token();
3003 state.width = initialWidth;
3004 state.height = initialHeight;
3005
3006 // --------------------------------------------------------------------
3007 // Invocation
3008
3009 uint32_t flags = mFlinger.setDisplayStateLocked(state);
3010
3011 // --------------------------------------------------------------------
3012 // Postconditions
3013
3014 // The returned flags are empty
3015 EXPECT_EQ(0u, flags);
3016
3017 // The current display state is unchanged
3018 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
3019 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
3020}
3021
3022TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
3023 using Case = SimplePrimaryDisplayCase;
3024 constexpr uint32_t initialWidth = 0;
3025 constexpr uint32_t desiredWidth = 1024;
3026
3027 // --------------------------------------------------------------------
3028 // Preconditions
3029
3030 // A display is set up
3031 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3032 display.inject();
3033
3034 // The display does not yet have a width
3035 display.mutableCurrentDisplayState().width = initialWidth;
3036
3037 // The incoming request sets a display width
3038 DisplayState state;
3039 state.what = DisplayState::eDisplaySizeChanged;
3040 state.token = display.token();
3041 state.width = desiredWidth;
3042
3043 // --------------------------------------------------------------------
3044 // Invocation
3045
3046 uint32_t flags = mFlinger.setDisplayStateLocked(state);
3047
3048 // --------------------------------------------------------------------
3049 // Postconditions
3050
3051 // The returned flags indicate a transaction is needed
3052 EXPECT_EQ(eDisplayTransactionNeeded, flags);
3053
3054 // The current display state has the new value.
3055 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
3056}
3057
3058TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
3059 using Case = SimplePrimaryDisplayCase;
3060 constexpr uint32_t initialHeight = 0;
3061 constexpr uint32_t desiredHeight = 768;
3062
3063 // --------------------------------------------------------------------
3064 // Preconditions
3065
3066 // A display is set up
3067 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3068 display.inject();
3069
3070 // The display does not yet have a height
3071 display.mutableCurrentDisplayState().height = initialHeight;
3072
3073 // The incoming request sets a display height
3074 DisplayState state;
3075 state.what = DisplayState::eDisplaySizeChanged;
3076 state.token = display.token();
3077 state.height = desiredHeight;
3078
3079 // --------------------------------------------------------------------
3080 // Invocation
3081
3082 uint32_t flags = mFlinger.setDisplayStateLocked(state);
3083
3084 // --------------------------------------------------------------------
3085 // Postconditions
3086
3087 // The returned flags indicate a transaction is needed
3088 EXPECT_EQ(eDisplayTransactionNeeded, flags);
3089
3090 // The current display state has the new value.
3091 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
3092}
3093
Lloyd Pique86016da2018-03-01 16:09:38 -08003094/* ------------------------------------------------------------------------
3095 * SurfaceFlinger::onInitializeDisplays
3096 */
3097
3098TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
3099 using Case = SimplePrimaryDisplayCase;
3100
3101 // --------------------------------------------------------------------
3102 // Preconditions
3103
3104 // A primary display is set up
3105 Case::Display::injectHwcDisplay(this);
3106 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
3107 primaryDisplay.inject();
3108
3109 // --------------------------------------------------------------------
3110 // Call Expectations
3111
3112 // We expect the surface interceptor to possibly be used, but we treat it as
3113 // disabled since it is called as a side effect rather than directly by this
3114 // function.
3115 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
3116
3117 // We expect a call to get the active display config.
3118 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
3119
3120 // We expect invalidate() to be invoked once to trigger display transaction
3121 // processing.
3122 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
3123
Ady Abraham0ed31c92020-04-16 11:48:45 -07003124 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime(_)).WillRepeatedly(Return(0));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003125
Lloyd Pique86016da2018-03-01 16:09:38 -08003126 // --------------------------------------------------------------------
3127 // Invocation
3128
3129 mFlinger.onInitializeDisplays();
3130
3131 // --------------------------------------------------------------------
3132 // Postconditions
3133
3134 // The primary display should have a current state
3135 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
3136 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
3137 // The layer stack state should be set to zero
3138 EXPECT_EQ(0u, primaryDisplayState.layerStack);
3139 // The orientation state should be set to zero
Dominik Laskowski718f9602019-11-09 20:01:35 -08003140 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
Lloyd Pique86016da2018-03-01 16:09:38 -08003141
3142 // The frame state should be set to INVALID
3143 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
3144
3145 // The viewport state should be set to INVALID
3146 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
3147
3148 // The width and height should both be zero
3149 EXPECT_EQ(0u, primaryDisplayState.width);
3150 EXPECT_EQ(0u, primaryDisplayState.height);
3151
Peiyong Lin65248e02020-04-18 21:15:07 -07003152 // The display should be set to PowerMode::ON
Lloyd Pique86016da2018-03-01 16:09:38 -08003153 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
3154 auto displayDevice = primaryDisplay.mutableDisplayDevice();
Peiyong Lin65248e02020-04-18 21:15:07 -07003155 EXPECT_EQ(PowerMode::ON, displayDevice->getPowerMode());
Lloyd Pique86016da2018-03-01 16:09:38 -08003156
3157 // The display refresh period should be set in the frame tracker.
3158 FrameStats stats;
3159 mFlinger.getAnimFrameTracker().getStats(&stats);
3160 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
3161
3162 // The display transaction needed flag should be set.
3163 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
3164
3165 // The compositor timing should be set to default values
3166 const auto& compositorTiming = mFlinger.getCompositorTiming();
3167 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
3168 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
3169 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
3170}
3171
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003172/* ------------------------------------------------------------------------
3173 * SurfaceFlinger::setPowerModeInternal
3174 */
3175
3176// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07003177template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003178struct DozeIsSupportedVariant {
3179 static constexpr bool DOZE_SUPPORTED = true;
3180 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3181 IComposerClient::PowerMode::DOZE;
3182 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3183 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07003184
3185 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3186 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003187 .WillOnce(DoAll(SetArgPointee<1>(
3188 std::vector<DisplayCapability>({DisplayCapability::DOZE})),
Peiyong Lined531a32018-10-26 18:27:56 -07003189 Return(Error::NONE)));
3190 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003191};
3192
Peiyong Lined531a32018-10-26 18:27:56 -07003193template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003194// Used when we simulate a display that does not support doze.
3195struct DozeNotSupportedVariant {
3196 static constexpr bool DOZE_SUPPORTED = false;
3197 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3198 IComposerClient::PowerMode::ON;
3199 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3200 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07003201
3202 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3203 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003204 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Peiyong Lined531a32018-10-26 18:27:56 -07003205 Return(Error::NONE)));
3206 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003207};
3208
3209struct EventThreadBaseSupportedVariant {
3210 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
3211 // The event control thread should not be notified.
3212 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
3213
3214 // The event thread should not be notified.
3215 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
3216 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
3217 }
3218};
3219
3220struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
3221 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3222 // These calls are only expected for the primary display.
3223
3224 // Instead expect no calls.
3225 setupEventAndEventControlThreadNoCallExpectations(test);
3226 }
3227
3228 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3229 // These calls are only expected for the primary display.
3230
3231 // Instead expect no calls.
3232 setupEventAndEventControlThreadNoCallExpectations(test);
3233 }
3234};
3235
3236struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
3237 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3238 // The event control thread should be notified to enable vsyncs
3239 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
3240
3241 // The event thread should be notified that the screen was acquired.
3242 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
3243 }
3244
3245 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3246 // There should be a call to setVsyncEnabled(false)
3247 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
3248
3249 // The event thread should not be notified that the screen was released.
3250 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
3251 }
3252};
3253
Lloyd Pique41be5d22018-06-21 13:11:48 -07003254struct DispSyncIsSupportedVariant {
3255 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique41be5d22018-06-21 13:11:48 -07003256 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
3257 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
3258 }
3259
3260 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
3261 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
3262 }
3263};
3264
3265struct DispSyncNotSupportedVariant {
3266 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3267
3268 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3269};
3270
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003271// --------------------------------------------------------------------
3272// Note:
3273//
3274// There are a large number of transitions we could test, however we only test a
3275// selected subset which provides complete test coverage of the implementation.
3276// --------------------------------------------------------------------
3277
Peiyong Lin65248e02020-04-18 21:15:07 -07003278template <PowerMode initialPowerMode, PowerMode targetPowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003279struct TransitionVariantCommon {
3280 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
3281 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
3282
3283 static void verifyPostconditions(DisplayTransactionTest*) {}
3284};
3285
Peiyong Lin65248e02020-04-18 21:15:07 -07003286struct TransitionOffToOnVariant : public TransitionVariantCommon<PowerMode::OFF, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003287 template <typename Case>
3288 static void setupCallExpectations(DisplayTransactionTest* test) {
3289 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3290 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003291 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003292 Case::setupRepaintEverythingCallExpectations(test);
3293 }
3294
3295 static void verifyPostconditions(DisplayTransactionTest* test) {
3296 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3297 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3298 }
3299};
3300
3301struct TransitionOffToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003302 : public TransitionVariantCommon<PowerMode::OFF, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003303 template <typename Case>
3304 static void setupCallExpectations(DisplayTransactionTest* test) {
3305 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3306 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3307 Case::setupRepaintEverythingCallExpectations(test);
3308 }
3309
3310 static void verifyPostconditions(DisplayTransactionTest* test) {
3311 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3312 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3313 }
3314};
3315
Peiyong Lin65248e02020-04-18 21:15:07 -07003316struct TransitionOnToOffVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003317 template <typename Case>
3318 static void setupCallExpectations(DisplayTransactionTest* test) {
3319 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003320 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003321 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3322 }
3323
3324 static void verifyPostconditions(DisplayTransactionTest* test) {
3325 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3326 }
3327};
3328
3329struct TransitionDozeSuspendToOffVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003330 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003331 template <typename Case>
3332 static void setupCallExpectations(DisplayTransactionTest* test) {
3333 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3334 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3335 }
3336
3337 static void verifyPostconditions(DisplayTransactionTest* test) {
3338 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3339 }
3340};
3341
Peiyong Lin65248e02020-04-18 21:15:07 -07003342struct TransitionOnToDozeVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003343 template <typename Case>
3344 static void setupCallExpectations(DisplayTransactionTest* test) {
3345 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3346 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3347 }
3348};
3349
3350struct TransitionDozeSuspendToDozeVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003351 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003352 template <typename Case>
3353 static void setupCallExpectations(DisplayTransactionTest* test) {
3354 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003355 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003356 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3357 }
3358};
3359
Peiyong Lin65248e02020-04-18 21:15:07 -07003360struct TransitionDozeToOnVariant : public TransitionVariantCommon<PowerMode::DOZE, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003361 template <typename Case>
3362 static void setupCallExpectations(DisplayTransactionTest* test) {
3363 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3364 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3365 }
3366};
3367
3368struct TransitionDozeSuspendToOnVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003369 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003370 template <typename Case>
3371 static void setupCallExpectations(DisplayTransactionTest* test) {
3372 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003373 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003374 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3375 }
3376};
3377
3378struct TransitionOnToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003379 : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003380 template <typename Case>
3381 static void setupCallExpectations(DisplayTransactionTest* test) {
3382 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003383 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003384 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3385 }
3386};
3387
3388struct TransitionOnToUnknownVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003389 : public TransitionVariantCommon<PowerMode::ON, static_cast<PowerMode>(POWER_MODE_LEET)> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003390 template <typename Case>
3391 static void setupCallExpectations(DisplayTransactionTest* test) {
3392 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3393 Case::setupNoComposerPowerModeCallExpectations(test);
3394 }
3395};
3396
3397// --------------------------------------------------------------------
3398// Note:
3399//
3400// Rather than testing the cartesian product of of
3401// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3402// display type, and the other for another display type.
3403// --------------------------------------------------------------------
3404
3405template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003406 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003407struct DisplayPowerCase {
3408 using Display = DisplayVariant;
3409 using Doze = DozeVariant;
3410 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003411 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003412 using Transition = TransitionVariant;
3413
Peiyong Lin65248e02020-04-18 21:15:07 -07003414 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003415 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003416 auto display = Display::makeFakeExistingDisplayInjector(test);
3417 display.inject();
3418 display.mutableDisplayDevice()->setPowerMode(mode);
3419 return display;
3420 }
3421
3422 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003423 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003424 }
3425
3426 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3427 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3428 }
3429
Peiyong Lin65248e02020-04-18 21:15:07 -07003430 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test,
3431 PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003432 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
Peiyong Lin65248e02020-04-18 21:15:07 -07003433 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, static_cast<int32_t>(mode)))
3434 .Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003435 }
3436
Peiyong Lin65248e02020-04-18 21:15:07 -07003437 static void setupComposerCallExpectations(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003438 // Any calls to get the active config will return a default value.
3439 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3440 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3441 Return(Error::NONE)));
3442
3443 // Any calls to get whether the display supports dozing will return the value set by the
3444 // policy variant.
3445 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3446 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3447
3448 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3449 }
3450
3451 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3452 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3453 }
3454};
3455
3456// A sample configuration for the primary display.
3457// In addition to having event thread support, we emulate doze support.
3458template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003459using PrimaryDisplayPowerCase =
3460 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3461 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3462 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003463
3464// A sample configuration for the external display.
3465// In addition to not having event thread support, we emulate not having doze
3466// support.
3467template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003468using ExternalDisplayPowerCase =
3469 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3470 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3471 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003472
3473class SetPowerModeInternalTest : public DisplayTransactionTest {
3474public:
3475 template <typename Case>
3476 void transitionDisplayCommon();
3477};
3478
Peiyong Lin65248e02020-04-18 21:15:07 -07003479template <PowerMode PowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003480struct PowerModeInitialVSyncEnabled : public std::false_type {};
3481
3482template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003483struct PowerModeInitialVSyncEnabled<PowerMode::ON> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003484
3485template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003486struct PowerModeInitialVSyncEnabled<PowerMode::DOZE> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003487
3488template <typename Case>
3489void SetPowerModeInternalTest::transitionDisplayCommon() {
3490 // --------------------------------------------------------------------
3491 // Preconditions
3492
Peiyong Lined531a32018-10-26 18:27:56 -07003493 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003494 auto display =
3495 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3496 Case::setInitialPrimaryHWVsyncEnabled(this,
3497 PowerModeInitialVSyncEnabled<
3498 Case::Transition::INITIAL_POWER_MODE>::value);
3499
3500 // --------------------------------------------------------------------
3501 // Call Expectations
3502
3503 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3504 Case::Transition::template setupCallExpectations<Case>(this);
3505
3506 // --------------------------------------------------------------------
3507 // Invocation
3508
3509 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3510 Case::Transition::TARGET_POWER_MODE);
3511
3512 // --------------------------------------------------------------------
3513 // Postconditions
3514
3515 Case::Transition::verifyPostconditions(this);
3516}
3517
3518TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3519 using Case = SimplePrimaryDisplayCase;
3520
3521 // --------------------------------------------------------------------
3522 // Preconditions
3523
3524 // A primary display device is set up
3525 Case::Display::injectHwcDisplay(this);
3526 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3527 display.inject();
3528
Peiyong Lin65248e02020-04-18 21:15:07 -07003529 // The display is already set to PowerMode::ON
3530 display.mutableDisplayDevice()->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003531
3532 // --------------------------------------------------------------------
3533 // Invocation
3534
Peiyong Lin65248e02020-04-18 21:15:07 -07003535 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003536
3537 // --------------------------------------------------------------------
3538 // Postconditions
3539
Peiyong Lin65248e02020-04-18 21:15:07 -07003540 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003541}
3542
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003543TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003544 using Case = HwcVirtualDisplayCase;
3545
3546 // --------------------------------------------------------------------
3547 // Preconditions
3548
Dominik Laskowski075d3172018-05-24 15:50:06 -07003549 // Insert display data so that the HWC thinks it created the virtual display.
3550 const auto displayId = Case::Display::DISPLAY_ID::get();
3551 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003552 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003553
3554 // A virtual display device is set up
3555 Case::Display::injectHwcDisplay(this);
3556 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3557 display.inject();
3558
Peiyong Lin65248e02020-04-18 21:15:07 -07003559 // The display is set to PowerMode::ON
3560 getDisplayDevice(display.token())->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003561
3562 // --------------------------------------------------------------------
3563 // Invocation
3564
Peiyong Lin65248e02020-04-18 21:15:07 -07003565 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003566
3567 // --------------------------------------------------------------------
3568 // Postconditions
3569
Peiyong Lin65248e02020-04-18 21:15:07 -07003570 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003571}
3572
3573TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3574 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3575}
3576
3577TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3578 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3579}
3580
3581TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3582 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3583}
3584
3585TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3586 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3587}
3588
3589TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3590 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3591}
3592
3593TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3594 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3595}
3596
3597TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3598 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3599}
3600
3601TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3602 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3603}
3604
3605TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3606 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3607}
3608
3609TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3610 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3611}
3612
3613TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3614 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3615}
3616
3617TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3618 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3619}
3620
3621TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3622 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3623}
3624
3625TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3626 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3627}
3628
3629TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3630 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3631}
3632
3633TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3634 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3635}
3636
3637TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3638 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3639}
3640
3641TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3642 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3643}
3644
3645TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3646 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3647}
3648
3649TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3650 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3651}
3652
Lloyd Piquef58625d2017-12-19 13:22:33 -08003653} // namespace
3654} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08003655
3656// TODO(b/129481165): remove the #pragma below and fix conversion issues
3657#pragma clang diagnostic pop // ignored "-Wconversion"