blob: fd2ccc48d4646f274ed25844f870e7278853897a [file] [log] [blame]
Lloyd Piquef58625d2017-12-19 13:22:33 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Lloyd Piquef58625d2017-12-19 13:22:33 -080021#undef LOG_TAG
22#define LOG_TAG "LibSurfaceFlingerUnittests"
23
Dominik Laskowski075d3172018-05-24 15:50:06 -070024#include <type_traits>
25
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070026#include <compositionengine/Display.h>
27#include <compositionengine/DisplayColorProfile.h>
Lloyd Pique33050472019-12-19 17:12:44 -080028#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070029#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080030#include <gmock/gmock.h>
31#include <gtest/gtest.h>
Lloyd Pique1ebe0902019-10-04 14:47:13 -070032#include <gui/mock/GraphicBufferConsumer.h>
33#include <gui/mock/GraphicBufferProducer.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080034#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070035#include <renderengine/mock/RenderEngine.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070036#include <ui/DebugUtils.h>
Dominik Laskowski075d3172018-05-24 15:50:06 -070037
38#include "DisplayIdentificationTest.h"
Ana Krulecafb45842019-02-13 13:33:03 -080039#include "TestableScheduler.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080040#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080041#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070042#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080043#include "mock/MockEventControlThread.h"
44#include "mock/MockEventThread.h"
45#include "mock/MockMessageQueue.h"
46#include "mock/MockNativeWindowSurface.h"
47#include "mock/MockSurfaceInterceptor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080048#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080049
50namespace android {
51namespace {
52
Lloyd Piquee39cad22017-12-20 17:01:29 -080053using testing::_;
Lloyd Piquee39cad22017-12-20 17:01:29 -080054using testing::DoAll;
55using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080056using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080057using testing::Return;
58using testing::SetArgPointee;
59
Lloyd Piqued883d5a2018-04-27 19:32:30 -070060using android::Hwc2::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080061using android::Hwc2::Error;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070062using android::Hwc2::Hdr;
Lloyd Piquee39cad22017-12-20 17:01:29 -080063using android::Hwc2::IComposer;
64using android::Hwc2::IComposerClient;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070065using android::Hwc2::PerFrameMetadataKey;
66using android::Hwc2::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080067
Lloyd Piquec11e0d32018-01-22 18:44:59 -080068using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
69using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080070using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080071using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080072
Lloyd Piquec11e0d32018-01-22 18:44:59 -080073constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080074constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080075constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080076
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080077constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value
78
Lloyd Piquec11e0d32018-01-22 18:44:59 -080079/* ------------------------------------------------------------------------
80 * Boolean avoidance
81 *
82 * To make calls and template instantiations more readable, we define some
83 * local enums along with an implicit bool conversion.
84 */
85
86#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
87
Lloyd Piquec11e0d32018-01-22 18:44:59 -080088BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -070089BOOL_SUBSTITUTE(Critical);
90BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080091BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -070092BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080093
94/* ------------------------------------------------------------------------
95 *
96 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080097
Lloyd Piquef58625d2017-12-19 13:22:33 -080098class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -080099public:
Lloyd Piquef58625d2017-12-19 13:22:33 -0800100 DisplayTransactionTest();
101 ~DisplayTransactionTest() override;
102
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800103 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800104 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800105
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700106 void injectMockScheduler();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800107 void injectMockComposer(int virtualDisplayCount);
108 void injectFakeBufferQueueFactory();
109 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800110
111 // --------------------------------------------------------------------
112 // Postcondition helpers
113
Dominik Laskowski075d3172018-05-24 15:50:06 -0700114 bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800115 bool hasTransactionFlagSet(int flag);
116 bool hasDisplayDevice(sp<IBinder> displayToken);
117 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
118 bool hasCurrentDisplayState(sp<IBinder> displayToken);
119 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
120 bool hasDrawingDisplayState(sp<IBinder> displayToken);
121 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
122
123 // --------------------------------------------------------------------
124 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800125
Lloyd Piquef58625d2017-12-19 13:22:33 -0800126 TestableSurfaceFlinger mFlinger;
Alec Mouriba013fa2018-10-16 12:43:11 -0700127 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800128 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800129
130 // These mocks are created by the test, but are destroyed by SurfaceFlinger
131 // by virtue of being stored into a std::unique_ptr. However we still need
132 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700133 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800134 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800135 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
136 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700137
138 mock::DispSync* mPrimaryDispSync = new mock::DispSync;
139 mock::EventControlThread* mEventControlThread = new mock::EventControlThread;
140 mock::EventThread* mEventThread = new mock::EventThread;
141 mock::EventThread* mSFEventThread = new mock::EventThread;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800142
143 // These mocks are created only when expected to be created via a factory.
144 sp<mock::GraphicBufferConsumer> mConsumer;
145 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700146 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800147};
148
149DisplayTransactionTest::DisplayTransactionTest() {
150 const ::testing::TestInfo* const test_info =
151 ::testing::UnitTest::GetInstance()->current_test_info();
152 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800153
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800154 // Default to no wide color display support configured
155 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700156 mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800157 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800158
159 // Default to using HWC virtual displays
160 mFlinger.mutableUseHwcVirtualDisplays() = true;
161
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800162 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
163 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
164 });
165
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800166 mFlinger.setCreateNativeWindowSurface([](auto) {
167 ADD_FAILURE() << "Unexpected request to create a native window surface.";
168 return nullptr;
169 });
170
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700171 injectMockScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800172 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700173 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800174 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800175
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800176 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800177}
178
179DisplayTransactionTest::~DisplayTransactionTest() {
180 const ::testing::TestInfo* const test_info =
181 ::testing::UnitTest::GetInstance()->current_test_info();
182 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
183}
184
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700185void DisplayTransactionTest::injectMockScheduler() {
Ana Krulecafb45842019-02-13 13:33:03 -0800186 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700187 EXPECT_CALL(*mEventThread, createEventConnection(_, _))
188 .WillOnce(Return(new EventThreadConnection(mEventThread, ResyncCallback(),
189 ISurfaceComposer::eConfigChangedSuppress)));
190
Ana Krulecafb45842019-02-13 13:33:03 -0800191 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700192 EXPECT_CALL(*mSFEventThread, createEventConnection(_, _))
193 .WillOnce(Return(new EventThreadConnection(mSFEventThread, ResyncCallback(),
194 ISurfaceComposer::eConfigChangedSuppress)));
Ana Krulecafb45842019-02-13 13:33:03 -0800195
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700196 mFlinger.setupScheduler(std::unique_ptr<DispSync>(mPrimaryDispSync),
197 std::unique_ptr<EventControlThread>(mEventControlThread),
198 std::unique_ptr<EventThread>(mEventThread),
199 std::unique_ptr<EventThread>(mSFEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800200}
201
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800202void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
203 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800204 EXPECT_CALL(*mComposer, getCapabilities())
205 .WillOnce(Return(std::vector<IComposer::Capability>()));
206 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
207 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800208
Lloyd Piquee39cad22017-12-20 17:01:29 -0800209 Mock::VerifyAndClear(mComposer);
210}
211
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800212void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800213 // This setup is only expected once per test.
214 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
215
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800216 mConsumer = new mock::GraphicBufferConsumer();
217 mProducer = new mock::GraphicBufferProducer();
218
219 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
220 *outProducer = mProducer;
221 *outConsumer = mConsumer;
222 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800223}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800224
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800225void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800226 // This setup is only expected once per test.
227 ASSERT_TRUE(mNativeWindowSurface == nullptr);
228
Lloyd Pique22098362018-09-13 11:46:49 -0700229 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800230
Lloyd Pique22098362018-09-13 11:46:49 -0700231 mFlinger.setCreateNativeWindowSurface([this](auto) {
232 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
233 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800234}
235
Dominik Laskowski075d3172018-05-24 15:50:06 -0700236bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) {
237 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800238}
239
240bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
241 return mFlinger.mutableTransactionFlags() & flag;
242}
243
244bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700245 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800246}
247
248sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700249 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800250}
251
252bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
253 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
254}
255
256const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
257 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
258}
259
260bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
261 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
262}
263
264const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
265 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
266}
267
268/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800269 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800270 */
271
Dominik Laskowski075d3172018-05-24 15:50:06 -0700272template <typename PhysicalDisplay>
273struct PhysicalDisplayId {};
274
Dominik Laskowski34157762018-10-31 13:07:19 -0700275template <DisplayId::Type displayId>
276using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700277
278struct NoDisplayId {};
279
280template <typename>
281struct IsPhysicalDisplayId : std::bool_constant<false> {};
282
283template <typename PhysicalDisplay>
284struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
285
286template <typename>
287struct DisplayIdGetter;
288
289template <typename PhysicalDisplay>
290struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
291 static std::optional<DisplayId> get() {
292 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
293 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
294 ? HWC_DISPLAY_PRIMARY
295 : HWC_DISPLAY_EXTERNAL);
296 }
297
298 const auto info =
299 parseDisplayIdentificationData(PhysicalDisplay::PORT,
300 PhysicalDisplay::GET_IDENTIFICATION_DATA());
301 return info ? std::make_optional(info->id) : std::nullopt;
302 }
303};
304
Dominik Laskowski34157762018-10-31 13:07:19 -0700305template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700306struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700307 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700308};
309
310template <>
311struct DisplayIdGetter<NoDisplayId> {
312 static std::optional<DisplayId> get() { return {}; }
313};
314
Dominik Laskowski55c85402020-01-21 16:25:47 -0800315template <typename>
316struct DisplayConnectionTypeGetter {
317 static constexpr std::optional<DisplayConnectionType> value;
318};
319
320template <typename PhysicalDisplay>
321struct DisplayConnectionTypeGetter<PhysicalDisplayId<PhysicalDisplay>> {
322 static constexpr std::optional<DisplayConnectionType> value = PhysicalDisplay::CONNECTION_TYPE;
323};
324
Dominik Laskowski075d3172018-05-24 15:50:06 -0700325// DisplayIdType can be:
326// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
327// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
328// 3) NoDisplayId for virtual display without HWC backing.
329template <typename DisplayIdType, int width, int height, Critical critical, Async async,
330 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800331struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700332 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800333 using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700334
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800335 // The display width and height
336 static constexpr int WIDTH = width;
337 static constexpr int HEIGHT = height;
338
339 static constexpr int GRALLOC_USAGE = grallocUsage;
340
Dominik Laskowski075d3172018-05-24 15:50:06 -0700341 // Whether the display is virtual or physical
342 static constexpr Virtual VIRTUAL =
343 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800344
345 // When creating native window surfaces for the framebuffer, whether those should be critical
346 static constexpr Critical CRITICAL = critical;
347
348 // When creating native window surfaces for the framebuffer, whether those should be async
349 static constexpr Async ASYNC = async;
350
351 // Whether the display should be treated as secure
352 static constexpr Secure SECURE = secure;
353
Dominik Laskowski075d3172018-05-24 15:50:06 -0700354 // Whether the display is primary
355 static constexpr Primary PRIMARY = primary;
356
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800357 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700358 auto injector =
Dominik Laskowski55c85402020-01-21 16:25:47 -0800359 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(), CONNECTION_TYPE::value,
360 static_cast<bool>(PRIMARY));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700361
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800362 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700363 injector.setNativeWindow(test->mNativeWindow);
364
365 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800366 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700367 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
368 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
369 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
370 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800371 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
372 .WillRepeatedly(Return(0));
373 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
374 .WillRepeatedly(Return(0));
375 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
376 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700377 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
378 .WillRepeatedly(Return(0));
379
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800380 return injector;
381 }
382
383 // Called by tests to set up any native window creation call expectations.
384 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
385 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
386 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800387
Alec Mouriba013fa2018-10-16 12:43:11 -0700388 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
389 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
390 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
391 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800392 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
393 .WillRepeatedly(Return(0));
394 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
395 .WillRepeatedly(Return(0));
396 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
397 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700398 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
399 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800400 }
401
402 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
403 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
404 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
405 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
406 .WillRepeatedly(Return(NO_ERROR));
407 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
408 .WillRepeatedly(Return(NO_ERROR));
409 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
410 .WillRepeatedly(Return(NO_ERROR));
411 }
412
413 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
414 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
415 }
416};
417
Dominik Laskowski075d3172018-05-24 15:50:06 -0700418template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
419 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800420struct HwcDisplayVariant {
421 // The display id supplied by the HWC
422 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
423
424 // The HWC display type
425 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
426
427 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700428 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700429 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800430
431 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
432 HWC2::Connection connection) {
433 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
434 HotplugEvent{HWC_DISPLAY_ID, connection});
435 }
436
437 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800438 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700439 const auto displayId = DisplayVariant::DISPLAY_ID::get();
440 ASSERT_TRUE(displayId);
441 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
442 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800443 .setHwcDisplayId(HWC_DISPLAY_ID)
444 .setWidth(DisplayVariant::WIDTH)
445 .setHeight(DisplayVariant::HEIGHT)
446 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700447 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800448 .inject(&test->mFlinger, test->mComposer);
449 }
450
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800451 // Called by tests to inject a HWC display setup
452 static void injectHwcDisplay(DisplayTransactionTest* test) {
453 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
454 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
455 Return(Error::NONE)));
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700456 EXPECT_CALL(*test->mComposer,
457 setPowerMode(HWC_DISPLAY_ID,
458 static_cast<Hwc2::IComposerClient::PowerMode>(INIT_POWER_MODE)))
459 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800460 injectHwcDisplayWithNoDefaultCapabilities(test);
461 }
462
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800463 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800464 constexpr auto CONNECTION_TYPE =
465 PhysicalDisplay::CONNECTION_TYPE == DisplayConnectionType::Internal
466 ? IComposerClient::DisplayConnectionType::INTERNAL
467 : IComposerClient::DisplayConnectionType::EXTERNAL;
468
469 EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _))
470 .WillOnce(
471 DoAll(SetArgPointee<1>(CONNECTION_TYPE), Return(Hwc2::V2_4::Error::NONE)));
472
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800473 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
474 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
475 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
476 Return(Error::NONE)));
477 EXPECT_CALL(*test->mComposer,
478 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
479 IComposerClient::Attribute::WIDTH, _))
480 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
481 EXPECT_CALL(*test->mComposer,
482 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
483 IComposerClient::Attribute::HEIGHT, _))
484 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
485 EXPECT_CALL(*test->mComposer,
486 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
487 IComposerClient::Attribute::VSYNC_PERIOD, _))
488 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
489 EXPECT_CALL(*test->mComposer,
490 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
491 IComposerClient::Attribute::DPI_X, _))
492 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
493 EXPECT_CALL(*test->mComposer,
494 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
495 IComposerClient::Attribute::DPI_Y, _))
496 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Ady Abraham7159f572019-10-11 11:10:18 -0700497 EXPECT_CALL(*test->mComposer,
498 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
499 IComposerClient::Attribute::CONFIG_GROUP, _))
500 .WillOnce(DoAll(SetArgPointee<3>(-1), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700501
502 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
503 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
504 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
505 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
506 Return(Error::NONE)));
507 } else {
508 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
509 .WillOnce(Return(Error::UNSUPPORTED));
510 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800511 }
512
513 // Called by tests to set up HWC call expectations
514 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
515 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700516 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800517 }
518};
519
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800520// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
521constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
522 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
523
Dominik Laskowski075d3172018-05-24 15:50:06 -0700524template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800525 Critical critical>
526struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700527 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
528 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
529 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
530 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
531 critical, Async::FALSE, Secure::TRUE,
532 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
533 PhysicalDisplay> {};
534
535template <bool hasIdentificationData>
536struct PrimaryDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800537 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::Internal;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700538 static constexpr Primary PRIMARY = Primary::TRUE;
539 static constexpr uint8_t PORT = 255;
540 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
541 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
542};
543
544template <bool hasIdentificationData>
545struct ExternalDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800546 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::External;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700547 static constexpr Primary PRIMARY = Primary::FALSE;
548 static constexpr uint8_t PORT = 254;
549 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
550 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
551};
552
553struct TertiaryDisplay {
554 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800555 static constexpr uint8_t PORT = 253;
556 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700557};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800558
559// A primary display is a physical display that is critical
560using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700561 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800562
563// An external display is physical display that is not critical.
564using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700565 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800566
567using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700568 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800569
570// A virtual display not supported by the HWC.
571constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
572
573template <int width, int height, Secure secure>
574struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700575 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
576 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
577 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
578 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
579
580 static void injectHwcDisplay(DisplayTransactionTest*) {}
581
582 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
583 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
584 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800585
586 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
587 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
588 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
589 }
590};
591
592// A virtual display supported by the HWC.
593constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
594
595template <int width, int height, Secure secure>
596struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700597 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
598 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
599 HwcDisplayVariant<
600 1010, HWC2::DisplayType::Virtual,
601 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
602 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
603 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
604 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800605 using Self = HwcVirtualDisplayVariant<width, height, secure>;
606
607 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
608 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
609 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
610 }
611
612 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
613 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
614 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
615 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
616 }
617};
618
619// For this variant, SurfaceFlinger should not configure itself with wide
620// display support, so the display should not be configured for wide-color
621// support.
622struct WideColorSupportNotConfiguredVariant {
623 static constexpr bool WIDE_COLOR_SUPPORTED = false;
624
625 static void injectConfigChange(DisplayTransactionTest* test) {
626 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700627 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800628 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800629 }
630
631 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
632 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
633 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
634 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
635 }
636};
637
638// For this variant, SurfaceFlinger should configure itself with wide display
639// support, and the display should respond with an non-empty list of supported
640// color modes. Wide-color support should be configured.
641template <typename Display>
642struct WideColorP3ColorimetricSupportedVariant {
643 static constexpr bool WIDE_COLOR_SUPPORTED = true;
644
645 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700646 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800647 test->mFlinger.mutableHasWideColorDisplay() = true;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800648 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800649 }
650
651 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800652 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
653
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800654 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
655 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
656 Return(Error::NONE)));
657 EXPECT_CALL(*test->mComposer,
658 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
659 .WillOnce(DoAll(SetArgPointee<2>(
660 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
661 Return(Error::NONE)));
662 EXPECT_CALL(*test->mComposer,
663 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
664 RenderIntent::COLORIMETRIC))
665 .WillOnce(Return(Error::NONE));
666 }
667};
668
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800669// For this variant, SurfaceFlinger should configure itself with wide display
670// support, but the display should respond with an empty list of supported color
671// modes. Wide-color support for the display should not be configured.
672template <typename Display>
673struct WideColorNotSupportedVariant {
674 static constexpr bool WIDE_COLOR_SUPPORTED = false;
675
676 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700677 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800678 test->mFlinger.mutableHasWideColorDisplay() = true;
679 }
680
681 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
682 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
683 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700684 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800685 }
686};
687
688// For this variant, the display is not a HWC display, so no HDR support should
689// be configured.
690struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800691 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800692 static constexpr bool HDR10_SUPPORTED = false;
693 static constexpr bool HDR_HLG_SUPPORTED = false;
694 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
695 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
696 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
697 }
698};
699
Valerie Haue9e843a2018-12-18 13:39:23 -0800700template <typename Display>
701struct Hdr10PlusSupportedVariant {
702 static constexpr bool HDR10_PLUS_SUPPORTED = true;
703 static constexpr bool HDR10_SUPPORTED = true;
704 static constexpr bool HDR_HLG_SUPPORTED = false;
705 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
706 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
707 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
708 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
709 Hdr::HDR10_PLUS,
710 Hdr::HDR10,
711 })),
712 Return(Error::NONE)));
713 }
714};
715
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800716// For this variant, the composer should respond with a non-empty list of HDR
717// modes containing HDR10, so HDR10 support should be configured.
718template <typename Display>
719struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800720 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800721 static constexpr bool HDR10_SUPPORTED = true;
722 static constexpr bool HDR_HLG_SUPPORTED = false;
723 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
724 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
725 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
726 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
727 Return(Error::NONE)));
728 }
729};
730
731// For this variant, the composer should respond with a non-empty list of HDR
732// modes containing HLG, so HLG support should be configured.
733template <typename Display>
734struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800735 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800736 static constexpr bool HDR10_SUPPORTED = false;
737 static constexpr bool HDR_HLG_SUPPORTED = true;
738 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
739 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
740 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
741 .WillOnce(
742 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
743 }
744};
745
746// For this variant, the composer should respond with a non-empty list of HDR
747// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
748template <typename Display>
749struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800750 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800751 static constexpr bool HDR10_SUPPORTED = false;
752 static constexpr bool HDR_HLG_SUPPORTED = false;
753 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
754 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
755 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
756 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
757 Return(Error::NONE)));
758 }
759};
760
761// For this variant, the composer should respond with am empty list of HDR
762// modes, so no HDR support should be configured.
763template <typename Display>
764struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800765 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800766 static constexpr bool HDR10_SUPPORTED = false;
767 static constexpr bool HDR_HLG_SUPPORTED = false;
768 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
769 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
770 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
771 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
772 }
773};
774
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700775struct NonHwcPerFrameMetadataSupportVariant {
776 static constexpr int PER_FRAME_METADATA_KEYS = 0;
777 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800778 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700779 }
780};
781
782template <typename Display>
783struct NoPerFrameMetadataSupportVariant {
784 static constexpr int PER_FRAME_METADATA_KEYS = 0;
785 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800786 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
787 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700788 }
789};
790
791template <typename Display>
792struct Smpte2086PerFrameMetadataSupportVariant {
793 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
794 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800795 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
796 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800797 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
798 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
799 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
800 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
801 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
802 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
803 PerFrameMetadataKey::WHITE_POINT_X,
804 PerFrameMetadataKey::WHITE_POINT_Y,
805 PerFrameMetadataKey::MAX_LUMINANCE,
806 PerFrameMetadataKey::MIN_LUMINANCE,
807 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700808 }
809};
810
811template <typename Display>
812struct Cta861_3_PerFrameMetadataSupportVariant {
813 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
814 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800815 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
816 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800817 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
818 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
819 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700820 }
821};
822
Valerie Haue9e843a2018-12-18 13:39:23 -0800823template <typename Display>
824struct Hdr10_Plus_PerFrameMetadataSupportVariant {
825 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
826 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
827 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
828 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
829 PerFrameMetadataKey::HDR10_PLUS_SEI,
830 })));
831 }
832};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800833/* ------------------------------------------------------------------------
834 * Typical display configurations to test
835 */
836
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700837template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
838 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800839struct Case {
840 using Display = DisplayPolicy;
841 using WideColorSupport = WideColorSupportPolicy;
842 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700843 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800844};
845
846using SimplePrimaryDisplayCase =
847 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700848 HdrNotSupportedVariant<PrimaryDisplayVariant>,
849 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800850using SimpleExternalDisplayCase =
851 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700852 HdrNotSupportedVariant<ExternalDisplayVariant>,
853 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800854using SimpleTertiaryDisplayCase =
855 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700856 HdrNotSupportedVariant<TertiaryDisplayVariant>,
857 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800858using NonHwcVirtualDisplayCase =
859 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700860 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
861 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800862using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
863using HwcVirtualDisplayCase =
864 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700865 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800866 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800867using WideColorP3ColorimetricDisplayCase =
868 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700869 HdrNotSupportedVariant<PrimaryDisplayVariant>,
870 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800871using Hdr10PlusDisplayCase =
872 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
873 Hdr10SupportedVariant<PrimaryDisplayVariant>,
874 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800875using Hdr10DisplayCase =
876 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700877 Hdr10SupportedVariant<PrimaryDisplayVariant>,
878 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800879using HdrHlgDisplayCase =
880 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700881 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
882 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800883using HdrDolbyVisionDisplayCase =
884 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700885 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
886 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
887using HdrSmpte2086DisplayCase =
888 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
889 HdrNotSupportedVariant<PrimaryDisplayVariant>,
890 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
891using HdrCta861_3_DisplayCase =
892 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
893 HdrNotSupportedVariant<PrimaryDisplayVariant>,
894 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700895
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800896/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800897 *
898 * SurfaceFlinger::onHotplugReceived
899 */
900
901TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
902 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700903 constexpr hwc2_display_t hwcDisplayId1 = 456;
904 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800905
906 // --------------------------------------------------------------------
907 // Preconditions
908
909 // Set the current sequence id for accepted events
910 mFlinger.mutableComposerSequenceId() = currentSequenceId;
911
912 // Set the main thread id so that the current thread does not appear to be
913 // the main thread.
914 mFlinger.mutableMainThreadId() = std::thread::id();
915
916 // --------------------------------------------------------------------
917 // Call Expectations
918
919 // We expect invalidate() to be invoked once to trigger display transaction
920 // processing.
921 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
922
923 // --------------------------------------------------------------------
924 // Invocation
925
926 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700927 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
928 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800929
930 // --------------------------------------------------------------------
931 // Postconditions
932
933 // The display transaction needed flag should be set.
934 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
935
936 // All events should be in the pending event queue.
937 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
938 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700939 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800940 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700941 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800942 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
943}
944
945TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
946 constexpr int currentSequenceId = 123;
947 constexpr int otherSequenceId = 321;
948 constexpr hwc2_display_t displayId = 456;
949
950 // --------------------------------------------------------------------
951 // Preconditions
952
953 // Set the current sequence id for accepted events
954 mFlinger.mutableComposerSequenceId() = currentSequenceId;
955
956 // Set the main thread id so that the current thread does not appear to be
957 // the main thread.
958 mFlinger.mutableMainThreadId() = std::thread::id();
959
960 // --------------------------------------------------------------------
961 // Call Expectations
962
963 // We do not expect any calls to invalidate().
964 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
965
966 // --------------------------------------------------------------------
967 // Invocation
968
969 // Call with an unexpected sequence id
970 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
971
972 // --------------------------------------------------------------------
973 // Postconditions
974
975 // The display transaction needed flag should not be set
976 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
977
978 // There should be no pending events
979 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
980}
981
982TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
983 constexpr int currentSequenceId = 123;
984 constexpr hwc2_display_t displayId1 = 456;
985
986 // --------------------------------------------------------------------
987 // Note:
988 // --------------------------------------------------------------------
989 // This test case is a bit tricky. We want to verify that
990 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
991 // don't really want to provide coverage for everything the later function
992 // does as there are specific tests for it.
993 // --------------------------------------------------------------------
994
995 // --------------------------------------------------------------------
996 // Preconditions
997
998 // Set the current sequence id for accepted events
999 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1000
1001 // Set the main thread id so that the current thread does appear to be the
1002 // main thread.
1003 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
1004
1005 // --------------------------------------------------------------------
1006 // Call Expectations
1007
1008 // We expect invalidate() to be invoked once to trigger display transaction
1009 // processing.
1010 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1011
1012 // --------------------------------------------------------------------
1013 // Invocation
1014
1015 // Simulate a disconnect on a display id that is not connected. This should
1016 // be enqueued by onHotplugReceived(), and dequeued by
1017 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
1018 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
1019
1020 // --------------------------------------------------------------------
1021 // Postconditions
1022
1023 // The display transaction needed flag should be set.
1024 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1025
1026 // There should be no event queued on return, as it should have been
1027 // processed.
1028 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1029}
1030
1031/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001032 * SurfaceFlinger::createDisplay
1033 */
1034
1035TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1036 const String8 name("virtual.test");
1037
1038 // --------------------------------------------------------------------
1039 // Call Expectations
1040
1041 // The call should notify the interceptor that a display was created.
1042 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1043
1044 // --------------------------------------------------------------------
1045 // Invocation
1046
1047 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1048
1049 // --------------------------------------------------------------------
1050 // Postconditions
1051
1052 // The display should have been added to the current state
1053 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1054 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001055 EXPECT_TRUE(display.isVirtual());
1056 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001057 EXPECT_EQ(name.string(), display.displayName);
1058
1059 // --------------------------------------------------------------------
1060 // Cleanup conditions
1061
1062 // Destroying the display invalidates the display state.
1063 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1064}
1065
1066TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1067 const String8 name("virtual.test");
1068
1069 // --------------------------------------------------------------------
1070 // Call Expectations
1071
1072 // The call should notify the interceptor that a display was created.
1073 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1074
1075 // --------------------------------------------------------------------
1076 // Invocation
1077
1078 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1079
1080 // --------------------------------------------------------------------
1081 // Postconditions
1082
1083 // The display should have been added to the current state
1084 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1085 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001086 EXPECT_TRUE(display.isVirtual());
1087 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001088 EXPECT_EQ(name.string(), display.displayName);
1089
1090 // --------------------------------------------------------------------
1091 // Cleanup conditions
1092
1093 // Destroying the display invalidates the display state.
1094 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1095}
1096
1097/* ------------------------------------------------------------------------
1098 * SurfaceFlinger::destroyDisplay
1099 */
1100
1101TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1102 using Case = NonHwcVirtualDisplayCase;
1103
1104 // --------------------------------------------------------------------
1105 // Preconditions
1106
1107 // A virtual display exists
1108 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1109 existing.inject();
1110
1111 // --------------------------------------------------------------------
1112 // Call Expectations
1113
1114 // The call should notify the interceptor that a display was created.
1115 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1116
1117 // Destroying the display invalidates the display state.
1118 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1119
1120 // --------------------------------------------------------------------
1121 // Invocation
1122
1123 mFlinger.destroyDisplay(existing.token());
1124
1125 // --------------------------------------------------------------------
1126 // Postconditions
1127
1128 // The display should have been removed from the current state
1129 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1130
1131 // Ths display should still exist in the drawing state
1132 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1133
1134 // The display transaction needed flasg should be set
1135 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1136}
1137
1138TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1139 // --------------------------------------------------------------------
1140 // Preconditions
1141
1142 sp<BBinder> displayToken = new BBinder();
1143
1144 // --------------------------------------------------------------------
1145 // Invocation
1146
1147 mFlinger.destroyDisplay(displayToken);
1148}
1149
1150/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001151 * SurfaceFlinger::resetDisplayState
1152 */
1153
1154TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1155 using Case = NonHwcVirtualDisplayCase;
1156
1157 // --------------------------------------------------------------------
1158 // Preconditions
1159
1160 // vsync is enabled and available
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001161 mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = true;
1162 mFlinger.scheduler()->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001163
1164 // A display exists
1165 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1166 existing.inject();
1167
1168 // --------------------------------------------------------------------
1169 // Call Expectations
1170
1171 // The call disable vsyncs
1172 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1173
Lloyd Pique41be5d22018-06-21 13:11:48 -07001174 // The call ends any display resyncs
1175 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1176
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001177 // --------------------------------------------------------------------
1178 // Invocation
1179
1180 mFlinger.resetDisplayState();
1181
1182 // --------------------------------------------------------------------
1183 // Postconditions
1184
1185 // vsyncs should be off and not available.
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001186 EXPECT_FALSE(mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled());
1187 EXPECT_FALSE(mFlinger.scheduler()->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001188
1189 // The display should have been removed from the display map.
1190 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1191
1192 // The display should still exist in the current state
1193 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1194
1195 // The display should have been removed from the drawing state
1196 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1197}
1198
1199/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001200 * DisplayDevice::GetBestColorMode
1201 */
1202class GetBestColorModeTest : public DisplayTransactionTest {
1203public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001204 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001205
Valerie Hau9758ae02018-10-09 16:05:09 -07001206 GetBestColorModeTest()
1207 : DisplayTransactionTest(),
Dominik Laskowski55c85402020-01-21 16:25:47 -08001208 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID,
1209 DisplayConnectionType::Internal,
Dominik Laskowski075d3172018-05-24 15:50:06 -07001210 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001211
1212 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1213
1214 void addHwcColorModesMapping(ui::ColorMode colorMode,
1215 std::vector<ui::RenderIntent> renderIntents) {
1216 mHwcColorModes[colorMode] = renderIntents;
1217 }
1218
1219 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1220
1221 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1222
1223 void getBestColorMode() {
1224 mInjector.setHwcColorModes(mHwcColorModes);
1225 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001226 mInjector.setNativeWindow(mNativeWindow);
1227
1228 // Creating a DisplayDevice requires getting default dimensions from the
1229 // native window.
1230 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1231 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1232 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1233 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001234 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1235 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1236 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07001237 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001238 auto displayDevice = mInjector.inject();
1239
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001240 displayDevice->getCompositionDisplay()
1241 ->getDisplayColorProfile()
1242 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1243 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001244 }
1245
1246 ui::Dataspace mOutDataspace;
1247 ui::ColorMode mOutColorMode;
1248 ui::RenderIntent mOutRenderIntent;
1249
1250private:
1251 ui::Dataspace mInputDataspace;
1252 ui::RenderIntent mInputRenderIntent;
1253 bool mHasWideColorGamut = false;
1254 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1255 FakeDisplayDeviceInjector mInjector;
1256};
1257
1258TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1259 addHwcColorModesMapping(ui::ColorMode::SRGB,
1260 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1261 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1262 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1263 setHasWideColorGamut(true);
1264
1265 getBestColorMode();
1266
Peiyong Lin14724e62018-12-05 07:27:30 -08001267 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001268 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1269 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1270}
1271
1272TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1273 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1274 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1275 addHwcColorModesMapping(ui::ColorMode::SRGB,
1276 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1277 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1278 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1279 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1280 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1281 setHasWideColorGamut(true);
1282
1283 getBestColorMode();
1284
1285 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1286 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1287 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1288}
1289
1290TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1291 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1292 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1293 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1294 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1295 setHasWideColorGamut(true);
1296
1297 getBestColorMode();
1298
1299 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1300 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1301 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1302}
1303
1304/* ------------------------------------------------------------------------
Lloyd Pique33050472019-12-19 17:12:44 -08001305 * DisplayDevice::setProjection
1306 */
1307
1308class DisplayDeviceSetProjectionTest : public DisplayTransactionTest {
1309public:
1310 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Lloyd Pique33050472019-12-19 17:12:44 -08001311 static constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1080; // arbitrary
1312 static constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1920; // arbitrary
1313
1314 static constexpr int32_t TRANSFORM_FLAGS_ROT_0 = 0;
1315 static constexpr int32_t TRANSFORM_FLAGS_ROT_90 = HAL_TRANSFORM_ROT_90;
1316 static constexpr int32_t TRANSFORM_FLAGS_ROT_180 = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V;
1317 static constexpr int32_t TRANSFORM_FLAGS_ROT_270 =
1318 HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
1319
1320 DisplayDeviceSetProjectionTest(ui::Size flingerDisplaySize, ui::Size hardwareDisplaySize,
1321 ui::Rotation physicalOrientation)
1322 : mFlingerDisplaySize(flingerDisplaySize),
1323 mHardwareDisplaySize(hardwareDisplaySize),
1324 mPhysicalOrientation(physicalOrientation),
1325 mDisplayDevice(createDisplayDevice()) {}
1326
1327 sp<DisplayDevice> createDisplayDevice() {
1328 // The DisplayDevice is required to have a framebuffer (behind the
1329 // ANativeWindow interface) which uses the actual hardware display
1330 // size.
1331 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1332 .WillRepeatedly(DoAll(SetArgPointee<1>(mHardwareDisplaySize.width), Return(0)));
1333 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1334 .WillRepeatedly(DoAll(SetArgPointee<1>(mHardwareDisplaySize.height), Return(0)));
1335 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT));
1336 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT));
1337 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64));
1338 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT));
1339
Dominik Laskowski55c85402020-01-21 16:25:47 -08001340 return FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID,
1341 DisplayConnectionType::Internal, true /* isPrimary */)
Lloyd Pique33050472019-12-19 17:12:44 -08001342 .setNativeWindow(mNativeWindow)
1343 .setPhysicalOrientation(mPhysicalOrientation)
1344 .inject();
1345 }
1346
1347 ui::Size SwapWH(const ui::Size size) const { return ui::Size(size.height, size.width); }
1348
1349 void setProjectionForRotation0() {
1350 // A logical rotation of 0 uses the SurfaceFlinger display size
1351 mDisplayDevice->setProjection(ui::ROTATION_0, Rect(mFlingerDisplaySize),
1352 Rect(mFlingerDisplaySize));
1353 }
1354
1355 void setProjectionForRotation90() {
1356 // A logical rotation of 90 uses the SurfaceFlinger display size with
1357 // the width/height swapped.
1358 mDisplayDevice->setProjection(ui::ROTATION_90, Rect(SwapWH(mFlingerDisplaySize)),
1359 Rect(SwapWH(mFlingerDisplaySize)));
1360 }
1361
1362 void setProjectionForRotation180() {
1363 // A logical rotation of 180 uses the SurfaceFlinger display size
1364 mDisplayDevice->setProjection(ui::ROTATION_180, Rect(mFlingerDisplaySize),
1365 Rect(mFlingerDisplaySize));
1366 }
1367
1368 void setProjectionForRotation270() {
1369 // A logical rotation of 270 uses the SurfaceFlinger display size with
1370 // the width/height swapped.
1371 mDisplayDevice->setProjection(ui::ROTATION_270, Rect(SwapWH(mFlingerDisplaySize)),
1372 Rect(SwapWH(mFlingerDisplaySize)));
1373 }
1374
1375 void expectStateForHardwareTransform0() {
1376 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1377 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_0, mHardwareDisplaySize.width,
1378 mHardwareDisplaySize.height),
1379 compositionState.transform);
1380 EXPECT_EQ(TRANSFORM_FLAGS_ROT_0, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001381 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1382 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001383 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1384 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1385 EXPECT_EQ(false, compositionState.needsFiltering);
1386 }
1387
1388 void expectStateForHardwareTransform90() {
1389 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1390 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width,
1391 mHardwareDisplaySize.height),
1392 compositionState.transform);
1393 EXPECT_EQ(TRANSFORM_FLAGS_ROT_90, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001394 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1395 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001396 // For 90, the frame and viewport have the hardware display size width and height swapped
1397 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1398 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1399 EXPECT_EQ(false, compositionState.needsFiltering);
1400 }
1401
1402 void expectStateForHardwareTransform180() {
1403 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1404 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width,
1405 mHardwareDisplaySize.height),
1406 compositionState.transform);
1407 EXPECT_EQ(TRANSFORM_FLAGS_ROT_180, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001408 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1409 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001410 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.frame);
1411 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.viewport);
1412 EXPECT_EQ(false, compositionState.needsFiltering);
1413 }
1414
1415 void expectStateForHardwareTransform270() {
1416 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1417 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width,
1418 mHardwareDisplaySize.height),
1419 compositionState.transform);
1420 EXPECT_EQ(TRANSFORM_FLAGS_ROT_270, compositionState.orientation);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08001421 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.sourceClip);
1422 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.destinationClip);
Lloyd Pique33050472019-12-19 17:12:44 -08001423 // For 270, the frame and viewport have the hardware display size width and height swapped
1424 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.frame);
1425 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.viewport);
1426 EXPECT_EQ(false, compositionState.needsFiltering);
1427 }
1428
1429 const ui::Size mFlingerDisplaySize;
1430 const ui::Size mHardwareDisplaySize;
1431 const ui::Rotation mPhysicalOrientation;
1432 const sp<DisplayDevice> mDisplayDevice;
1433};
1434
1435struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest {
1436 DisplayDeviceSetProjectionTest_Installed0()
1437 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1438 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1439 ui::ROTATION_0) {}
1440};
1441
1442TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) {
1443 setProjectionForRotation0();
1444 expectStateForHardwareTransform0();
1445}
1446
1447TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) {
1448 setProjectionForRotation90();
1449 expectStateForHardwareTransform90();
1450}
1451
1452TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) {
1453 setProjectionForRotation180();
1454 expectStateForHardwareTransform180();
1455}
1456
1457TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) {
1458 setProjectionForRotation270();
1459 expectStateForHardwareTransform270();
1460}
1461
1462struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest {
1463 DisplayDeviceSetProjectionTest_Installed90()
1464 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1465 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1466 ui::ROTATION_90) {}
1467};
1468
1469TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) {
1470 setProjectionForRotation0();
1471 expectStateForHardwareTransform90();
1472}
1473
1474TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) {
1475 setProjectionForRotation90();
1476 expectStateForHardwareTransform180();
1477}
1478
1479TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) {
1480 setProjectionForRotation180();
1481 expectStateForHardwareTransform270();
1482}
1483
1484TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) {
1485 setProjectionForRotation270();
1486 expectStateForHardwareTransform0();
1487}
1488
1489struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest {
1490 DisplayDeviceSetProjectionTest_Installed180()
1491 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1492 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1493 ui::ROTATION_180) {}
1494};
1495
1496TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) {
1497 setProjectionForRotation0();
1498 expectStateForHardwareTransform180();
1499}
1500
1501TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) {
1502 setProjectionForRotation90();
1503 expectStateForHardwareTransform270();
1504}
1505
1506TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) {
1507 setProjectionForRotation180();
1508 expectStateForHardwareTransform0();
1509}
1510
1511TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) {
1512 setProjectionForRotation270();
1513 expectStateForHardwareTransform90();
1514}
1515
1516struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest {
1517 DisplayDeviceSetProjectionTest_Installed270()
1518 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1519 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1520 ui::ROTATION_270) {}
1521};
1522
1523TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) {
1524 setProjectionForRotation0();
1525 expectStateForHardwareTransform270();
1526}
1527
1528TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) {
1529 setProjectionForRotation90();
1530 expectStateForHardwareTransform0();
1531}
1532
1533TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) {
1534 setProjectionForRotation180();
1535 expectStateForHardwareTransform90();
1536}
1537
1538TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) {
1539 setProjectionForRotation270();
1540 expectStateForHardwareTransform180();
1541}
1542
1543/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001544 * SurfaceFlinger::getDisplayNativePrimaries
1545 */
1546
1547class GetDisplayNativePrimaries : public DisplayTransactionTest {
1548public:
1549 GetDisplayNativePrimaries();
1550 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1551 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1552
1553private:
1554 static constexpr float mStartingTestValue = 1.0f;
1555};
1556
1557GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1558 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1559 injectFakeNativeWindowSurfaceFactory();
1560}
1561
1562void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1563 ui::DisplayPrimaries& primaries) {
1564 float startingVal = mStartingTestValue;
1565 primaries.red.X = startingVal++;
1566 primaries.red.Y = startingVal++;
1567 primaries.red.Z = startingVal++;
1568 primaries.green.X = startingVal++;
1569 primaries.green.Y = startingVal++;
1570 primaries.green.Z = startingVal++;
1571 primaries.blue.X = startingVal++;
1572 primaries.blue.Y = startingVal++;
1573 primaries.blue.Z = startingVal++;
1574 primaries.white.X = startingVal++;
1575 primaries.white.Y = startingVal++;
1576 primaries.white.Z = startingVal++;
1577}
1578
1579void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1580 const ui::DisplayPrimaries& primaries) {
1581 float startingVal = mStartingTestValue;
1582 EXPECT_EQ(primaries.red.X, startingVal++);
1583 EXPECT_EQ(primaries.red.Y, startingVal++);
1584 EXPECT_EQ(primaries.red.Z, startingVal++);
1585 EXPECT_EQ(primaries.green.X, startingVal++);
1586 EXPECT_EQ(primaries.green.Y, startingVal++);
1587 EXPECT_EQ(primaries.green.Z, startingVal++);
1588 EXPECT_EQ(primaries.blue.X, startingVal++);
1589 EXPECT_EQ(primaries.blue.Y, startingVal++);
1590 EXPECT_EQ(primaries.blue.Z, startingVal++);
1591 EXPECT_EQ(primaries.white.X, startingVal++);
1592 EXPECT_EQ(primaries.white.Y, startingVal++);
1593 EXPECT_EQ(primaries.white.Z, startingVal++);
1594}
1595
1596TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1597 ui::DisplayPrimaries primaries;
1598 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1599}
1600
Daniel Solomon42d04562019-01-20 21:03:19 -08001601TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1602 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1603 injector.inject();
1604 auto internalDisplayToken = injector.token();
1605
1606 ui::DisplayPrimaries expectedPrimaries;
1607 populateDummyDisplayNativePrimaries(expectedPrimaries);
1608 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1609
1610 ui::DisplayPrimaries primaries;
1611 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1612
1613 checkDummyDisplayNativePrimaries(primaries);
1614}
1615
1616TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1617 sp<BBinder> notInternalDisplayToken = new BBinder();
1618
1619 ui::DisplayPrimaries primaries;
1620 populateDummyDisplayNativePrimaries(primaries);
1621 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1622
1623 // Check primaries argument wasn't modified in case of failure
1624 checkDummyDisplayNativePrimaries(primaries);
1625}
1626
1627/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001628 * SurfaceFlinger::setupNewDisplayDeviceInternal
1629 */
1630
1631class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1632public:
1633 template <typename T>
1634 void setupNewDisplayDeviceInternalTest();
1635};
1636
1637template <typename Case>
1638void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1639 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001640 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1641 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001642 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001643
1644 // --------------------------------------------------------------------
1645 // Preconditions
1646
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001647 // Wide color displays support is configured appropriately
1648 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001649
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001650 // The display is setup with the HWC.
1651 Case::Display::injectHwcDisplay(this);
1652
1653 // SurfaceFlinger will use a test-controlled factory for native window
1654 // surfaces.
1655 injectFakeNativeWindowSurfaceFactory();
1656
1657 // --------------------------------------------------------------------
1658 // Call Expectations
1659
1660 // Various native window calls will be made.
1661 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001662 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001663 Case::WideColorSupport::setupComposerCallExpectations(this);
1664 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001665 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001666
1667 // --------------------------------------------------------------------
1668 // Invocation
1669
1670 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -08001671 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1672 const auto displayId = Case::Display::DISPLAY_ID::get();
1673 ASSERT_TRUE(displayId);
1674 state.physical = {*displayId, *connectionType};
1675 }
1676
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001677 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1678
Dominik Laskowski075d3172018-05-24 15:50:06 -07001679 auto device =
1680 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1681 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001682
1683 // --------------------------------------------------------------------
1684 // Postconditions
1685
1686 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001687 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001688 EXPECT_EQ(Case::Display::CONNECTION_TYPE::value, device->getConnectionType());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001689 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001690 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001691 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001692 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1693 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1694 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001695 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001696 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1697 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1698 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001699 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1700 // remapped, and the test only ever sets up one config. If there were an error
1701 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
Ady Abraham2139f732019-11-13 18:56:40 -08001702 EXPECT_EQ(0, device->getActiveConfig().value());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001703 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1704 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001705}
1706
1707TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1708 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1709}
1710
1711TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1712 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1713}
1714
1715TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1716 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1717}
1718
1719TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001720 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001721
Dominik Laskowski075d3172018-05-24 15:50:06 -07001722 // Insert display data so that the HWC thinks it created the virtual display.
1723 const auto displayId = Case::Display::DISPLAY_ID::get();
1724 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001725 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001726
1727 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001728}
1729
1730TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1731 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1732}
1733
Valerie Haue9e843a2018-12-18 13:39:23 -08001734TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1735 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1736}
1737
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001738TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1739 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1740}
1741
1742TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1743 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1744}
1745
1746TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1747 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1748}
1749
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001750TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1751 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1752}
1753
1754TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1755 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1756}
1757
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001758/* ------------------------------------------------------------------------
1759 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1760 */
1761
1762class HandleTransactionLockedTest : public DisplayTransactionTest {
1763public:
1764 template <typename Case>
1765 void setupCommonPreconditions();
1766
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001767 template <typename Case, bool connected>
1768 static void expectHotplugReceived(mock::EventThread*);
1769
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001770 template <typename Case>
1771 void setupCommonCallExpectationsForConnectProcessing();
1772
1773 template <typename Case>
1774 void setupCommonCallExpectationsForDisconnectProcessing();
1775
1776 template <typename Case>
1777 void processesHotplugConnectCommon();
1778
1779 template <typename Case>
1780 void ignoresHotplugConnectCommon();
1781
1782 template <typename Case>
1783 void processesHotplugDisconnectCommon();
1784
1785 template <typename Case>
1786 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1787
1788 template <typename Case>
1789 void verifyPhysicalDisplayIsConnected();
1790
1791 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1792};
1793
1794template <typename Case>
1795void HandleTransactionLockedTest::setupCommonPreconditions() {
1796 // Wide color displays support is configured appropriately
1797 Case::WideColorSupport::injectConfigChange(this);
1798
1799 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1800 injectFakeBufferQueueFactory();
1801
1802 // SurfaceFlinger will use a test-controlled factory for native window
1803 // surfaces.
1804 injectFakeNativeWindowSurfaceFactory();
1805}
1806
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001807template <typename Case, bool connected>
1808void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1809 const auto convert = [](auto physicalDisplayId) {
1810 return std::make_optional(DisplayId{physicalDisplayId});
1811 };
1812
1813 EXPECT_CALL(*eventThread,
1814 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1815 .Times(1);
1816}
1817
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001818template <typename Case>
1819void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1820 Case::Display::setupHwcHotplugCallExpectations(this);
1821
1822 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1823 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1824 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1825 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1826
1827 Case::WideColorSupport::setupComposerCallExpectations(this);
1828 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001829 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001830
1831 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001832 expectHotplugReceived<Case, true>(mEventThread);
1833 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001834}
1835
1836template <typename Case>
1837void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1838 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001839
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001840 expectHotplugReceived<Case, false>(mEventThread);
1841 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001842}
1843
1844template <typename Case>
1845void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1846 // The display device should have been set up in the list of displays.
1847 ASSERT_TRUE(hasDisplayDevice(displayToken));
1848 const auto& device = getDisplayDevice(displayToken);
1849 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001850 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001851
Dominik Laskowski55c85402020-01-21 16:25:47 -08001852 std::optional<DisplayDeviceState::Physical> expectedPhysical;
1853 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1854 const auto displayId = Case::Display::DISPLAY_ID::get();
1855 ASSERT_TRUE(displayId);
1856 expectedPhysical = {*displayId, *connectionType};
1857 }
1858
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001859 // The display should have been set up in the current display state
1860 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1861 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001862 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001863 EXPECT_EQ(expectedPhysical, current.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001864
1865 // The display should have been set up in the drawing display state
1866 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1867 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001868 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001869 EXPECT_EQ(expectedPhysical, draw.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001870}
1871
1872template <typename Case>
1873void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1874 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001875 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001876
Dominik Laskowski075d3172018-05-24 15:50:06 -07001877 // SF should have a display token.
1878 const auto displayId = Case::Display::DISPLAY_ID::get();
1879 ASSERT_TRUE(displayId);
1880 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1881 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001882
1883 verifyDisplayIsConnected<Case>(displayToken);
1884}
1885
1886void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1887 EXPECT_FALSE(hasDisplayDevice(displayToken));
1888 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1889 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1890}
1891
1892template <typename Case>
1893void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1894 // --------------------------------------------------------------------
1895 // Preconditions
1896
1897 setupCommonPreconditions<Case>();
1898
1899 // A hotplug connect event is enqueued for a display
1900 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001901
1902 // --------------------------------------------------------------------
1903 // Call Expectations
1904
1905 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001906
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001907 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001908
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001909 // --------------------------------------------------------------------
1910 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001911
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001912 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001913
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001914 // --------------------------------------------------------------------
1915 // Postconditions
1916
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001917 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001918
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001919 // --------------------------------------------------------------------
1920 // Cleanup conditions
1921
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001922 EXPECT_CALL(*mComposer,
1923 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001924 .WillOnce(Return(Error::NONE));
1925 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001926}
1927
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001928template <typename Case>
1929void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1930 // --------------------------------------------------------------------
1931 // Preconditions
1932
1933 setupCommonPreconditions<Case>();
1934
1935 // A hotplug connect event is enqueued for a display
1936 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1937
1938 // --------------------------------------------------------------------
1939 // Invocation
1940
1941 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1942
1943 // --------------------------------------------------------------------
1944 // Postconditions
1945
1946 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001947 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001948}
1949
1950template <typename Case>
1951void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1952 // --------------------------------------------------------------------
1953 // Preconditions
1954
1955 setupCommonPreconditions<Case>();
1956
1957 // A hotplug disconnect event is enqueued for a display
1958 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1959
1960 // The display is already completely set up.
1961 Case::Display::injectHwcDisplay(this);
1962 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1963 existing.inject();
1964
1965 // --------------------------------------------------------------------
1966 // Call Expectations
1967
1968 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001969 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1970 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001971
1972 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1973
1974 // --------------------------------------------------------------------
1975 // Invocation
1976
1977 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1978
1979 // --------------------------------------------------------------------
1980 // Postconditions
1981
1982 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001983 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001984
Dominik Laskowski075d3172018-05-24 15:50:06 -07001985 // SF should not have a display token.
1986 const auto displayId = Case::Display::DISPLAY_ID::get();
1987 ASSERT_TRUE(displayId);
1988 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001989
1990 // The existing token should have been removed
1991 verifyDisplayIsNotConnected(existing.token());
1992}
1993
1994TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1995 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1996}
1997
1998TEST_F(HandleTransactionLockedTest,
1999 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
2000 // Inject an external display.
2001 ExternalDisplayVariant::injectHwcDisplay(this);
2002
2003 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2004}
2005
2006TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
2007 // Inject a primary display.
2008 PrimaryDisplayVariant::injectHwcDisplay(this);
2009
2010 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
2011}
2012
2013TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
2014 // Inject both a primary and external display.
2015 PrimaryDisplayVariant::injectHwcDisplay(this);
2016 ExternalDisplayVariant::injectHwcDisplay(this);
2017
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002018 // TODO: This is an unnecessary call.
2019 EXPECT_CALL(*mComposer,
2020 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
2021 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
2022 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
2023 Return(Error::NONE)));
2024
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002025 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2026
2027 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
2028}
2029
2030TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
2031 // Inject a primary display.
2032 PrimaryDisplayVariant::injectHwcDisplay(this);
2033
2034 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
2035
2036 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
2037}
2038
2039TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
2040 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
2041}
2042
2043TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
2044 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
2045}
2046
2047TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
2048 using Case = SimplePrimaryDisplayCase;
2049
2050 // --------------------------------------------------------------------
2051 // Preconditions
2052
2053 setupCommonPreconditions<Case>();
2054
2055 // A hotplug connect event is enqueued for a display
2056 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
2057 // A hotplug disconnect event is also enqueued for the same display
2058 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
2059
2060 // --------------------------------------------------------------------
2061 // Call Expectations
2062
2063 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2064
2065 setupCommonCallExpectationsForConnectProcessing<Case>();
2066 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2067
2068 EXPECT_CALL(*mComposer,
2069 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2070 .WillOnce(Return(Error::NONE));
2071 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2072
2073 // --------------------------------------------------------------------
2074 // Invocation
2075
2076 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2077
2078 // --------------------------------------------------------------------
2079 // Postconditions
2080
2081 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002082 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002083
Dominik Laskowski075d3172018-05-24 15:50:06 -07002084 // SF should not have a display token.
2085 const auto displayId = Case::Display::DISPLAY_ID::get();
2086 ASSERT_TRUE(displayId);
2087 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002088}
2089
2090TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
2091 using Case = SimplePrimaryDisplayCase;
2092
2093 // --------------------------------------------------------------------
2094 // Preconditions
2095
2096 setupCommonPreconditions<Case>();
2097
2098 // The display is already completely set up.
2099 Case::Display::injectHwcDisplay(this);
2100 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2101 existing.inject();
2102
2103 // A hotplug disconnect event is enqueued for a display
2104 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
2105 // A hotplug connect event is also enqueued for the same display
2106 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
2107
2108 // --------------------------------------------------------------------
2109 // Call Expectations
2110
2111 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2112
2113 setupCommonCallExpectationsForConnectProcessing<Case>();
2114 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2115
2116 // --------------------------------------------------------------------
2117 // Invocation
2118
2119 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2120
2121 // --------------------------------------------------------------------
2122 // Postconditions
2123
2124 // The existing token should have been removed
2125 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07002126 const auto displayId = Case::Display::DISPLAY_ID::get();
2127 ASSERT_TRUE(displayId);
2128 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
2129 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002130
2131 // A new display should be connected in its place
2132
2133 verifyPhysicalDisplayIsConnected<Case>();
2134
2135 // --------------------------------------------------------------------
2136 // Cleanup conditions
2137
2138 EXPECT_CALL(*mComposer,
2139 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2140 .WillOnce(Return(Error::NONE));
2141 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2142}
2143
2144TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
2145 using Case = HwcVirtualDisplayCase;
2146
2147 // --------------------------------------------------------------------
2148 // Preconditions
2149
2150 // The HWC supports at least one virtual display
2151 injectMockComposer(1);
2152
2153 setupCommonPreconditions<Case>();
2154
2155 // A virtual display was added to the current state, and it has a
2156 // surface(producer)
2157 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07002158
Dominik Laskowski075d3172018-05-24 15:50:06 -07002159 DisplayDeviceState state;
2160 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002161
2162 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07002163 state.surface = surface;
2164 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002165
2166 // --------------------------------------------------------------------
2167 // Call Expectations
2168
2169 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
2170 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
2171
2172 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
2173 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
2174 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
2175 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
2176 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
2177 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
2178 Return(NO_ERROR)));
2179 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
2180 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
2181
2182 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
2183
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002184 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002185 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
2186
2187 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
2188 Case::WideColorSupport::setupComposerCallExpectations(this);
2189 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07002190 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002191
2192 // --------------------------------------------------------------------
2193 // Invocation
2194
2195 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2196
2197 // --------------------------------------------------------------------
2198 // Postconditions
2199
2200 // The display device should have been set up in the list of displays.
2201 verifyDisplayIsConnected<Case>(displayToken);
2202
2203 // --------------------------------------------------------------------
2204 // Cleanup conditions
2205
2206 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
2207 .WillOnce(Return(Error::NONE));
2208 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08002209
2210 // Cleanup
2211 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
2212 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002213}
2214
2215TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
2216 using Case = HwcVirtualDisplayCase;
2217
2218 // --------------------------------------------------------------------
2219 // Preconditions
2220
2221 // The HWC supports at least one virtual display
2222 injectMockComposer(1);
2223
2224 setupCommonPreconditions<Case>();
2225
2226 // A virtual display was added to the current state, but it does not have a
2227 // surface.
2228 sp<BBinder> displayToken = new BBinder();
2229
Dominik Laskowski075d3172018-05-24 15:50:06 -07002230 DisplayDeviceState state;
2231 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002232
Dominik Laskowski075d3172018-05-24 15:50:06 -07002233 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002234
2235 // --------------------------------------------------------------------
2236 // Call Expectations
2237
2238 // --------------------------------------------------------------------
2239 // Invocation
2240
2241 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2242
2243 // --------------------------------------------------------------------
2244 // Postconditions
2245
2246 // There will not be a display device set up.
2247 EXPECT_FALSE(hasDisplayDevice(displayToken));
2248
2249 // The drawing display state will be set from the current display state.
2250 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2251 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002252 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002253}
2254
2255TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
2256 using Case = HwcVirtualDisplayCase;
2257
2258 // --------------------------------------------------------------------
2259 // Preconditions
2260
2261 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002262 const auto displayId = Case::Display::DISPLAY_ID::get();
2263 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08002264 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002265 Case::Display::injectHwcDisplay(this);
2266 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2267 existing.inject();
2268 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2269
2270 // --------------------------------------------------------------------
2271 // Call Expectations
2272
2273 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2274
2275 // --------------------------------------------------------------------
2276 // Invocation
2277
2278 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2279
2280 // --------------------------------------------------------------------
2281 // Postconditions
2282
2283 // The existing token should have been removed
2284 verifyDisplayIsNotConnected(existing.token());
2285}
2286
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002287TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2288 using Case = NonHwcVirtualDisplayCase;
2289
2290 constexpr uint32_t oldLayerStack = 0u;
2291 constexpr uint32_t newLayerStack = 123u;
2292
2293 // --------------------------------------------------------------------
2294 // Preconditions
2295
2296 // A display is set up
2297 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2298 display.inject();
2299
2300 // There is a change to the layerStack state
2301 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2302 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2303
2304 // --------------------------------------------------------------------
2305 // Invocation
2306
2307 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2308
2309 // --------------------------------------------------------------------
2310 // Postconditions
2311
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002312 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002313}
2314
2315TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2316 using Case = NonHwcVirtualDisplayCase;
2317
Dominik Laskowski718f9602019-11-09 20:01:35 -08002318 constexpr ui::Rotation oldTransform = ui::ROTATION_0;
2319 constexpr ui::Rotation newTransform = ui::ROTATION_180;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002320
2321 // --------------------------------------------------------------------
2322 // Preconditions
2323
2324 // A display is set up
2325 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2326 display.inject();
2327
2328 // There is a change to the orientation state
2329 display.mutableDrawingDisplayState().orientation = oldTransform;
2330 display.mutableCurrentDisplayState().orientation = newTransform;
2331
2332 // --------------------------------------------------------------------
2333 // Invocation
2334
2335 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2336
2337 // --------------------------------------------------------------------
2338 // Postconditions
2339
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002340 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002341}
2342
2343TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2344 using Case = NonHwcVirtualDisplayCase;
2345
2346 const Rect oldViewport(0, 0, 0, 0);
2347 const Rect newViewport(0, 0, 123, 456);
2348
2349 // --------------------------------------------------------------------
2350 // Preconditions
2351
2352 // A display is set up
2353 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2354 display.inject();
2355
2356 // There is a change to the viewport state
2357 display.mutableDrawingDisplayState().viewport = oldViewport;
2358 display.mutableCurrentDisplayState().viewport = newViewport;
2359
2360 // --------------------------------------------------------------------
2361 // Invocation
2362
2363 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2364
2365 // --------------------------------------------------------------------
2366 // Postconditions
2367
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002368 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002369}
2370
2371TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2372 using Case = NonHwcVirtualDisplayCase;
2373
2374 const Rect oldFrame(0, 0, 0, 0);
2375 const Rect newFrame(0, 0, 123, 456);
2376
2377 // --------------------------------------------------------------------
2378 // Preconditions
2379
2380 // A display is set up
2381 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2382 display.inject();
2383
2384 // There is a change to the viewport state
2385 display.mutableDrawingDisplayState().frame = oldFrame;
2386 display.mutableCurrentDisplayState().frame = newFrame;
2387
2388 // --------------------------------------------------------------------
2389 // Invocation
2390
2391 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2392
2393 // --------------------------------------------------------------------
2394 // Postconditions
2395
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002396 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002397}
2398
2399TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2400 using Case = NonHwcVirtualDisplayCase;
2401
2402 constexpr int oldWidth = 0;
2403 constexpr int oldHeight = 10;
2404 constexpr int newWidth = 123;
2405
2406 // --------------------------------------------------------------------
2407 // Preconditions
2408
2409 // A display is set up
2410 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002411 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002412 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002413 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2414 display.setNativeWindow(nativeWindow);
2415 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002416 // Setup injection expections
2417 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2418 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2419 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2420 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002421 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2422 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2423 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002424 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002425 display.inject();
2426
2427 // There is a change to the viewport state
2428 display.mutableDrawingDisplayState().width = oldWidth;
2429 display.mutableDrawingDisplayState().height = oldHeight;
2430 display.mutableCurrentDisplayState().width = newWidth;
2431 display.mutableCurrentDisplayState().height = oldHeight;
2432
2433 // --------------------------------------------------------------------
2434 // Call Expectations
2435
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002436 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002437
2438 // --------------------------------------------------------------------
2439 // Invocation
2440
2441 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2442}
2443
2444TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2445 using Case = NonHwcVirtualDisplayCase;
2446
2447 constexpr int oldWidth = 0;
2448 constexpr int oldHeight = 10;
2449 constexpr int newHeight = 123;
2450
2451 // --------------------------------------------------------------------
2452 // Preconditions
2453
2454 // A display is set up
2455 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002456 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002457 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002458 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2459 display.setNativeWindow(nativeWindow);
2460 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002461 // Setup injection expections
2462 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2463 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2464 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2465 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002466 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2467 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2468 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002469 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002470 display.inject();
2471
2472 // There is a change to the viewport state
2473 display.mutableDrawingDisplayState().width = oldWidth;
2474 display.mutableDrawingDisplayState().height = oldHeight;
2475 display.mutableCurrentDisplayState().width = oldWidth;
2476 display.mutableCurrentDisplayState().height = newHeight;
2477
2478 // --------------------------------------------------------------------
2479 // Call Expectations
2480
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002481 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002482
2483 // --------------------------------------------------------------------
2484 // Invocation
2485
2486 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2487}
2488
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002489/* ------------------------------------------------------------------------
2490 * SurfaceFlinger::setDisplayStateLocked
2491 */
2492
2493TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2494 // --------------------------------------------------------------------
2495 // Preconditions
2496
2497 // We have an unknown display token not associated with a known display
2498 sp<BBinder> displayToken = new BBinder();
2499
2500 // The requested display state references the unknown display.
2501 DisplayState state;
2502 state.what = DisplayState::eLayerStackChanged;
2503 state.token = displayToken;
2504 state.layerStack = 456;
2505
2506 // --------------------------------------------------------------------
2507 // Invocation
2508
2509 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2510
2511 // --------------------------------------------------------------------
2512 // Postconditions
2513
2514 // The returned flags are empty
2515 EXPECT_EQ(0u, flags);
2516
2517 // The display token still doesn't match anything known.
2518 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2519}
2520
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002521TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2522 using Case = SimplePrimaryDisplayCase;
2523
2524 // --------------------------------------------------------------------
2525 // Preconditions
2526
2527 // A display is already set up
2528 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2529 display.inject();
2530
2531 // No changes are made to the display
2532 DisplayState state;
2533 state.what = 0;
2534 state.token = display.token();
2535
2536 // --------------------------------------------------------------------
2537 // Invocation
2538
2539 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2540
2541 // --------------------------------------------------------------------
2542 // Postconditions
2543
2544 // The returned flags are empty
2545 EXPECT_EQ(0u, flags);
2546}
2547
2548TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2549 using Case = SimplePrimaryDisplayCase;
2550
2551 // --------------------------------------------------------------------
2552 // Preconditions
2553
2554 // A display is already set up
2555 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2556 display.inject();
2557
2558 // There is a surface that can be set.
2559 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2560
2561 // The current display state has the surface set
2562 display.mutableCurrentDisplayState().surface = surface;
2563
2564 // The incoming request sets the same surface
2565 DisplayState state;
2566 state.what = DisplayState::eSurfaceChanged;
2567 state.token = display.token();
2568 state.surface = surface;
2569
2570 // --------------------------------------------------------------------
2571 // Invocation
2572
2573 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2574
2575 // --------------------------------------------------------------------
2576 // Postconditions
2577
2578 // The returned flags are empty
2579 EXPECT_EQ(0u, flags);
2580
2581 // The current display state is unchanged.
2582 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2583}
2584
2585TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2586 using Case = SimplePrimaryDisplayCase;
2587
2588 // --------------------------------------------------------------------
2589 // Preconditions
2590
2591 // A display is already set up
2592 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2593 display.inject();
2594
2595 // There is a surface that can be set.
2596 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2597
2598 // The current display state does not have a surface
2599 display.mutableCurrentDisplayState().surface = nullptr;
2600
2601 // The incoming request sets a surface
2602 DisplayState state;
2603 state.what = DisplayState::eSurfaceChanged;
2604 state.token = display.token();
2605 state.surface = surface;
2606
2607 // --------------------------------------------------------------------
2608 // Invocation
2609
2610 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2611
2612 // --------------------------------------------------------------------
2613 // Postconditions
2614
2615 // The returned flags indicate a transaction is needed
2616 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2617
2618 // The current display layer stack state is set to the new value
2619 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2620}
2621
2622TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2623 using Case = SimplePrimaryDisplayCase;
2624
2625 // --------------------------------------------------------------------
2626 // Preconditions
2627
2628 // A display is already set up
2629 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2630 display.inject();
2631
2632 // The display has a layer stack set
2633 display.mutableCurrentDisplayState().layerStack = 456u;
2634
2635 // The incoming request sets the same layer stack
2636 DisplayState state;
2637 state.what = DisplayState::eLayerStackChanged;
2638 state.token = display.token();
2639 state.layerStack = 456u;
2640
2641 // --------------------------------------------------------------------
2642 // Invocation
2643
2644 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2645
2646 // --------------------------------------------------------------------
2647 // Postconditions
2648
2649 // The returned flags are empty
2650 EXPECT_EQ(0u, flags);
2651
2652 // The current display state is unchanged
2653 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2654}
2655
2656TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2657 using Case = SimplePrimaryDisplayCase;
2658
2659 // --------------------------------------------------------------------
2660 // Preconditions
2661
2662 // A display is set up
2663 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2664 display.inject();
2665
2666 // The display has a layer stack set
2667 display.mutableCurrentDisplayState().layerStack = 654u;
2668
2669 // The incoming request sets a different layer stack
2670 DisplayState state;
2671 state.what = DisplayState::eLayerStackChanged;
2672 state.token = display.token();
2673 state.layerStack = 456u;
2674
2675 // --------------------------------------------------------------------
2676 // Invocation
2677
2678 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2679
2680 // --------------------------------------------------------------------
2681 // Postconditions
2682
2683 // The returned flags indicate a transaction is needed
2684 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2685
2686 // The desired display state has been set to the new value.
2687 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2688}
2689
2690TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2691 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002692 constexpr ui::Rotation initialOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002693 const Rect initialFrame = {1, 2, 3, 4};
2694 const Rect initialViewport = {5, 6, 7, 8};
2695
2696 // --------------------------------------------------------------------
2697 // Preconditions
2698
2699 // A display is set up
2700 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2701 display.inject();
2702
2703 // The current display state projection state is all set
2704 display.mutableCurrentDisplayState().orientation = initialOrientation;
2705 display.mutableCurrentDisplayState().frame = initialFrame;
2706 display.mutableCurrentDisplayState().viewport = initialViewport;
2707
2708 // The incoming request sets the same projection state
2709 DisplayState state;
2710 state.what = DisplayState::eDisplayProjectionChanged;
2711 state.token = display.token();
2712 state.orientation = initialOrientation;
2713 state.frame = initialFrame;
2714 state.viewport = initialViewport;
2715
2716 // --------------------------------------------------------------------
2717 // Invocation
2718
2719 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2720
2721 // --------------------------------------------------------------------
2722 // Postconditions
2723
2724 // The returned flags are empty
2725 EXPECT_EQ(0u, flags);
2726
2727 // The current display state is unchanged
2728 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2729
2730 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2731 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2732}
2733
2734TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2735 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002736 constexpr ui::Rotation initialOrientation = ui::ROTATION_90;
2737 constexpr ui::Rotation desiredOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002738
2739 // --------------------------------------------------------------------
2740 // Preconditions
2741
2742 // A display is set up
2743 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2744 display.inject();
2745
2746 // The current display state has an orientation set
2747 display.mutableCurrentDisplayState().orientation = initialOrientation;
2748
2749 // The incoming request sets a different orientation
2750 DisplayState state;
2751 state.what = DisplayState::eDisplayProjectionChanged;
2752 state.token = display.token();
2753 state.orientation = desiredOrientation;
2754
2755 // --------------------------------------------------------------------
2756 // Invocation
2757
2758 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2759
2760 // --------------------------------------------------------------------
2761 // Postconditions
2762
2763 // The returned flags indicate a transaction is needed
2764 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2765
2766 // The current display state has the new value.
2767 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2768}
2769
2770TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2771 using Case = SimplePrimaryDisplayCase;
2772 const Rect initialFrame = {0, 0, 0, 0};
2773 const Rect desiredFrame = {5, 6, 7, 8};
2774
2775 // --------------------------------------------------------------------
2776 // Preconditions
2777
2778 // A display is set up
2779 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2780 display.inject();
2781
2782 // The current display state does not have a frame
2783 display.mutableCurrentDisplayState().frame = initialFrame;
2784
2785 // The incoming request sets a frame
2786 DisplayState state;
2787 state.what = DisplayState::eDisplayProjectionChanged;
2788 state.token = display.token();
2789 state.frame = desiredFrame;
2790
2791 // --------------------------------------------------------------------
2792 // Invocation
2793
2794 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2795
2796 // --------------------------------------------------------------------
2797 // Postconditions
2798
2799 // The returned flags indicate a transaction is needed
2800 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2801
2802 // The current display state has the new value.
2803 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2804}
2805
2806TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2807 using Case = SimplePrimaryDisplayCase;
2808 const Rect initialViewport = {0, 0, 0, 0};
2809 const Rect desiredViewport = {5, 6, 7, 8};
2810
2811 // --------------------------------------------------------------------
2812 // Preconditions
2813
2814 // A display is set up
2815 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2816 display.inject();
2817
2818 // The current display state does not have a viewport
2819 display.mutableCurrentDisplayState().viewport = initialViewport;
2820
2821 // The incoming request sets a viewport
2822 DisplayState state;
2823 state.what = DisplayState::eDisplayProjectionChanged;
2824 state.token = display.token();
2825 state.viewport = desiredViewport;
2826
2827 // --------------------------------------------------------------------
2828 // Invocation
2829
2830 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2831
2832 // --------------------------------------------------------------------
2833 // Postconditions
2834
2835 // The returned flags indicate a transaction is needed
2836 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2837
2838 // The current display state has the new value.
2839 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2840}
2841
2842TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2843 using Case = SimplePrimaryDisplayCase;
2844 constexpr uint32_t initialWidth = 1024;
2845 constexpr uint32_t initialHeight = 768;
2846
2847 // --------------------------------------------------------------------
2848 // Preconditions
2849
2850 // A display is set up
2851 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2852 display.inject();
2853
2854 // The current display state has a size set
2855 display.mutableCurrentDisplayState().width = initialWidth;
2856 display.mutableCurrentDisplayState().height = initialHeight;
2857
2858 // The incoming request sets the same display size
2859 DisplayState state;
2860 state.what = DisplayState::eDisplaySizeChanged;
2861 state.token = display.token();
2862 state.width = initialWidth;
2863 state.height = initialHeight;
2864
2865 // --------------------------------------------------------------------
2866 // Invocation
2867
2868 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2869
2870 // --------------------------------------------------------------------
2871 // Postconditions
2872
2873 // The returned flags are empty
2874 EXPECT_EQ(0u, flags);
2875
2876 // The current display state is unchanged
2877 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2878 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2879}
2880
2881TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2882 using Case = SimplePrimaryDisplayCase;
2883 constexpr uint32_t initialWidth = 0;
2884 constexpr uint32_t desiredWidth = 1024;
2885
2886 // --------------------------------------------------------------------
2887 // Preconditions
2888
2889 // A display is set up
2890 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2891 display.inject();
2892
2893 // The display does not yet have a width
2894 display.mutableCurrentDisplayState().width = initialWidth;
2895
2896 // The incoming request sets a display width
2897 DisplayState state;
2898 state.what = DisplayState::eDisplaySizeChanged;
2899 state.token = display.token();
2900 state.width = desiredWidth;
2901
2902 // --------------------------------------------------------------------
2903 // Invocation
2904
2905 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2906
2907 // --------------------------------------------------------------------
2908 // Postconditions
2909
2910 // The returned flags indicate a transaction is needed
2911 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2912
2913 // The current display state has the new value.
2914 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2915}
2916
2917TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2918 using Case = SimplePrimaryDisplayCase;
2919 constexpr uint32_t initialHeight = 0;
2920 constexpr uint32_t desiredHeight = 768;
2921
2922 // --------------------------------------------------------------------
2923 // Preconditions
2924
2925 // A display is set up
2926 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2927 display.inject();
2928
2929 // The display does not yet have a height
2930 display.mutableCurrentDisplayState().height = initialHeight;
2931
2932 // The incoming request sets a display height
2933 DisplayState state;
2934 state.what = DisplayState::eDisplaySizeChanged;
2935 state.token = display.token();
2936 state.height = desiredHeight;
2937
2938 // --------------------------------------------------------------------
2939 // Invocation
2940
2941 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2942
2943 // --------------------------------------------------------------------
2944 // Postconditions
2945
2946 // The returned flags indicate a transaction is needed
2947 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2948
2949 // The current display state has the new value.
2950 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2951}
2952
Lloyd Pique86016da2018-03-01 16:09:38 -08002953/* ------------------------------------------------------------------------
2954 * SurfaceFlinger::onInitializeDisplays
2955 */
2956
2957TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2958 using Case = SimplePrimaryDisplayCase;
2959
2960 // --------------------------------------------------------------------
2961 // Preconditions
2962
2963 // A primary display is set up
2964 Case::Display::injectHwcDisplay(this);
2965 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2966 primaryDisplay.inject();
2967
2968 // --------------------------------------------------------------------
2969 // Call Expectations
2970
2971 // We expect the surface interceptor to possibly be used, but we treat it as
2972 // disabled since it is called as a side effect rather than directly by this
2973 // function.
2974 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2975
2976 // We expect a call to get the active display config.
2977 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2978
2979 // We expect invalidate() to be invoked once to trigger display transaction
2980 // processing.
2981 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2982
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002983 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2984
Lloyd Pique86016da2018-03-01 16:09:38 -08002985 // --------------------------------------------------------------------
2986 // Invocation
2987
2988 mFlinger.onInitializeDisplays();
2989
2990 // --------------------------------------------------------------------
2991 // Postconditions
2992
2993 // The primary display should have a current state
2994 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2995 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2996 // The layer stack state should be set to zero
2997 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2998 // The orientation state should be set to zero
Dominik Laskowski718f9602019-11-09 20:01:35 -08002999 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
Lloyd Pique86016da2018-03-01 16:09:38 -08003000
3001 // The frame state should be set to INVALID
3002 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
3003
3004 // The viewport state should be set to INVALID
3005 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
3006
3007 // The width and height should both be zero
3008 EXPECT_EQ(0u, primaryDisplayState.width);
3009 EXPECT_EQ(0u, primaryDisplayState.height);
3010
3011 // The display should be set to HWC_POWER_MODE_NORMAL
3012 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
3013 auto displayDevice = primaryDisplay.mutableDisplayDevice();
3014 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
3015
3016 // The display refresh period should be set in the frame tracker.
3017 FrameStats stats;
3018 mFlinger.getAnimFrameTracker().getStats(&stats);
3019 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
3020
3021 // The display transaction needed flag should be set.
3022 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
3023
3024 // The compositor timing should be set to default values
3025 const auto& compositorTiming = mFlinger.getCompositorTiming();
3026 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
3027 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
3028 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
3029}
3030
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003031/* ------------------------------------------------------------------------
3032 * SurfaceFlinger::setPowerModeInternal
3033 */
3034
3035// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07003036template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003037struct DozeIsSupportedVariant {
3038 static constexpr bool DOZE_SUPPORTED = true;
3039 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3040 IComposerClient::PowerMode::DOZE;
3041 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3042 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07003043
3044 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3045 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
3046 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
3047 {Hwc2::DisplayCapability::DOZE})),
3048 Return(Error::NONE)));
3049 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003050};
3051
Peiyong Lined531a32018-10-26 18:27:56 -07003052template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003053// Used when we simulate a display that does not support doze.
3054struct DozeNotSupportedVariant {
3055 static constexpr bool DOZE_SUPPORTED = false;
3056 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3057 IComposerClient::PowerMode::ON;
3058 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3059 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07003060
3061 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3062 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
3063 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
3064 Return(Error::NONE)));
3065 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003066};
3067
3068struct EventThreadBaseSupportedVariant {
3069 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
3070 // The event control thread should not be notified.
3071 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
3072
3073 // The event thread should not be notified.
3074 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
3075 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
3076 }
3077};
3078
3079struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
3080 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3081 // These calls are only expected for the primary display.
3082
3083 // Instead expect no calls.
3084 setupEventAndEventControlThreadNoCallExpectations(test);
3085 }
3086
3087 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3088 // These calls are only expected for the primary display.
3089
3090 // Instead expect no calls.
3091 setupEventAndEventControlThreadNoCallExpectations(test);
3092 }
3093};
3094
3095struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
3096 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3097 // The event control thread should be notified to enable vsyncs
3098 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
3099
3100 // The event thread should be notified that the screen was acquired.
3101 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
3102 }
3103
3104 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3105 // There should be a call to setVsyncEnabled(false)
3106 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
3107
3108 // The event thread should not be notified that the screen was released.
3109 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
3110 }
3111};
3112
Lloyd Pique41be5d22018-06-21 13:11:48 -07003113struct DispSyncIsSupportedVariant {
3114 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique41be5d22018-06-21 13:11:48 -07003115 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
3116 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
3117 }
3118
3119 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
3120 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
3121 }
3122};
3123
3124struct DispSyncNotSupportedVariant {
3125 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3126
3127 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
3128};
3129
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003130// --------------------------------------------------------------------
3131// Note:
3132//
3133// There are a large number of transitions we could test, however we only test a
3134// selected subset which provides complete test coverage of the implementation.
3135// --------------------------------------------------------------------
3136
3137template <int initialPowerMode, int targetPowerMode>
3138struct TransitionVariantCommon {
3139 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
3140 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
3141
3142 static void verifyPostconditions(DisplayTransactionTest*) {}
3143};
3144
3145struct TransitionOffToOnVariant
3146 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
3147 template <typename Case>
3148 static void setupCallExpectations(DisplayTransactionTest* test) {
3149 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3150 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003151 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003152 Case::setupRepaintEverythingCallExpectations(test);
3153 }
3154
3155 static void verifyPostconditions(DisplayTransactionTest* test) {
3156 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3157 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3158 }
3159};
3160
3161struct TransitionOffToDozeSuspendVariant
3162 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
3163 template <typename Case>
3164 static void setupCallExpectations(DisplayTransactionTest* test) {
3165 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3166 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3167 Case::setupRepaintEverythingCallExpectations(test);
3168 }
3169
3170 static void verifyPostconditions(DisplayTransactionTest* test) {
3171 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3172 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3173 }
3174};
3175
3176struct TransitionOnToOffVariant
3177 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
3178 template <typename Case>
3179 static void setupCallExpectations(DisplayTransactionTest* test) {
3180 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003181 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003182 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3183 }
3184
3185 static void verifyPostconditions(DisplayTransactionTest* test) {
3186 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3187 }
3188};
3189
3190struct TransitionDozeSuspendToOffVariant
3191 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
3192 template <typename Case>
3193 static void setupCallExpectations(DisplayTransactionTest* test) {
3194 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3195 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3196 }
3197
3198 static void verifyPostconditions(DisplayTransactionTest* test) {
3199 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3200 }
3201};
3202
3203struct TransitionOnToDozeVariant
3204 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
3205 template <typename Case>
3206 static void setupCallExpectations(DisplayTransactionTest* test) {
3207 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3208 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3209 }
3210};
3211
3212struct TransitionDozeSuspendToDozeVariant
3213 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
3214 template <typename Case>
3215 static void setupCallExpectations(DisplayTransactionTest* test) {
3216 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003217 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003218 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3219 }
3220};
3221
3222struct TransitionDozeToOnVariant
3223 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
3224 template <typename Case>
3225 static void setupCallExpectations(DisplayTransactionTest* test) {
3226 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3227 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3228 }
3229};
3230
3231struct TransitionDozeSuspendToOnVariant
3232 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
3233 template <typename Case>
3234 static void setupCallExpectations(DisplayTransactionTest* test) {
3235 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003236 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003237 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3238 }
3239};
3240
3241struct TransitionOnToDozeSuspendVariant
3242 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
3243 template <typename Case>
3244 static void setupCallExpectations(DisplayTransactionTest* test) {
3245 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003246 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003247 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3248 }
3249};
3250
3251struct TransitionOnToUnknownVariant
3252 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
3253 template <typename Case>
3254 static void setupCallExpectations(DisplayTransactionTest* test) {
3255 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
3256 Case::setupNoComposerPowerModeCallExpectations(test);
3257 }
3258};
3259
3260// --------------------------------------------------------------------
3261// Note:
3262//
3263// Rather than testing the cartesian product of of
3264// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3265// display type, and the other for another display type.
3266// --------------------------------------------------------------------
3267
3268template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003269 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003270struct DisplayPowerCase {
3271 using Display = DisplayVariant;
3272 using Doze = DozeVariant;
3273 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003274 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003275 using Transition = TransitionVariant;
3276
3277 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003278 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003279 auto display = Display::makeFakeExistingDisplayInjector(test);
3280 display.inject();
3281 display.mutableDisplayDevice()->setPowerMode(mode);
3282 return display;
3283 }
3284
3285 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003286 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003287 }
3288
3289 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3290 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3291 }
3292
3293 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3294 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3295 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3296 }
3297
3298 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3299 IComposerClient::PowerMode mode) {
3300 // Any calls to get the active config will return a default value.
3301 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3302 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3303 Return(Error::NONE)));
3304
3305 // Any calls to get whether the display supports dozing will return the value set by the
3306 // policy variant.
3307 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3308 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3309
3310 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3311 }
3312
3313 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3314 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3315 }
3316};
3317
3318// A sample configuration for the primary display.
3319// In addition to having event thread support, we emulate doze support.
3320template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003321using PrimaryDisplayPowerCase =
3322 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3323 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3324 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003325
3326// A sample configuration for the external display.
3327// In addition to not having event thread support, we emulate not having doze
3328// support.
3329template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003330using ExternalDisplayPowerCase =
3331 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3332 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3333 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003334
3335class SetPowerModeInternalTest : public DisplayTransactionTest {
3336public:
3337 template <typename Case>
3338 void transitionDisplayCommon();
3339};
3340
3341template <int PowerMode>
3342struct PowerModeInitialVSyncEnabled : public std::false_type {};
3343
3344template <>
3345struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3346
3347template <>
3348struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3349
3350template <typename Case>
3351void SetPowerModeInternalTest::transitionDisplayCommon() {
3352 // --------------------------------------------------------------------
3353 // Preconditions
3354
Peiyong Lined531a32018-10-26 18:27:56 -07003355 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003356 auto display =
3357 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3358 Case::setInitialPrimaryHWVsyncEnabled(this,
3359 PowerModeInitialVSyncEnabled<
3360 Case::Transition::INITIAL_POWER_MODE>::value);
3361
3362 // --------------------------------------------------------------------
3363 // Call Expectations
3364
3365 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3366 Case::Transition::template setupCallExpectations<Case>(this);
3367
3368 // --------------------------------------------------------------------
3369 // Invocation
3370
3371 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3372 Case::Transition::TARGET_POWER_MODE);
3373
3374 // --------------------------------------------------------------------
3375 // Postconditions
3376
3377 Case::Transition::verifyPostconditions(this);
3378}
3379
3380TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3381 using Case = SimplePrimaryDisplayCase;
3382
3383 // --------------------------------------------------------------------
3384 // Preconditions
3385
3386 // A primary display device is set up
3387 Case::Display::injectHwcDisplay(this);
3388 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3389 display.inject();
3390
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003391 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003392 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3393
3394 // --------------------------------------------------------------------
3395 // Invocation
3396
3397 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3398
3399 // --------------------------------------------------------------------
3400 // Postconditions
3401
3402 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3403}
3404
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003405TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003406 using Case = HwcVirtualDisplayCase;
3407
3408 // --------------------------------------------------------------------
3409 // Preconditions
3410
Dominik Laskowski075d3172018-05-24 15:50:06 -07003411 // Insert display data so that the HWC thinks it created the virtual display.
3412 const auto displayId = Case::Display::DISPLAY_ID::get();
3413 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003414 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003415
3416 // A virtual display device is set up
3417 Case::Display::injectHwcDisplay(this);
3418 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3419 display.inject();
3420
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003421 // The display is set to HWC_POWER_MODE_NORMAL
3422 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003423
3424 // --------------------------------------------------------------------
3425 // Invocation
3426
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003427 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003428
3429 // --------------------------------------------------------------------
3430 // Postconditions
3431
3432 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3433}
3434
3435TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3436 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3437}
3438
3439TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3440 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3441}
3442
3443TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3444 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3445}
3446
3447TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3448 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3449}
3450
3451TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3452 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3453}
3454
3455TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3456 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3457}
3458
3459TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3460 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3461}
3462
3463TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3464 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3465}
3466
3467TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3468 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3469}
3470
3471TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3472 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3473}
3474
3475TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3476 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3477}
3478
3479TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3480 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3481}
3482
3483TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3484 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3485}
3486
3487TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3488 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3489}
3490
3491TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3492 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3493}
3494
3495TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3496 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3497}
3498
3499TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3500 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3501}
3502
3503TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3504 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3505}
3506
3507TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3508 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3509}
3510
3511TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3512 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3513}
3514
Lloyd Piquef58625d2017-12-19 13:22:33 -08003515} // namespace
3516} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08003517
3518// TODO(b/129481165): remove the #pragma below and fix conversion issues
3519#pragma clang diagnostic pop // ignored "-Wconversion"