blob: 19f308b62aa3c9e4c5260532d42d6443ab5cad64 [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
17#undef LOG_TAG
18#define LOG_TAG "LibSurfaceFlingerUnittests"
19
Dominik Laskowski075d3172018-05-24 15:50:06 -070020#include <type_traits>
21
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070022#include <compositionengine/Display.h>
23#include <compositionengine/DisplayColorProfile.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070024#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080025#include <gmock/gmock.h>
26#include <gtest/gtest.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080027#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070028#include <renderengine/mock/RenderEngine.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070029#include <ui/DebugUtils.h>
Dominik Laskowski075d3172018-05-24 15:50:06 -070030
31#include "DisplayIdentificationTest.h"
Ana Krulecafb45842019-02-13 13:33:03 -080032#include "TestableScheduler.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080033#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080034#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070035#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080036#include "mock/MockEventControlThread.h"
37#include "mock/MockEventThread.h"
38#include "mock/MockMessageQueue.h"
39#include "mock/MockNativeWindowSurface.h"
40#include "mock/MockSurfaceInterceptor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080041#include "mock/gui/MockGraphicBufferConsumer.h"
42#include "mock/gui/MockGraphicBufferProducer.h"
43#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080044
45namespace android {
46namespace {
47
Lloyd Piquee39cad22017-12-20 17:01:29 -080048using testing::_;
Lloyd Piquee39cad22017-12-20 17:01:29 -080049using testing::DoAll;
50using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080051using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080052using testing::Return;
53using testing::SetArgPointee;
54
Lloyd Piqued883d5a2018-04-27 19:32:30 -070055using android::Hwc2::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080056using android::Hwc2::Error;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070057using android::Hwc2::Hdr;
Lloyd Piquee39cad22017-12-20 17:01:29 -080058using android::Hwc2::IComposer;
59using android::Hwc2::IComposerClient;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070060using android::Hwc2::PerFrameMetadataKey;
61using android::Hwc2::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080062
Lloyd Piquec11e0d32018-01-22 18:44:59 -080063using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
64using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080065using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080066using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080067
Lloyd Piquec11e0d32018-01-22 18:44:59 -080068constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080069constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080070constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080071
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080072constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value
73
Lloyd Piquec11e0d32018-01-22 18:44:59 -080074/* ------------------------------------------------------------------------
75 * Boolean avoidance
76 *
77 * To make calls and template instantiations more readable, we define some
78 * local enums along with an implicit bool conversion.
79 */
80
81#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
82
Lloyd Piquec11e0d32018-01-22 18:44:59 -080083BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -070084BOOL_SUBSTITUTE(Critical);
85BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080086BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -070087BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080088
89/* ------------------------------------------------------------------------
90 *
91 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080092
Lloyd Piquef58625d2017-12-19 13:22:33 -080093class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -080094public:
Lloyd Piquef58625d2017-12-19 13:22:33 -080095 DisplayTransactionTest();
96 ~DisplayTransactionTest() override;
97
Ana Krulecafb45842019-02-13 13:33:03 -080098 void setupScheduler();
99
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800100 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800101 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800102
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800103 void injectMockComposer(int virtualDisplayCount);
104 void injectFakeBufferQueueFactory();
105 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800106
107 // --------------------------------------------------------------------
108 // Postcondition helpers
109
Dominik Laskowski075d3172018-05-24 15:50:06 -0700110 bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800111 bool hasTransactionFlagSet(int flag);
112 bool hasDisplayDevice(sp<IBinder> displayToken);
113 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
114 bool hasCurrentDisplayState(sp<IBinder> displayToken);
115 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
116 bool hasDrawingDisplayState(sp<IBinder> displayToken);
117 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
118
119 // --------------------------------------------------------------------
120 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800121
Ana Krulecafb45842019-02-13 13:33:03 -0800122 TestableScheduler* mScheduler;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800123 TestableSurfaceFlinger mFlinger;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800124 mock::EventThread* mEventThread = new mock::EventThread();
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800125 mock::EventThread* mSFEventThread = new mock::EventThread();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800126 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
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();
Lloyd Pique41be5d22018-06-21 13:11:48 -0700137 mock::DispSync* mPrimaryDispSync = new mock::DispSync();
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800138
139 // These mocks are created only when expected to be created via a factory.
140 sp<mock::GraphicBufferConsumer> mConsumer;
141 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700142 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800143};
144
145DisplayTransactionTest::DisplayTransactionTest() {
146 const ::testing::TestInfo* const test_info =
147 ::testing::UnitTest::GetInstance()->current_test_info();
148 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800149
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800150 // Default to no wide color display support configured
151 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700152 mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800153 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
154
155 // Default to using HWC virtual displays
156 mFlinger.mutableUseHwcVirtualDisplays() = true;
157
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800158 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
159 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
160 });
161
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800162 mFlinger.setCreateNativeWindowSurface([](auto) {
163 ADD_FAILURE() << "Unexpected request to create a native window surface.";
164 return nullptr;
165 });
166
Ana Krulecafb45842019-02-13 13:33:03 -0800167 setupScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800168 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700169 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800170 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800171
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800172 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800173}
174
175DisplayTransactionTest::~DisplayTransactionTest() {
176 const ::testing::TestInfo* const test_info =
177 ::testing::UnitTest::GetInstance()->current_test_info();
178 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
179}
180
Ana Krulecafb45842019-02-13 13:33:03 -0800181void DisplayTransactionTest::setupScheduler() {
182 mScheduler = new TestableScheduler();
183 mScheduler->mutableEventControlThread().reset(mEventControlThread);
184 mScheduler->mutablePrimaryDispSync().reset(mPrimaryDispSync);
185 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
186 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
187
188 sp<Scheduler::ConnectionHandle> sfConnectionHandle =
189 mScheduler->addConnection(std::unique_ptr<EventThread>(mSFEventThread));
190 mFlinger.mutableSfConnectionHandle() = std::move(sfConnectionHandle);
191 sp<Scheduler::ConnectionHandle> appConnectionHandle =
192 mScheduler->addConnection(std::unique_ptr<EventThread>(mEventThread));
193 mFlinger.mutableAppConnectionHandle() = std::move(appConnectionHandle);
194 mFlinger.mutableScheduler().reset(mScheduler);
195}
196
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800197void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
198 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800199 EXPECT_CALL(*mComposer, getCapabilities())
200 .WillOnce(Return(std::vector<IComposer::Capability>()));
201 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
202 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800203
Lloyd Piquee39cad22017-12-20 17:01:29 -0800204 Mock::VerifyAndClear(mComposer);
205}
206
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800207void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800208 // This setup is only expected once per test.
209 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
210
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800211 mConsumer = new mock::GraphicBufferConsumer();
212 mProducer = new mock::GraphicBufferProducer();
213
214 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
215 *outProducer = mProducer;
216 *outConsumer = mConsumer;
217 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800218}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800219
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800220void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800221 // This setup is only expected once per test.
222 ASSERT_TRUE(mNativeWindowSurface == nullptr);
223
Lloyd Pique22098362018-09-13 11:46:49 -0700224 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800225
Lloyd Pique22098362018-09-13 11:46:49 -0700226 mFlinger.setCreateNativeWindowSurface([this](auto) {
227 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
228 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800229}
230
Dominik Laskowski075d3172018-05-24 15:50:06 -0700231bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) {
232 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800233}
234
235bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
236 return mFlinger.mutableTransactionFlags() & flag;
237}
238
239bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700240 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800241}
242
243sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700244 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800245}
246
247bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
248 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
249}
250
251const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
252 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
253}
254
255bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
256 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
257}
258
259const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
260 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
261}
262
263/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800264 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800265 */
266
Dominik Laskowski075d3172018-05-24 15:50:06 -0700267template <typename PhysicalDisplay>
268struct PhysicalDisplayId {};
269
Dominik Laskowski34157762018-10-31 13:07:19 -0700270template <DisplayId::Type displayId>
271using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700272
273struct NoDisplayId {};
274
275template <typename>
276struct IsPhysicalDisplayId : std::bool_constant<false> {};
277
278template <typename PhysicalDisplay>
279struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
280
281template <typename>
282struct DisplayIdGetter;
283
284template <typename PhysicalDisplay>
285struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
286 static std::optional<DisplayId> get() {
287 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
288 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
289 ? HWC_DISPLAY_PRIMARY
290 : HWC_DISPLAY_EXTERNAL);
291 }
292
293 const auto info =
294 parseDisplayIdentificationData(PhysicalDisplay::PORT,
295 PhysicalDisplay::GET_IDENTIFICATION_DATA());
296 return info ? std::make_optional(info->id) : std::nullopt;
297 }
298};
299
Dominik Laskowski34157762018-10-31 13:07:19 -0700300template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700301struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700302 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700303};
304
305template <>
306struct DisplayIdGetter<NoDisplayId> {
307 static std::optional<DisplayId> get() { return {}; }
308};
309
310// DisplayIdType can be:
311// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
312// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
313// 3) NoDisplayId for virtual display without HWC backing.
314template <typename DisplayIdType, int width, int height, Critical critical, Async async,
315 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800316struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700317 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
318
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800319 // The display width and height
320 static constexpr int WIDTH = width;
321 static constexpr int HEIGHT = height;
322
323 static constexpr int GRALLOC_USAGE = grallocUsage;
324
Dominik Laskowski075d3172018-05-24 15:50:06 -0700325 // Whether the display is virtual or physical
326 static constexpr Virtual VIRTUAL =
327 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800328
329 // When creating native window surfaces for the framebuffer, whether those should be critical
330 static constexpr Critical CRITICAL = critical;
331
332 // When creating native window surfaces for the framebuffer, whether those should be async
333 static constexpr Async ASYNC = async;
334
335 // Whether the display should be treated as secure
336 static constexpr Secure SECURE = secure;
337
Dominik Laskowski075d3172018-05-24 15:50:06 -0700338 // Whether the display is primary
339 static constexpr Primary PRIMARY = primary;
340
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800341 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700342 auto injector =
343 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(),
344 static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY));
345
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800346 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700347 injector.setNativeWindow(test->mNativeWindow);
348
349 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800350 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700351 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
352 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
353 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
354 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800355 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
356 .WillRepeatedly(Return(0));
357 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
358 .WillRepeatedly(Return(0));
359 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
360 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800361 return injector;
362 }
363
364 // Called by tests to set up any native window creation call expectations.
365 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
366 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
367 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800368
Alec Mouriba013fa2018-10-16 12:43:11 -0700369 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
370 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
371 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
372 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800373 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
374 .WillRepeatedly(Return(0));
375 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
376 .WillRepeatedly(Return(0));
377 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
378 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800379 }
380
381 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
382 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
383 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
384 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
385 .WillRepeatedly(Return(NO_ERROR));
386 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
387 .WillRepeatedly(Return(NO_ERROR));
388 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
389 .WillRepeatedly(Return(NO_ERROR));
390 }
391
392 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
393 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
394 }
395};
396
Dominik Laskowski075d3172018-05-24 15:50:06 -0700397template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
398 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800399struct HwcDisplayVariant {
400 // The display id supplied by the HWC
401 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
402
403 // The HWC display type
404 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
405
406 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700407 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800408
409 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
410 HWC2::Connection connection) {
411 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
412 HotplugEvent{HWC_DISPLAY_ID, connection});
413 }
414
415 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800416 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700417 const auto displayId = DisplayVariant::DISPLAY_ID::get();
418 ASSERT_TRUE(displayId);
419 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
420 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800421 .setHwcDisplayId(HWC_DISPLAY_ID)
422 .setWidth(DisplayVariant::WIDTH)
423 .setHeight(DisplayVariant::HEIGHT)
424 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
425 .inject(&test->mFlinger, test->mComposer);
426 }
427
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800428 // Called by tests to inject a HWC display setup
429 static void injectHwcDisplay(DisplayTransactionTest* test) {
430 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
431 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
432 Return(Error::NONE)));
433 injectHwcDisplayWithNoDefaultCapabilities(test);
434 }
435
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800436 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
437 EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _))
438 .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>(
439 HWC_DISPLAY_TYPE)),
440 Return(Error::NONE)));
441 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
442 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
443 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
444 Return(Error::NONE)));
445 EXPECT_CALL(*test->mComposer,
446 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
447 IComposerClient::Attribute::WIDTH, _))
448 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
449 EXPECT_CALL(*test->mComposer,
450 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
451 IComposerClient::Attribute::HEIGHT, _))
452 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
453 EXPECT_CALL(*test->mComposer,
454 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
455 IComposerClient::Attribute::VSYNC_PERIOD, _))
456 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
457 EXPECT_CALL(*test->mComposer,
458 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
459 IComposerClient::Attribute::DPI_X, _))
460 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
461 EXPECT_CALL(*test->mComposer,
462 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
463 IComposerClient::Attribute::DPI_Y, _))
464 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800465 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
466 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
467 Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700468
469 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
470 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
471 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
472 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
473 Return(Error::NONE)));
474 } else {
475 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
476 .WillOnce(Return(Error::UNSUPPORTED));
477 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800478 }
479
480 // Called by tests to set up HWC call expectations
481 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
482 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700483 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800484 }
485};
486
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800487// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
488constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
489 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
490
Dominik Laskowski075d3172018-05-24 15:50:06 -0700491template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800492 Critical critical>
493struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700494 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
495 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
496 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
497 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
498 critical, Async::FALSE, Secure::TRUE,
499 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
500 PhysicalDisplay> {};
501
502template <bool hasIdentificationData>
503struct PrimaryDisplay {
504 static constexpr Primary PRIMARY = Primary::TRUE;
505 static constexpr uint8_t PORT = 255;
506 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
507 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
508};
509
510template <bool hasIdentificationData>
511struct ExternalDisplay {
512 static constexpr Primary PRIMARY = Primary::FALSE;
513 static constexpr uint8_t PORT = 254;
514 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
515 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
516};
517
518struct TertiaryDisplay {
519 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800520 static constexpr uint8_t PORT = 253;
521 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700522};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800523
524// A primary display is a physical display that is critical
525using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700526 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800527
528// An external display is physical display that is not critical.
529using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700530 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800531
532using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700533 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800534
535// A virtual display not supported by the HWC.
536constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
537
538template <int width, int height, Secure secure>
539struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700540 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
541 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
542 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
543 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
544
545 static void injectHwcDisplay(DisplayTransactionTest*) {}
546
547 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
548 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
549 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800550
551 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
552 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
553 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
554 }
555};
556
557// A virtual display supported by the HWC.
558constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
559
560template <int width, int height, Secure secure>
561struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700562 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
563 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
564 HwcDisplayVariant<
565 1010, HWC2::DisplayType::Virtual,
566 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
567 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
568 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
569 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800570 using Self = HwcVirtualDisplayVariant<width, height, secure>;
571
572 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
573 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
574 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
575 }
576
577 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
578 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
579 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
580 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
581 }
582};
583
584// For this variant, SurfaceFlinger should not configure itself with wide
585// display support, so the display should not be configured for wide-color
586// support.
587struct WideColorSupportNotConfiguredVariant {
588 static constexpr bool WIDE_COLOR_SUPPORTED = false;
589
590 static void injectConfigChange(DisplayTransactionTest* test) {
591 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700592 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800593 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
594 }
595
596 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
597 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
598 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
599 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
600 }
601};
602
603// For this variant, SurfaceFlinger should configure itself with wide display
604// support, and the display should respond with an non-empty list of supported
605// color modes. Wide-color support should be configured.
606template <typename Display>
607struct WideColorP3ColorimetricSupportedVariant {
608 static constexpr bool WIDE_COLOR_SUPPORTED = true;
609
610 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700611 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800612 test->mFlinger.mutableHasWideColorDisplay() = true;
613 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
614 }
615
616 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800617 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
618
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800619 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
620 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
621 Return(Error::NONE)));
622 EXPECT_CALL(*test->mComposer,
623 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
624 .WillOnce(DoAll(SetArgPointee<2>(
625 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
626 Return(Error::NONE)));
627 EXPECT_CALL(*test->mComposer,
628 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
629 RenderIntent::COLORIMETRIC))
630 .WillOnce(Return(Error::NONE));
631 }
632};
633
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800634// For this variant, SurfaceFlinger should configure itself with wide display
635// support, but the display should respond with an empty list of supported color
636// modes. Wide-color support for the display should not be configured.
637template <typename Display>
638struct WideColorNotSupportedVariant {
639 static constexpr bool WIDE_COLOR_SUPPORTED = false;
640
641 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700642 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800643 test->mFlinger.mutableHasWideColorDisplay() = true;
644 }
645
646 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
647 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
648 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700649 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800650 }
651};
652
653// For this variant, the display is not a HWC display, so no HDR support should
654// be configured.
655struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800656 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800657 static constexpr bool HDR10_SUPPORTED = false;
658 static constexpr bool HDR_HLG_SUPPORTED = false;
659 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
660 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
661 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
662 }
663};
664
Valerie Haue9e843a2018-12-18 13:39:23 -0800665template <typename Display>
666struct Hdr10PlusSupportedVariant {
667 static constexpr bool HDR10_PLUS_SUPPORTED = true;
668 static constexpr bool HDR10_SUPPORTED = true;
669 static constexpr bool HDR_HLG_SUPPORTED = false;
670 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
671 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
672 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
673 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
674 Hdr::HDR10_PLUS,
675 Hdr::HDR10,
676 })),
677 Return(Error::NONE)));
678 }
679};
680
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800681// For this variant, the composer should respond with a non-empty list of HDR
682// modes containing HDR10, so HDR10 support should be configured.
683template <typename Display>
684struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800685 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800686 static constexpr bool HDR10_SUPPORTED = true;
687 static constexpr bool HDR_HLG_SUPPORTED = false;
688 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
689 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
690 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
691 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
692 Return(Error::NONE)));
693 }
694};
695
696// For this variant, the composer should respond with a non-empty list of HDR
697// modes containing HLG, so HLG support should be configured.
698template <typename Display>
699struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800700 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800701 static constexpr bool HDR10_SUPPORTED = false;
702 static constexpr bool HDR_HLG_SUPPORTED = true;
703 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
704 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
705 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
706 .WillOnce(
707 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
708 }
709};
710
711// For this variant, the composer should respond with a non-empty list of HDR
712// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
713template <typename Display>
714struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800715 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800716 static constexpr bool HDR10_SUPPORTED = false;
717 static constexpr bool HDR_HLG_SUPPORTED = false;
718 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
719 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
720 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
721 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
722 Return(Error::NONE)));
723 }
724};
725
726// For this variant, the composer should respond with am empty list of HDR
727// modes, so no HDR support should be configured.
728template <typename Display>
729struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800730 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800731 static constexpr bool HDR10_SUPPORTED = false;
732 static constexpr bool HDR_HLG_SUPPORTED = false;
733 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
734 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
735 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
736 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
737 }
738};
739
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700740struct NonHwcPerFrameMetadataSupportVariant {
741 static constexpr int PER_FRAME_METADATA_KEYS = 0;
742 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800743 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700744 }
745};
746
747template <typename Display>
748struct NoPerFrameMetadataSupportVariant {
749 static constexpr int PER_FRAME_METADATA_KEYS = 0;
750 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800751 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
752 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700753 }
754};
755
756template <typename Display>
757struct Smpte2086PerFrameMetadataSupportVariant {
758 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
759 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800760 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
761 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800762 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
763 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
764 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
765 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
766 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
767 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
768 PerFrameMetadataKey::WHITE_POINT_X,
769 PerFrameMetadataKey::WHITE_POINT_Y,
770 PerFrameMetadataKey::MAX_LUMINANCE,
771 PerFrameMetadataKey::MIN_LUMINANCE,
772 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700773 }
774};
775
776template <typename Display>
777struct Cta861_3_PerFrameMetadataSupportVariant {
778 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
779 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800780 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
781 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800782 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
783 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
784 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700785 }
786};
787
Valerie Haue9e843a2018-12-18 13:39:23 -0800788template <typename Display>
789struct Hdr10_Plus_PerFrameMetadataSupportVariant {
790 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
791 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
792 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
793 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
794 PerFrameMetadataKey::HDR10_PLUS_SEI,
795 })));
796 }
797};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800798/* ------------------------------------------------------------------------
799 * Typical display configurations to test
800 */
801
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700802template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
803 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800804struct Case {
805 using Display = DisplayPolicy;
806 using WideColorSupport = WideColorSupportPolicy;
807 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700808 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800809};
810
811using SimplePrimaryDisplayCase =
812 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700813 HdrNotSupportedVariant<PrimaryDisplayVariant>,
814 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800815using SimpleExternalDisplayCase =
816 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700817 HdrNotSupportedVariant<ExternalDisplayVariant>,
818 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800819using SimpleTertiaryDisplayCase =
820 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700821 HdrNotSupportedVariant<TertiaryDisplayVariant>,
822 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800823using NonHwcVirtualDisplayCase =
824 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700825 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
826 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800827using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
828using HwcVirtualDisplayCase =
829 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700830 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800831 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800832using WideColorP3ColorimetricDisplayCase =
833 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700834 HdrNotSupportedVariant<PrimaryDisplayVariant>,
835 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800836using Hdr10PlusDisplayCase =
837 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
838 Hdr10SupportedVariant<PrimaryDisplayVariant>,
839 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800840using Hdr10DisplayCase =
841 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700842 Hdr10SupportedVariant<PrimaryDisplayVariant>,
843 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800844using HdrHlgDisplayCase =
845 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700846 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
847 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800848using HdrDolbyVisionDisplayCase =
849 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700850 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
851 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
852using HdrSmpte2086DisplayCase =
853 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
854 HdrNotSupportedVariant<PrimaryDisplayVariant>,
855 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
856using HdrCta861_3_DisplayCase =
857 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
858 HdrNotSupportedVariant<PrimaryDisplayVariant>,
859 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700860
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800861/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800862 *
863 * SurfaceFlinger::onHotplugReceived
864 */
865
866TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
867 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700868 constexpr hwc2_display_t hwcDisplayId1 = 456;
869 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800870
871 // --------------------------------------------------------------------
872 // Preconditions
873
874 // Set the current sequence id for accepted events
875 mFlinger.mutableComposerSequenceId() = currentSequenceId;
876
877 // Set the main thread id so that the current thread does not appear to be
878 // the main thread.
879 mFlinger.mutableMainThreadId() = std::thread::id();
880
881 // --------------------------------------------------------------------
882 // Call Expectations
883
884 // We expect invalidate() to be invoked once to trigger display transaction
885 // processing.
886 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
887
888 // --------------------------------------------------------------------
889 // Invocation
890
891 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700892 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
893 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800894
895 // --------------------------------------------------------------------
896 // Postconditions
897
898 // The display transaction needed flag should be set.
899 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
900
901 // All events should be in the pending event queue.
902 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
903 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700904 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800905 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700906 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800907 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
908}
909
910TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
911 constexpr int currentSequenceId = 123;
912 constexpr int otherSequenceId = 321;
913 constexpr hwc2_display_t displayId = 456;
914
915 // --------------------------------------------------------------------
916 // Preconditions
917
918 // Set the current sequence id for accepted events
919 mFlinger.mutableComposerSequenceId() = currentSequenceId;
920
921 // Set the main thread id so that the current thread does not appear to be
922 // the main thread.
923 mFlinger.mutableMainThreadId() = std::thread::id();
924
925 // --------------------------------------------------------------------
926 // Call Expectations
927
928 // We do not expect any calls to invalidate().
929 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
930
931 // --------------------------------------------------------------------
932 // Invocation
933
934 // Call with an unexpected sequence id
935 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
936
937 // --------------------------------------------------------------------
938 // Postconditions
939
940 // The display transaction needed flag should not be set
941 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
942
943 // There should be no pending events
944 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
945}
946
947TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
948 constexpr int currentSequenceId = 123;
949 constexpr hwc2_display_t displayId1 = 456;
950
951 // --------------------------------------------------------------------
952 // Note:
953 // --------------------------------------------------------------------
954 // This test case is a bit tricky. We want to verify that
955 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
956 // don't really want to provide coverage for everything the later function
957 // does as there are specific tests for it.
958 // --------------------------------------------------------------------
959
960 // --------------------------------------------------------------------
961 // Preconditions
962
963 // Set the current sequence id for accepted events
964 mFlinger.mutableComposerSequenceId() = currentSequenceId;
965
966 // Set the main thread id so that the current thread does appear to be the
967 // main thread.
968 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
969
970 // --------------------------------------------------------------------
971 // Call Expectations
972
973 // We expect invalidate() to be invoked once to trigger display transaction
974 // processing.
975 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
976
977 // --------------------------------------------------------------------
978 // Invocation
979
980 // Simulate a disconnect on a display id that is not connected. This should
981 // be enqueued by onHotplugReceived(), and dequeued by
982 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
983 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
984
985 // --------------------------------------------------------------------
986 // Postconditions
987
988 // The display transaction needed flag should be set.
989 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
990
991 // There should be no event queued on return, as it should have been
992 // processed.
993 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
994}
995
996/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -0800997 * SurfaceFlinger::createDisplay
998 */
999
1000TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1001 const String8 name("virtual.test");
1002
1003 // --------------------------------------------------------------------
1004 // Call Expectations
1005
1006 // The call should notify the interceptor that a display was created.
1007 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1008
1009 // --------------------------------------------------------------------
1010 // Invocation
1011
1012 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1013
1014 // --------------------------------------------------------------------
1015 // Postconditions
1016
1017 // The display should have been added to the current state
1018 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1019 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001020 EXPECT_TRUE(display.isVirtual());
1021 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001022 EXPECT_EQ(name.string(), display.displayName);
1023
1024 // --------------------------------------------------------------------
1025 // Cleanup conditions
1026
1027 // Destroying the display invalidates the display state.
1028 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1029}
1030
1031TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1032 const String8 name("virtual.test");
1033
1034 // --------------------------------------------------------------------
1035 // Call Expectations
1036
1037 // The call should notify the interceptor that a display was created.
1038 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1039
1040 // --------------------------------------------------------------------
1041 // Invocation
1042
1043 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1044
1045 // --------------------------------------------------------------------
1046 // Postconditions
1047
1048 // The display should have been added to the current state
1049 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1050 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001051 EXPECT_TRUE(display.isVirtual());
1052 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001053 EXPECT_EQ(name.string(), display.displayName);
1054
1055 // --------------------------------------------------------------------
1056 // Cleanup conditions
1057
1058 // Destroying the display invalidates the display state.
1059 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1060}
1061
1062/* ------------------------------------------------------------------------
1063 * SurfaceFlinger::destroyDisplay
1064 */
1065
1066TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1067 using Case = NonHwcVirtualDisplayCase;
1068
1069 // --------------------------------------------------------------------
1070 // Preconditions
1071
1072 // A virtual display exists
1073 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1074 existing.inject();
1075
1076 // --------------------------------------------------------------------
1077 // Call Expectations
1078
1079 // The call should notify the interceptor that a display was created.
1080 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1081
1082 // Destroying the display invalidates the display state.
1083 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1084
1085 // --------------------------------------------------------------------
1086 // Invocation
1087
1088 mFlinger.destroyDisplay(existing.token());
1089
1090 // --------------------------------------------------------------------
1091 // Postconditions
1092
1093 // The display should have been removed from the current state
1094 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1095
1096 // Ths display should still exist in the drawing state
1097 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1098
1099 // The display transaction needed flasg should be set
1100 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1101}
1102
1103TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1104 // --------------------------------------------------------------------
1105 // Preconditions
1106
1107 sp<BBinder> displayToken = new BBinder();
1108
1109 // --------------------------------------------------------------------
1110 // Invocation
1111
1112 mFlinger.destroyDisplay(displayToken);
1113}
1114
1115/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001116 * SurfaceFlinger::resetDisplayState
1117 */
1118
1119TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1120 using Case = NonHwcVirtualDisplayCase;
1121
1122 // --------------------------------------------------------------------
1123 // Preconditions
1124
1125 // vsync is enabled and available
Ana Krulecafb45842019-02-13 13:33:03 -08001126 mScheduler->mutablePrimaryHWVsyncEnabled() = true;
1127 mScheduler->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001128
1129 // A display exists
1130 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1131 existing.inject();
1132
1133 // --------------------------------------------------------------------
1134 // Call Expectations
1135
1136 // The call disable vsyncs
1137 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1138
Lloyd Pique41be5d22018-06-21 13:11:48 -07001139 // The call ends any display resyncs
1140 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1141
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001142 // --------------------------------------------------------------------
1143 // Invocation
1144
1145 mFlinger.resetDisplayState();
1146
1147 // --------------------------------------------------------------------
1148 // Postconditions
1149
1150 // vsyncs should be off and not available.
Ana Krulecafb45842019-02-13 13:33:03 -08001151 EXPECT_FALSE(mScheduler->mutablePrimaryHWVsyncEnabled());
1152 EXPECT_FALSE(mScheduler->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001153
1154 // The display should have been removed from the display map.
1155 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1156
1157 // The display should still exist in the current state
1158 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1159
1160 // The display should have been removed from the drawing state
1161 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1162}
1163
1164/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001165 * DisplayDevice::GetBestColorMode
1166 */
1167class GetBestColorModeTest : public DisplayTransactionTest {
1168public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001169 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001170
Valerie Hau9758ae02018-10-09 16:05:09 -07001171 GetBestColorModeTest()
1172 : DisplayTransactionTest(),
Dominik Laskowski075d3172018-05-24 15:50:06 -07001173 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */,
1174 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001175
1176 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1177
1178 void addHwcColorModesMapping(ui::ColorMode colorMode,
1179 std::vector<ui::RenderIntent> renderIntents) {
1180 mHwcColorModes[colorMode] = renderIntents;
1181 }
1182
1183 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1184
1185 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1186
1187 void getBestColorMode() {
1188 mInjector.setHwcColorModes(mHwcColorModes);
1189 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001190 mInjector.setNativeWindow(mNativeWindow);
1191
1192 // Creating a DisplayDevice requires getting default dimensions from the
1193 // native window.
1194 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1195 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1196 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1197 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001198 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1199 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1200 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001201 auto displayDevice = mInjector.inject();
1202
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001203 displayDevice->getCompositionDisplay()
1204 ->getDisplayColorProfile()
1205 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1206 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001207 }
1208
1209 ui::Dataspace mOutDataspace;
1210 ui::ColorMode mOutColorMode;
1211 ui::RenderIntent mOutRenderIntent;
1212
1213private:
1214 ui::Dataspace mInputDataspace;
1215 ui::RenderIntent mInputRenderIntent;
1216 bool mHasWideColorGamut = false;
1217 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1218 FakeDisplayDeviceInjector mInjector;
1219};
1220
1221TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1222 addHwcColorModesMapping(ui::ColorMode::SRGB,
1223 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1224 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1225 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1226 setHasWideColorGamut(true);
1227
1228 getBestColorMode();
1229
Peiyong Lin14724e62018-12-05 07:27:30 -08001230 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001231 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1232 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1233}
1234
1235TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1236 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1237 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1238 addHwcColorModesMapping(ui::ColorMode::SRGB,
1239 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1240 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1241 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1242 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1243 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1244 setHasWideColorGamut(true);
1245
1246 getBestColorMode();
1247
1248 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1249 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1250 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1251}
1252
1253TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1254 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1255 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1256 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1257 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1258 setHasWideColorGamut(true);
1259
1260 getBestColorMode();
1261
1262 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1263 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1264 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1265}
1266
1267/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001268 * SurfaceFlinger::getDisplayNativePrimaries
1269 */
1270
1271class GetDisplayNativePrimaries : public DisplayTransactionTest {
1272public:
1273 GetDisplayNativePrimaries();
1274 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1275 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1276
1277private:
1278 static constexpr float mStartingTestValue = 1.0f;
1279};
1280
1281GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1282 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1283 injectFakeNativeWindowSurfaceFactory();
1284}
1285
1286void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1287 ui::DisplayPrimaries& primaries) {
1288 float startingVal = mStartingTestValue;
1289 primaries.red.X = startingVal++;
1290 primaries.red.Y = startingVal++;
1291 primaries.red.Z = startingVal++;
1292 primaries.green.X = startingVal++;
1293 primaries.green.Y = startingVal++;
1294 primaries.green.Z = startingVal++;
1295 primaries.blue.X = startingVal++;
1296 primaries.blue.Y = startingVal++;
1297 primaries.blue.Z = startingVal++;
1298 primaries.white.X = startingVal++;
1299 primaries.white.Y = startingVal++;
1300 primaries.white.Z = startingVal++;
1301}
1302
1303void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1304 const ui::DisplayPrimaries& primaries) {
1305 float startingVal = mStartingTestValue;
1306 EXPECT_EQ(primaries.red.X, startingVal++);
1307 EXPECT_EQ(primaries.red.Y, startingVal++);
1308 EXPECT_EQ(primaries.red.Z, startingVal++);
1309 EXPECT_EQ(primaries.green.X, startingVal++);
1310 EXPECT_EQ(primaries.green.Y, startingVal++);
1311 EXPECT_EQ(primaries.green.Z, startingVal++);
1312 EXPECT_EQ(primaries.blue.X, startingVal++);
1313 EXPECT_EQ(primaries.blue.Y, startingVal++);
1314 EXPECT_EQ(primaries.blue.Z, startingVal++);
1315 EXPECT_EQ(primaries.white.X, startingVal++);
1316 EXPECT_EQ(primaries.white.Y, startingVal++);
1317 EXPECT_EQ(primaries.white.Z, startingVal++);
1318}
1319
1320TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1321 ui::DisplayPrimaries primaries;
1322 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1323}
1324
1325TEST_F(GetDisplayNativePrimaries, internalDisplayWithDefaultPrimariesData) {
1326 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1327 injector.inject();
1328 auto internalDisplayToken = injector.token();
1329 // A nullptr would trigger a different execution path than what's being tested here
1330 EXPECT_NE(nullptr, internalDisplayToken.get());
1331
1332 mFlinger.initDefaultDisplayNativePrimaries();
1333
1334 ui::DisplayPrimaries primaries;
1335 // Expecting sRGB primaries
1336 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1337 EXPECT_EQ(primaries.red.X, 0.4123f);
1338 EXPECT_EQ(primaries.red.Y, 0.2126f);
1339 EXPECT_EQ(primaries.red.Z, 0.0193f);
1340 EXPECT_EQ(primaries.green.X, 0.3576f);
1341 EXPECT_EQ(primaries.green.Y, 0.7152f);
1342 EXPECT_EQ(primaries.green.Z, 0.1192f);
1343 EXPECT_EQ(primaries.blue.X, 0.1805f);
1344 EXPECT_EQ(primaries.blue.Y, 0.0722f);
1345 EXPECT_EQ(primaries.blue.Z, 0.9506f);
1346 EXPECT_EQ(primaries.white.X, 0.9505f);
1347 EXPECT_EQ(primaries.white.Y, 1.0000f);
1348 EXPECT_EQ(primaries.white.Z, 1.0891f);
1349}
1350
1351TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1352 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1353 injector.inject();
1354 auto internalDisplayToken = injector.token();
1355
1356 ui::DisplayPrimaries expectedPrimaries;
1357 populateDummyDisplayNativePrimaries(expectedPrimaries);
1358 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1359
1360 ui::DisplayPrimaries primaries;
1361 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1362
1363 checkDummyDisplayNativePrimaries(primaries);
1364}
1365
1366TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1367 sp<BBinder> notInternalDisplayToken = new BBinder();
1368
1369 ui::DisplayPrimaries primaries;
1370 populateDummyDisplayNativePrimaries(primaries);
1371 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1372
1373 // Check primaries argument wasn't modified in case of failure
1374 checkDummyDisplayNativePrimaries(primaries);
1375}
1376
1377/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001378 * SurfaceFlinger::setupNewDisplayDeviceInternal
1379 */
1380
1381class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1382public:
1383 template <typename T>
1384 void setupNewDisplayDeviceInternalTest();
1385};
1386
1387template <typename Case>
1388void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1389 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001390 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1391 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001392 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001393
1394 // --------------------------------------------------------------------
1395 // Preconditions
1396
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001397 // Wide color displays support is configured appropriately
1398 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001399
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001400 // The display is setup with the HWC.
1401 Case::Display::injectHwcDisplay(this);
1402
1403 // SurfaceFlinger will use a test-controlled factory for native window
1404 // surfaces.
1405 injectFakeNativeWindowSurfaceFactory();
1406
1407 // --------------------------------------------------------------------
1408 // Call Expectations
1409
1410 // Various native window calls will be made.
1411 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001412 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001413 Case::WideColorSupport::setupComposerCallExpectations(this);
1414 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001415 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001416
1417 // --------------------------------------------------------------------
1418 // Invocation
1419
1420 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001421 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1422 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001423 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1424
Dominik Laskowski075d3172018-05-24 15:50:06 -07001425 auto device =
1426 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1427 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001428
1429 // --------------------------------------------------------------------
1430 // Postconditions
1431
1432 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001433 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1434 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001435 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001436 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001437 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1438 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1439 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001440 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001441 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1442 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1443 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001444 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1445 // remapped, and the test only ever sets up one config. If there were an error
1446 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
1447 EXPECT_EQ(0, device->getActiveConfig());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001448 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1449 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001450}
1451
1452TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1453 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1454}
1455
1456TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1457 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1458}
1459
1460TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1461 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1462}
1463
1464TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001465 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001466
Dominik Laskowski075d3172018-05-24 15:50:06 -07001467 // Insert display data so that the HWC thinks it created the virtual display.
1468 const auto displayId = Case::Display::DISPLAY_ID::get();
1469 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001470 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001471
1472 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001473}
1474
1475TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1476 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1477}
1478
Valerie Haue9e843a2018-12-18 13:39:23 -08001479TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1480 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1481}
1482
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001483TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1484 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1485}
1486
1487TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1488 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1489}
1490
1491TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1492 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1493}
1494
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001495TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1496 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1497}
1498
1499TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1500 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1501}
1502
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001503/* ------------------------------------------------------------------------
1504 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1505 */
1506
1507class HandleTransactionLockedTest : public DisplayTransactionTest {
1508public:
1509 template <typename Case>
1510 void setupCommonPreconditions();
1511
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001512 template <typename Case, bool connected>
1513 static void expectHotplugReceived(mock::EventThread*);
1514
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001515 template <typename Case>
1516 void setupCommonCallExpectationsForConnectProcessing();
1517
1518 template <typename Case>
1519 void setupCommonCallExpectationsForDisconnectProcessing();
1520
1521 template <typename Case>
1522 void processesHotplugConnectCommon();
1523
1524 template <typename Case>
1525 void ignoresHotplugConnectCommon();
1526
1527 template <typename Case>
1528 void processesHotplugDisconnectCommon();
1529
1530 template <typename Case>
1531 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1532
1533 template <typename Case>
1534 void verifyPhysicalDisplayIsConnected();
1535
1536 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1537};
1538
1539template <typename Case>
1540void HandleTransactionLockedTest::setupCommonPreconditions() {
1541 // Wide color displays support is configured appropriately
1542 Case::WideColorSupport::injectConfigChange(this);
1543
1544 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1545 injectFakeBufferQueueFactory();
1546
1547 // SurfaceFlinger will use a test-controlled factory for native window
1548 // surfaces.
1549 injectFakeNativeWindowSurfaceFactory();
1550}
1551
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001552template <typename Case, bool connected>
1553void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1554 const auto convert = [](auto physicalDisplayId) {
1555 return std::make_optional(DisplayId{physicalDisplayId});
1556 };
1557
1558 EXPECT_CALL(*eventThread,
1559 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1560 .Times(1);
1561}
1562
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001563template <typename Case>
1564void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1565 Case::Display::setupHwcHotplugCallExpectations(this);
1566
1567 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1568 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1569 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1570 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1571
1572 Case::WideColorSupport::setupComposerCallExpectations(this);
1573 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001574 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001575
1576 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001577 expectHotplugReceived<Case, true>(mEventThread);
1578 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001579}
1580
1581template <typename Case>
1582void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1583 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001584
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001585 expectHotplugReceived<Case, false>(mEventThread);
1586 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001587}
1588
1589template <typename Case>
1590void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1591 // The display device should have been set up in the list of displays.
1592 ASSERT_TRUE(hasDisplayDevice(displayToken));
1593 const auto& device = getDisplayDevice(displayToken);
1594 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001595 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001596
1597 // The display should have been set up in the current display state
1598 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1599 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001600 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1601 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1602 : Case::Display::DISPLAY_ID::get(),
1603 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001604
1605 // The display should have been set up in the drawing display state
1606 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1607 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001608 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1609 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1610 : Case::Display::DISPLAY_ID::get(),
1611 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001612}
1613
1614template <typename Case>
1615void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1616 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001617 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001618
Dominik Laskowski075d3172018-05-24 15:50:06 -07001619 // SF should have a display token.
1620 const auto displayId = Case::Display::DISPLAY_ID::get();
1621 ASSERT_TRUE(displayId);
1622 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1623 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001624
1625 verifyDisplayIsConnected<Case>(displayToken);
1626}
1627
1628void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1629 EXPECT_FALSE(hasDisplayDevice(displayToken));
1630 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1631 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1632}
1633
1634template <typename Case>
1635void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1636 // --------------------------------------------------------------------
1637 // Preconditions
1638
1639 setupCommonPreconditions<Case>();
1640
1641 // A hotplug connect event is enqueued for a display
1642 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001643
1644 // --------------------------------------------------------------------
1645 // Call Expectations
1646
1647 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001648
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001649 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001650
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001651 // --------------------------------------------------------------------
1652 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001653
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001654 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001655
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001656 // --------------------------------------------------------------------
1657 // Postconditions
1658
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001659 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001660
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001661 // --------------------------------------------------------------------
1662 // Cleanup conditions
1663
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001664 EXPECT_CALL(*mComposer,
1665 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001666 .WillOnce(Return(Error::NONE));
1667 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001668}
1669
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001670template <typename Case>
1671void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1672 // --------------------------------------------------------------------
1673 // Preconditions
1674
1675 setupCommonPreconditions<Case>();
1676
1677 // A hotplug connect event is enqueued for a display
1678 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1679
1680 // --------------------------------------------------------------------
1681 // Invocation
1682
1683 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1684
1685 // --------------------------------------------------------------------
1686 // Postconditions
1687
1688 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001689 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001690}
1691
1692template <typename Case>
1693void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1694 // --------------------------------------------------------------------
1695 // Preconditions
1696
1697 setupCommonPreconditions<Case>();
1698
1699 // A hotplug disconnect event is enqueued for a display
1700 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1701
1702 // The display is already completely set up.
1703 Case::Display::injectHwcDisplay(this);
1704 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1705 existing.inject();
1706
1707 // --------------------------------------------------------------------
1708 // Call Expectations
1709
1710 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001711 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1712 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001713
1714 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1715
1716 // --------------------------------------------------------------------
1717 // Invocation
1718
1719 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1720
1721 // --------------------------------------------------------------------
1722 // Postconditions
1723
1724 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001725 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001726
Dominik Laskowski075d3172018-05-24 15:50:06 -07001727 // SF should not have a display token.
1728 const auto displayId = Case::Display::DISPLAY_ID::get();
1729 ASSERT_TRUE(displayId);
1730 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001731
1732 // The existing token should have been removed
1733 verifyDisplayIsNotConnected(existing.token());
1734}
1735
1736TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1737 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1738}
1739
1740TEST_F(HandleTransactionLockedTest,
1741 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1742 // Inject an external display.
1743 ExternalDisplayVariant::injectHwcDisplay(this);
1744
1745 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1746}
1747
1748TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1749 // Inject a primary display.
1750 PrimaryDisplayVariant::injectHwcDisplay(this);
1751
1752 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1753}
1754
1755TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1756 // Inject both a primary and external display.
1757 PrimaryDisplayVariant::injectHwcDisplay(this);
1758 ExternalDisplayVariant::injectHwcDisplay(this);
1759
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001760 // TODO: This is an unnecessary call.
1761 EXPECT_CALL(*mComposer,
1762 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
1763 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
1764 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
1765 Return(Error::NONE)));
1766
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001767 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1768
1769 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1770}
1771
1772TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1773 // Inject a primary display.
1774 PrimaryDisplayVariant::injectHwcDisplay(this);
1775
1776 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1777
1778 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1779}
1780
1781TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1782 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1783}
1784
1785TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1786 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1787}
1788
1789TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1790 using Case = SimplePrimaryDisplayCase;
1791
1792 // --------------------------------------------------------------------
1793 // Preconditions
1794
1795 setupCommonPreconditions<Case>();
1796
1797 // A hotplug connect event is enqueued for a display
1798 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1799 // A hotplug disconnect event is also enqueued for the same display
1800 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1801
1802 // --------------------------------------------------------------------
1803 // Call Expectations
1804
1805 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1806
1807 setupCommonCallExpectationsForConnectProcessing<Case>();
1808 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1809
1810 EXPECT_CALL(*mComposer,
1811 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1812 .WillOnce(Return(Error::NONE));
1813 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1814
1815 // --------------------------------------------------------------------
1816 // Invocation
1817
1818 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1819
1820 // --------------------------------------------------------------------
1821 // Postconditions
1822
1823 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001824 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001825
Dominik Laskowski075d3172018-05-24 15:50:06 -07001826 // SF should not have a display token.
1827 const auto displayId = Case::Display::DISPLAY_ID::get();
1828 ASSERT_TRUE(displayId);
1829 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001830}
1831
1832TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1833 using Case = SimplePrimaryDisplayCase;
1834
1835 // --------------------------------------------------------------------
1836 // Preconditions
1837
1838 setupCommonPreconditions<Case>();
1839
1840 // The display is already completely set up.
1841 Case::Display::injectHwcDisplay(this);
1842 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1843 existing.inject();
1844
1845 // A hotplug disconnect event is enqueued for a display
1846 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1847 // A hotplug connect event is also enqueued for the same display
1848 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1849
1850 // --------------------------------------------------------------------
1851 // Call Expectations
1852
1853 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1854
1855 setupCommonCallExpectationsForConnectProcessing<Case>();
1856 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1857
1858 // --------------------------------------------------------------------
1859 // Invocation
1860
1861 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1862
1863 // --------------------------------------------------------------------
1864 // Postconditions
1865
1866 // The existing token should have been removed
1867 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001868 const auto displayId = Case::Display::DISPLAY_ID::get();
1869 ASSERT_TRUE(displayId);
1870 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1871 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001872
1873 // A new display should be connected in its place
1874
1875 verifyPhysicalDisplayIsConnected<Case>();
1876
1877 // --------------------------------------------------------------------
1878 // Cleanup conditions
1879
1880 EXPECT_CALL(*mComposer,
1881 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1882 .WillOnce(Return(Error::NONE));
1883 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1884}
1885
1886TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1887 using Case = HwcVirtualDisplayCase;
1888
1889 // --------------------------------------------------------------------
1890 // Preconditions
1891
1892 // The HWC supports at least one virtual display
1893 injectMockComposer(1);
1894
1895 setupCommonPreconditions<Case>();
1896
1897 // A virtual display was added to the current state, and it has a
1898 // surface(producer)
1899 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07001900
Dominik Laskowski075d3172018-05-24 15:50:06 -07001901 DisplayDeviceState state;
1902 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001903
1904 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001905 state.surface = surface;
1906 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001907
1908 // --------------------------------------------------------------------
1909 // Call Expectations
1910
1911 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1912 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1913
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001914 EXPECT_CALL(*mComposer, getDisplayCapabilities(Case::Display::HWC_DISPLAY_ID, _))
1915 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
1916 Return(Error::NONE)));
1917
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001918 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1919 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1920 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1921 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1922 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1923 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1924 Return(NO_ERROR)));
1925 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1926 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1927
1928 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1929
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001930 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001931 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1932
1933 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1934 Case::WideColorSupport::setupComposerCallExpectations(this);
1935 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001936 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001937
1938 // --------------------------------------------------------------------
1939 // Invocation
1940
1941 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1942
1943 // --------------------------------------------------------------------
1944 // Postconditions
1945
1946 // The display device should have been set up in the list of displays.
1947 verifyDisplayIsConnected<Case>(displayToken);
1948
1949 // --------------------------------------------------------------------
1950 // Cleanup conditions
1951
1952 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1953 .WillOnce(Return(Error::NONE));
1954 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1955}
1956
1957TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1958 using Case = HwcVirtualDisplayCase;
1959
1960 // --------------------------------------------------------------------
1961 // Preconditions
1962
1963 // The HWC supports at least one virtual display
1964 injectMockComposer(1);
1965
1966 setupCommonPreconditions<Case>();
1967
1968 // A virtual display was added to the current state, but it does not have a
1969 // surface.
1970 sp<BBinder> displayToken = new BBinder();
1971
Dominik Laskowski075d3172018-05-24 15:50:06 -07001972 DisplayDeviceState state;
1973 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001974
Dominik Laskowski075d3172018-05-24 15:50:06 -07001975 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001976
1977 // --------------------------------------------------------------------
1978 // Call Expectations
1979
1980 // --------------------------------------------------------------------
1981 // Invocation
1982
1983 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1984
1985 // --------------------------------------------------------------------
1986 // Postconditions
1987
1988 // There will not be a display device set up.
1989 EXPECT_FALSE(hasDisplayDevice(displayToken));
1990
1991 // The drawing display state will be set from the current display state.
1992 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1993 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001994 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001995}
1996
1997TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1998 using Case = HwcVirtualDisplayCase;
1999
2000 // --------------------------------------------------------------------
2001 // Preconditions
2002
2003 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002004 const auto displayId = Case::Display::DISPLAY_ID::get();
2005 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08002006 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002007 Case::Display::injectHwcDisplay(this);
2008 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2009 existing.inject();
2010 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2011
2012 // --------------------------------------------------------------------
2013 // Call Expectations
2014
2015 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2016
2017 // --------------------------------------------------------------------
2018 // Invocation
2019
2020 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2021
2022 // --------------------------------------------------------------------
2023 // Postconditions
2024
2025 // The existing token should have been removed
2026 verifyDisplayIsNotConnected(existing.token());
2027}
2028
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002029TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2030 using Case = NonHwcVirtualDisplayCase;
2031
2032 constexpr uint32_t oldLayerStack = 0u;
2033 constexpr uint32_t newLayerStack = 123u;
2034
2035 // --------------------------------------------------------------------
2036 // Preconditions
2037
2038 // A display is set up
2039 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2040 display.inject();
2041
2042 // There is a change to the layerStack state
2043 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2044 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2045
2046 // --------------------------------------------------------------------
2047 // Invocation
2048
2049 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2050
2051 // --------------------------------------------------------------------
2052 // Postconditions
2053
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002054 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002055}
2056
2057TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2058 using Case = NonHwcVirtualDisplayCase;
2059
2060 constexpr int oldTransform = 0;
2061 constexpr int newTransform = 2;
2062
2063 // --------------------------------------------------------------------
2064 // Preconditions
2065
2066 // A display is set up
2067 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2068 display.inject();
2069
2070 // There is a change to the orientation state
2071 display.mutableDrawingDisplayState().orientation = oldTransform;
2072 display.mutableCurrentDisplayState().orientation = newTransform;
2073
2074 // --------------------------------------------------------------------
2075 // Invocation
2076
2077 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2078
2079 // --------------------------------------------------------------------
2080 // Postconditions
2081
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002082 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002083}
2084
2085TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2086 using Case = NonHwcVirtualDisplayCase;
2087
2088 const Rect oldViewport(0, 0, 0, 0);
2089 const Rect newViewport(0, 0, 123, 456);
2090
2091 // --------------------------------------------------------------------
2092 // Preconditions
2093
2094 // A display is set up
2095 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2096 display.inject();
2097
2098 // There is a change to the viewport state
2099 display.mutableDrawingDisplayState().viewport = oldViewport;
2100 display.mutableCurrentDisplayState().viewport = newViewport;
2101
2102 // --------------------------------------------------------------------
2103 // Invocation
2104
2105 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2106
2107 // --------------------------------------------------------------------
2108 // Postconditions
2109
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002110 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002111}
2112
2113TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2114 using Case = NonHwcVirtualDisplayCase;
2115
2116 const Rect oldFrame(0, 0, 0, 0);
2117 const Rect newFrame(0, 0, 123, 456);
2118
2119 // --------------------------------------------------------------------
2120 // Preconditions
2121
2122 // A display is set up
2123 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2124 display.inject();
2125
2126 // There is a change to the viewport state
2127 display.mutableDrawingDisplayState().frame = oldFrame;
2128 display.mutableCurrentDisplayState().frame = newFrame;
2129
2130 // --------------------------------------------------------------------
2131 // Invocation
2132
2133 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2134
2135 // --------------------------------------------------------------------
2136 // Postconditions
2137
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002138 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002139}
2140
2141TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2142 using Case = NonHwcVirtualDisplayCase;
2143
2144 constexpr int oldWidth = 0;
2145 constexpr int oldHeight = 10;
2146 constexpr int newWidth = 123;
2147
2148 // --------------------------------------------------------------------
2149 // Preconditions
2150
2151 // A display is set up
2152 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002153 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002154 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002155 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2156 display.setNativeWindow(nativeWindow);
2157 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002158 // Setup injection expections
2159 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2160 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2161 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2162 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002163 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2164 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2165 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002166 display.inject();
2167
2168 // There is a change to the viewport state
2169 display.mutableDrawingDisplayState().width = oldWidth;
2170 display.mutableDrawingDisplayState().height = oldHeight;
2171 display.mutableCurrentDisplayState().width = newWidth;
2172 display.mutableCurrentDisplayState().height = oldHeight;
2173
2174 // --------------------------------------------------------------------
2175 // Call Expectations
2176
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002177 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002178
2179 // --------------------------------------------------------------------
2180 // Invocation
2181
2182 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2183}
2184
2185TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2186 using Case = NonHwcVirtualDisplayCase;
2187
2188 constexpr int oldWidth = 0;
2189 constexpr int oldHeight = 10;
2190 constexpr int newHeight = 123;
2191
2192 // --------------------------------------------------------------------
2193 // Preconditions
2194
2195 // A display is set up
2196 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002197 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002198 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002199 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2200 display.setNativeWindow(nativeWindow);
2201 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002202 // Setup injection expections
2203 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2204 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2205 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2206 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002207 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2208 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2209 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002210 display.inject();
2211
2212 // There is a change to the viewport state
2213 display.mutableDrawingDisplayState().width = oldWidth;
2214 display.mutableDrawingDisplayState().height = oldHeight;
2215 display.mutableCurrentDisplayState().width = oldWidth;
2216 display.mutableCurrentDisplayState().height = newHeight;
2217
2218 // --------------------------------------------------------------------
2219 // Call Expectations
2220
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002221 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002222
2223 // --------------------------------------------------------------------
2224 // Invocation
2225
2226 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2227}
2228
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002229/* ------------------------------------------------------------------------
2230 * SurfaceFlinger::setDisplayStateLocked
2231 */
2232
2233TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2234 // --------------------------------------------------------------------
2235 // Preconditions
2236
2237 // We have an unknown display token not associated with a known display
2238 sp<BBinder> displayToken = new BBinder();
2239
2240 // The requested display state references the unknown display.
2241 DisplayState state;
2242 state.what = DisplayState::eLayerStackChanged;
2243 state.token = displayToken;
2244 state.layerStack = 456;
2245
2246 // --------------------------------------------------------------------
2247 // Invocation
2248
2249 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2250
2251 // --------------------------------------------------------------------
2252 // Postconditions
2253
2254 // The returned flags are empty
2255 EXPECT_EQ(0u, flags);
2256
2257 // The display token still doesn't match anything known.
2258 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2259}
2260
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002261TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2262 using Case = SimplePrimaryDisplayCase;
2263
2264 // --------------------------------------------------------------------
2265 // Preconditions
2266
2267 // A display is already set up
2268 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2269 display.inject();
2270
2271 // No changes are made to the display
2272 DisplayState state;
2273 state.what = 0;
2274 state.token = display.token();
2275
2276 // --------------------------------------------------------------------
2277 // Invocation
2278
2279 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2280
2281 // --------------------------------------------------------------------
2282 // Postconditions
2283
2284 // The returned flags are empty
2285 EXPECT_EQ(0u, flags);
2286}
2287
2288TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2289 using Case = SimplePrimaryDisplayCase;
2290
2291 // --------------------------------------------------------------------
2292 // Preconditions
2293
2294 // A display is already set up
2295 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2296 display.inject();
2297
2298 // There is a surface that can be set.
2299 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2300
2301 // The current display state has the surface set
2302 display.mutableCurrentDisplayState().surface = surface;
2303
2304 // The incoming request sets the same surface
2305 DisplayState state;
2306 state.what = DisplayState::eSurfaceChanged;
2307 state.token = display.token();
2308 state.surface = surface;
2309
2310 // --------------------------------------------------------------------
2311 // Invocation
2312
2313 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2314
2315 // --------------------------------------------------------------------
2316 // Postconditions
2317
2318 // The returned flags are empty
2319 EXPECT_EQ(0u, flags);
2320
2321 // The current display state is unchanged.
2322 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2323}
2324
2325TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2326 using Case = SimplePrimaryDisplayCase;
2327
2328 // --------------------------------------------------------------------
2329 // Preconditions
2330
2331 // A display is already set up
2332 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2333 display.inject();
2334
2335 // There is a surface that can be set.
2336 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2337
2338 // The current display state does not have a surface
2339 display.mutableCurrentDisplayState().surface = nullptr;
2340
2341 // The incoming request sets a surface
2342 DisplayState state;
2343 state.what = DisplayState::eSurfaceChanged;
2344 state.token = display.token();
2345 state.surface = surface;
2346
2347 // --------------------------------------------------------------------
2348 // Invocation
2349
2350 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2351
2352 // --------------------------------------------------------------------
2353 // Postconditions
2354
2355 // The returned flags indicate a transaction is needed
2356 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2357
2358 // The current display layer stack state is set to the new value
2359 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2360}
2361
2362TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2363 using Case = SimplePrimaryDisplayCase;
2364
2365 // --------------------------------------------------------------------
2366 // Preconditions
2367
2368 // A display is already set up
2369 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2370 display.inject();
2371
2372 // The display has a layer stack set
2373 display.mutableCurrentDisplayState().layerStack = 456u;
2374
2375 // The incoming request sets the same layer stack
2376 DisplayState state;
2377 state.what = DisplayState::eLayerStackChanged;
2378 state.token = display.token();
2379 state.layerStack = 456u;
2380
2381 // --------------------------------------------------------------------
2382 // Invocation
2383
2384 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2385
2386 // --------------------------------------------------------------------
2387 // Postconditions
2388
2389 // The returned flags are empty
2390 EXPECT_EQ(0u, flags);
2391
2392 // The current display state is unchanged
2393 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2394}
2395
2396TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2397 using Case = SimplePrimaryDisplayCase;
2398
2399 // --------------------------------------------------------------------
2400 // Preconditions
2401
2402 // A display is set up
2403 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2404 display.inject();
2405
2406 // The display has a layer stack set
2407 display.mutableCurrentDisplayState().layerStack = 654u;
2408
2409 // The incoming request sets a different layer stack
2410 DisplayState state;
2411 state.what = DisplayState::eLayerStackChanged;
2412 state.token = display.token();
2413 state.layerStack = 456u;
2414
2415 // --------------------------------------------------------------------
2416 // Invocation
2417
2418 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2419
2420 // --------------------------------------------------------------------
2421 // Postconditions
2422
2423 // The returned flags indicate a transaction is needed
2424 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2425
2426 // The desired display state has been set to the new value.
2427 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2428}
2429
2430TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2431 using Case = SimplePrimaryDisplayCase;
2432 constexpr int initialOrientation = 180;
2433 const Rect initialFrame = {1, 2, 3, 4};
2434 const Rect initialViewport = {5, 6, 7, 8};
2435
2436 // --------------------------------------------------------------------
2437 // Preconditions
2438
2439 // A display is set up
2440 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2441 display.inject();
2442
2443 // The current display state projection state is all set
2444 display.mutableCurrentDisplayState().orientation = initialOrientation;
2445 display.mutableCurrentDisplayState().frame = initialFrame;
2446 display.mutableCurrentDisplayState().viewport = initialViewport;
2447
2448 // The incoming request sets the same projection state
2449 DisplayState state;
2450 state.what = DisplayState::eDisplayProjectionChanged;
2451 state.token = display.token();
2452 state.orientation = initialOrientation;
2453 state.frame = initialFrame;
2454 state.viewport = initialViewport;
2455
2456 // --------------------------------------------------------------------
2457 // Invocation
2458
2459 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2460
2461 // --------------------------------------------------------------------
2462 // Postconditions
2463
2464 // The returned flags are empty
2465 EXPECT_EQ(0u, flags);
2466
2467 // The current display state is unchanged
2468 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2469
2470 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2471 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2472}
2473
2474TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2475 using Case = SimplePrimaryDisplayCase;
2476 constexpr int initialOrientation = 90;
2477 constexpr int desiredOrientation = 180;
2478
2479 // --------------------------------------------------------------------
2480 // Preconditions
2481
2482 // A display is set up
2483 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2484 display.inject();
2485
2486 // The current display state has an orientation set
2487 display.mutableCurrentDisplayState().orientation = initialOrientation;
2488
2489 // The incoming request sets a different orientation
2490 DisplayState state;
2491 state.what = DisplayState::eDisplayProjectionChanged;
2492 state.token = display.token();
2493 state.orientation = desiredOrientation;
2494
2495 // --------------------------------------------------------------------
2496 // Invocation
2497
2498 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2499
2500 // --------------------------------------------------------------------
2501 // Postconditions
2502
2503 // The returned flags indicate a transaction is needed
2504 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2505
2506 // The current display state has the new value.
2507 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2508}
2509
2510TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2511 using Case = SimplePrimaryDisplayCase;
2512 const Rect initialFrame = {0, 0, 0, 0};
2513 const Rect desiredFrame = {5, 6, 7, 8};
2514
2515 // --------------------------------------------------------------------
2516 // Preconditions
2517
2518 // A display is set up
2519 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2520 display.inject();
2521
2522 // The current display state does not have a frame
2523 display.mutableCurrentDisplayState().frame = initialFrame;
2524
2525 // The incoming request sets a frame
2526 DisplayState state;
2527 state.what = DisplayState::eDisplayProjectionChanged;
2528 state.token = display.token();
2529 state.frame = desiredFrame;
2530
2531 // --------------------------------------------------------------------
2532 // Invocation
2533
2534 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2535
2536 // --------------------------------------------------------------------
2537 // Postconditions
2538
2539 // The returned flags indicate a transaction is needed
2540 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2541
2542 // The current display state has the new value.
2543 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2544}
2545
2546TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2547 using Case = SimplePrimaryDisplayCase;
2548 const Rect initialViewport = {0, 0, 0, 0};
2549 const Rect desiredViewport = {5, 6, 7, 8};
2550
2551 // --------------------------------------------------------------------
2552 // Preconditions
2553
2554 // A display is set up
2555 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2556 display.inject();
2557
2558 // The current display state does not have a viewport
2559 display.mutableCurrentDisplayState().viewport = initialViewport;
2560
2561 // The incoming request sets a viewport
2562 DisplayState state;
2563 state.what = DisplayState::eDisplayProjectionChanged;
2564 state.token = display.token();
2565 state.viewport = desiredViewport;
2566
2567 // --------------------------------------------------------------------
2568 // Invocation
2569
2570 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2571
2572 // --------------------------------------------------------------------
2573 // Postconditions
2574
2575 // The returned flags indicate a transaction is needed
2576 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2577
2578 // The current display state has the new value.
2579 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2580}
2581
2582TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2583 using Case = SimplePrimaryDisplayCase;
2584 constexpr uint32_t initialWidth = 1024;
2585 constexpr uint32_t initialHeight = 768;
2586
2587 // --------------------------------------------------------------------
2588 // Preconditions
2589
2590 // A display is set up
2591 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2592 display.inject();
2593
2594 // The current display state has a size set
2595 display.mutableCurrentDisplayState().width = initialWidth;
2596 display.mutableCurrentDisplayState().height = initialHeight;
2597
2598 // The incoming request sets the same display size
2599 DisplayState state;
2600 state.what = DisplayState::eDisplaySizeChanged;
2601 state.token = display.token();
2602 state.width = initialWidth;
2603 state.height = initialHeight;
2604
2605 // --------------------------------------------------------------------
2606 // Invocation
2607
2608 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2609
2610 // --------------------------------------------------------------------
2611 // Postconditions
2612
2613 // The returned flags are empty
2614 EXPECT_EQ(0u, flags);
2615
2616 // The current display state is unchanged
2617 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2618 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2619}
2620
2621TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2622 using Case = SimplePrimaryDisplayCase;
2623 constexpr uint32_t initialWidth = 0;
2624 constexpr uint32_t desiredWidth = 1024;
2625
2626 // --------------------------------------------------------------------
2627 // Preconditions
2628
2629 // A display is set up
2630 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2631 display.inject();
2632
2633 // The display does not yet have a width
2634 display.mutableCurrentDisplayState().width = initialWidth;
2635
2636 // The incoming request sets a display width
2637 DisplayState state;
2638 state.what = DisplayState::eDisplaySizeChanged;
2639 state.token = display.token();
2640 state.width = desiredWidth;
2641
2642 // --------------------------------------------------------------------
2643 // Invocation
2644
2645 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2646
2647 // --------------------------------------------------------------------
2648 // Postconditions
2649
2650 // The returned flags indicate a transaction is needed
2651 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2652
2653 // The current display state has the new value.
2654 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2655}
2656
2657TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2658 using Case = SimplePrimaryDisplayCase;
2659 constexpr uint32_t initialHeight = 0;
2660 constexpr uint32_t desiredHeight = 768;
2661
2662 // --------------------------------------------------------------------
2663 // Preconditions
2664
2665 // A display is set up
2666 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2667 display.inject();
2668
2669 // The display does not yet have a height
2670 display.mutableCurrentDisplayState().height = initialHeight;
2671
2672 // The incoming request sets a display height
2673 DisplayState state;
2674 state.what = DisplayState::eDisplaySizeChanged;
2675 state.token = display.token();
2676 state.height = desiredHeight;
2677
2678 // --------------------------------------------------------------------
2679 // Invocation
2680
2681 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2682
2683 // --------------------------------------------------------------------
2684 // Postconditions
2685
2686 // The returned flags indicate a transaction is needed
2687 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2688
2689 // The current display state has the new value.
2690 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2691}
2692
Lloyd Pique86016da2018-03-01 16:09:38 -08002693/* ------------------------------------------------------------------------
2694 * SurfaceFlinger::onInitializeDisplays
2695 */
2696
2697TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2698 using Case = SimplePrimaryDisplayCase;
2699
2700 // --------------------------------------------------------------------
2701 // Preconditions
2702
2703 // A primary display is set up
2704 Case::Display::injectHwcDisplay(this);
2705 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2706 primaryDisplay.inject();
2707
2708 // --------------------------------------------------------------------
2709 // Call Expectations
2710
2711 // We expect the surface interceptor to possibly be used, but we treat it as
2712 // disabled since it is called as a side effect rather than directly by this
2713 // function.
2714 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2715
2716 // We expect a call to get the active display config.
2717 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2718
2719 // We expect invalidate() to be invoked once to trigger display transaction
2720 // processing.
2721 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2722
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002723 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2724
Lloyd Pique86016da2018-03-01 16:09:38 -08002725 // --------------------------------------------------------------------
2726 // Invocation
2727
2728 mFlinger.onInitializeDisplays();
2729
2730 // --------------------------------------------------------------------
2731 // Postconditions
2732
2733 // The primary display should have a current state
2734 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2735 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2736 // The layer stack state should be set to zero
2737 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2738 // The orientation state should be set to zero
2739 EXPECT_EQ(0, primaryDisplayState.orientation);
2740
2741 // The frame state should be set to INVALID
2742 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2743
2744 // The viewport state should be set to INVALID
2745 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2746
2747 // The width and height should both be zero
2748 EXPECT_EQ(0u, primaryDisplayState.width);
2749 EXPECT_EQ(0u, primaryDisplayState.height);
2750
2751 // The display should be set to HWC_POWER_MODE_NORMAL
2752 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2753 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2754 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2755
2756 // The display refresh period should be set in the frame tracker.
2757 FrameStats stats;
2758 mFlinger.getAnimFrameTracker().getStats(&stats);
2759 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2760
2761 // The display transaction needed flag should be set.
2762 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2763
2764 // The compositor timing should be set to default values
2765 const auto& compositorTiming = mFlinger.getCompositorTiming();
2766 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2767 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2768 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2769}
2770
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002771/* ------------------------------------------------------------------------
2772 * SurfaceFlinger::setPowerModeInternal
2773 */
2774
2775// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07002776template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002777struct DozeIsSupportedVariant {
2778 static constexpr bool DOZE_SUPPORTED = true;
2779 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2780 IComposerClient::PowerMode::DOZE;
2781 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2782 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07002783
2784 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2785 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2786 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
2787 {Hwc2::DisplayCapability::DOZE})),
2788 Return(Error::NONE)));
2789 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002790};
2791
Peiyong Lined531a32018-10-26 18:27:56 -07002792template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002793// Used when we simulate a display that does not support doze.
2794struct DozeNotSupportedVariant {
2795 static constexpr bool DOZE_SUPPORTED = false;
2796 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2797 IComposerClient::PowerMode::ON;
2798 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2799 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07002800
2801 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2802 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2803 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
2804 Return(Error::NONE)));
2805 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002806};
2807
2808struct EventThreadBaseSupportedVariant {
2809 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
2810 // The event control thread should not be notified.
2811 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
2812
2813 // The event thread should not be notified.
2814 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
2815 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
2816 }
2817};
2818
2819struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
2820 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2821 // These calls are only expected for the primary display.
2822
2823 // Instead expect no calls.
2824 setupEventAndEventControlThreadNoCallExpectations(test);
2825 }
2826
2827 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2828 // These calls are only expected for the primary display.
2829
2830 // Instead expect no calls.
2831 setupEventAndEventControlThreadNoCallExpectations(test);
2832 }
2833};
2834
2835struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
2836 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2837 // The event control thread should be notified to enable vsyncs
2838 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
2839
2840 // The event thread should be notified that the screen was acquired.
2841 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
2842 }
2843
2844 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2845 // There should be a call to setVsyncEnabled(false)
2846 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
2847
2848 // The event thread should not be notified that the screen was released.
2849 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
2850 }
2851};
2852
Lloyd Pique41be5d22018-06-21 13:11:48 -07002853struct DispSyncIsSupportedVariant {
2854 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
2855 EXPECT_CALL(*test->mPrimaryDispSync, reset()).Times(1);
2856 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
2857 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
2858 }
2859
2860 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
2861 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
2862 }
2863};
2864
2865struct DispSyncNotSupportedVariant {
2866 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2867
2868 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2869};
2870
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002871// --------------------------------------------------------------------
2872// Note:
2873//
2874// There are a large number of transitions we could test, however we only test a
2875// selected subset which provides complete test coverage of the implementation.
2876// --------------------------------------------------------------------
2877
2878template <int initialPowerMode, int targetPowerMode>
2879struct TransitionVariantCommon {
2880 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
2881 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
2882
2883 static void verifyPostconditions(DisplayTransactionTest*) {}
2884};
2885
2886struct TransitionOffToOnVariant
2887 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
2888 template <typename Case>
2889 static void setupCallExpectations(DisplayTransactionTest* test) {
2890 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2891 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002892 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002893 Case::setupRepaintEverythingCallExpectations(test);
2894 }
2895
2896 static void verifyPostconditions(DisplayTransactionTest* test) {
2897 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2898 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2899 }
2900};
2901
2902struct TransitionOffToDozeSuspendVariant
2903 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
2904 template <typename Case>
2905 static void setupCallExpectations(DisplayTransactionTest* test) {
2906 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2907 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2908 Case::setupRepaintEverythingCallExpectations(test);
2909 }
2910
2911 static void verifyPostconditions(DisplayTransactionTest* test) {
2912 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2913 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2914 }
2915};
2916
2917struct TransitionOnToOffVariant
2918 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
2919 template <typename Case>
2920 static void setupCallExpectations(DisplayTransactionTest* test) {
2921 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002922 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002923 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2924 }
2925
2926 static void verifyPostconditions(DisplayTransactionTest* test) {
2927 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2928 }
2929};
2930
2931struct TransitionDozeSuspendToOffVariant
2932 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
2933 template <typename Case>
2934 static void setupCallExpectations(DisplayTransactionTest* test) {
2935 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2936 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2937 }
2938
2939 static void verifyPostconditions(DisplayTransactionTest* test) {
2940 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2941 }
2942};
2943
2944struct TransitionOnToDozeVariant
2945 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
2946 template <typename Case>
2947 static void setupCallExpectations(DisplayTransactionTest* test) {
2948 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2949 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2950 }
2951};
2952
2953struct TransitionDozeSuspendToDozeVariant
2954 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
2955 template <typename Case>
2956 static void setupCallExpectations(DisplayTransactionTest* test) {
2957 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002958 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002959 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2960 }
2961};
2962
2963struct TransitionDozeToOnVariant
2964 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
2965 template <typename Case>
2966 static void setupCallExpectations(DisplayTransactionTest* test) {
2967 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2968 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2969 }
2970};
2971
2972struct TransitionDozeSuspendToOnVariant
2973 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
2974 template <typename Case>
2975 static void setupCallExpectations(DisplayTransactionTest* test) {
2976 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002977 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002978 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2979 }
2980};
2981
2982struct TransitionOnToDozeSuspendVariant
2983 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
2984 template <typename Case>
2985 static void setupCallExpectations(DisplayTransactionTest* test) {
2986 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002987 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002988 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2989 }
2990};
2991
2992struct TransitionOnToUnknownVariant
2993 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
2994 template <typename Case>
2995 static void setupCallExpectations(DisplayTransactionTest* test) {
2996 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2997 Case::setupNoComposerPowerModeCallExpectations(test);
2998 }
2999};
3000
3001// --------------------------------------------------------------------
3002// Note:
3003//
3004// Rather than testing the cartesian product of of
3005// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3006// display type, and the other for another display type.
3007// --------------------------------------------------------------------
3008
3009template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003010 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003011struct DisplayPowerCase {
3012 using Display = DisplayVariant;
3013 using Doze = DozeVariant;
3014 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003015 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003016 using Transition = TransitionVariant;
3017
3018 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003019 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003020 auto display = Display::makeFakeExistingDisplayInjector(test);
3021 display.inject();
3022 display.mutableDisplayDevice()->setPowerMode(mode);
3023 return display;
3024 }
3025
3026 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Ana Krulecafb45842019-02-13 13:33:03 -08003027 test->mScheduler->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003028 }
3029
3030 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3031 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3032 }
3033
3034 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3035 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3036 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3037 }
3038
3039 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3040 IComposerClient::PowerMode mode) {
3041 // Any calls to get the active config will return a default value.
3042 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3043 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3044 Return(Error::NONE)));
3045
3046 // Any calls to get whether the display supports dozing will return the value set by the
3047 // policy variant.
3048 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3049 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3050
3051 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3052 }
3053
3054 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3055 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3056 }
3057};
3058
3059// A sample configuration for the primary display.
3060// In addition to having event thread support, we emulate doze support.
3061template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003062using PrimaryDisplayPowerCase =
3063 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3064 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3065 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003066
3067// A sample configuration for the external display.
3068// In addition to not having event thread support, we emulate not having doze
3069// support.
3070template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003071using ExternalDisplayPowerCase =
3072 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3073 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3074 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003075
3076class SetPowerModeInternalTest : public DisplayTransactionTest {
3077public:
3078 template <typename Case>
3079 void transitionDisplayCommon();
3080};
3081
3082template <int PowerMode>
3083struct PowerModeInitialVSyncEnabled : public std::false_type {};
3084
3085template <>
3086struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3087
3088template <>
3089struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3090
3091template <typename Case>
3092void SetPowerModeInternalTest::transitionDisplayCommon() {
3093 // --------------------------------------------------------------------
3094 // Preconditions
3095
Peiyong Lined531a32018-10-26 18:27:56 -07003096 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003097 auto display =
3098 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3099 Case::setInitialPrimaryHWVsyncEnabled(this,
3100 PowerModeInitialVSyncEnabled<
3101 Case::Transition::INITIAL_POWER_MODE>::value);
3102
3103 // --------------------------------------------------------------------
3104 // Call Expectations
3105
3106 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3107 Case::Transition::template setupCallExpectations<Case>(this);
3108
3109 // --------------------------------------------------------------------
3110 // Invocation
3111
3112 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3113 Case::Transition::TARGET_POWER_MODE);
3114
3115 // --------------------------------------------------------------------
3116 // Postconditions
3117
3118 Case::Transition::verifyPostconditions(this);
3119}
3120
3121TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3122 using Case = SimplePrimaryDisplayCase;
3123
3124 // --------------------------------------------------------------------
3125 // Preconditions
3126
3127 // A primary display device is set up
3128 Case::Display::injectHwcDisplay(this);
3129 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3130 display.inject();
3131
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003132 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003133 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3134
3135 // --------------------------------------------------------------------
3136 // Invocation
3137
3138 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3139
3140 // --------------------------------------------------------------------
3141 // Postconditions
3142
3143 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3144}
3145
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003146TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003147 using Case = HwcVirtualDisplayCase;
3148
3149 // --------------------------------------------------------------------
3150 // Preconditions
3151
Dominik Laskowski075d3172018-05-24 15:50:06 -07003152 // Insert display data so that the HWC thinks it created the virtual display.
3153 const auto displayId = Case::Display::DISPLAY_ID::get();
3154 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003155 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003156
3157 // A virtual display device is set up
3158 Case::Display::injectHwcDisplay(this);
3159 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3160 display.inject();
3161
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003162 // The display is set to HWC_POWER_MODE_NORMAL
3163 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003164
3165 // --------------------------------------------------------------------
3166 // Invocation
3167
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003168 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003169
3170 // --------------------------------------------------------------------
3171 // Postconditions
3172
3173 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3174}
3175
3176TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3177 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3178}
3179
3180TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3181 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3182}
3183
3184TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3185 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3186}
3187
3188TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3189 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3190}
3191
3192TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3193 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3194}
3195
3196TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3197 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3198}
3199
3200TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3201 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3202}
3203
3204TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3205 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3206}
3207
3208TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3209 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3210}
3211
3212TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3213 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3214}
3215
3216TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3217 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3218}
3219
3220TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3221 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3222}
3223
3224TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3225 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3226}
3227
3228TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3229 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3230}
3231
3232TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3233 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3234}
3235
3236TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3237 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3238}
3239
3240TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3241 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3242}
3243
3244TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3245 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3246}
3247
3248TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3249 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3250}
3251
3252TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3253 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3254}
3255
Lloyd Piquef58625d2017-12-19 13:22:33 -08003256} // namespace
3257} // namespace android