blob: 8f6f3ecfe4a4b93953da5920f5817531b36980fc [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
Lloyd Pique1fa4d462018-01-22 18:03:16 -080098 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -080099 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800100
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700101 void injectMockScheduler();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800102 void injectMockComposer(int virtualDisplayCount);
103 void injectFakeBufferQueueFactory();
104 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800105
106 // --------------------------------------------------------------------
107 // Postcondition helpers
108
Dominik Laskowski075d3172018-05-24 15:50:06 -0700109 bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800110 bool hasTransactionFlagSet(int flag);
111 bool hasDisplayDevice(sp<IBinder> displayToken);
112 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
113 bool hasCurrentDisplayState(sp<IBinder> displayToken);
114 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
115 bool hasDrawingDisplayState(sp<IBinder> displayToken);
116 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
117
118 // --------------------------------------------------------------------
119 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800120
Lloyd Piquef58625d2017-12-19 13:22:33 -0800121 TestableSurfaceFlinger mFlinger;
Alec Mouriba013fa2018-10-16 12:43:11 -0700122 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800123 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800124
125 // These mocks are created by the test, but are destroyed by SurfaceFlinger
126 // by virtue of being stored into a std::unique_ptr. However we still need
127 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700128 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800129 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800130 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
131 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700132
133 mock::DispSync* mPrimaryDispSync = new mock::DispSync;
134 mock::EventControlThread* mEventControlThread = new mock::EventControlThread;
135 mock::EventThread* mEventThread = new mock::EventThread;
136 mock::EventThread* mSFEventThread = new mock::EventThread;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800137
138 // These mocks are created only when expected to be created via a factory.
139 sp<mock::GraphicBufferConsumer> mConsumer;
140 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700141 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800142};
143
144DisplayTransactionTest::DisplayTransactionTest() {
145 const ::testing::TestInfo* const test_info =
146 ::testing::UnitTest::GetInstance()->current_test_info();
147 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800148
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800149 // Default to no wide color display support configured
150 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700151 mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800152 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
153
154 // Default to using HWC virtual displays
155 mFlinger.mutableUseHwcVirtualDisplays() = true;
156
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800157 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
158 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
159 });
160
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800161 mFlinger.setCreateNativeWindowSurface([](auto) {
162 ADD_FAILURE() << "Unexpected request to create a native window surface.";
163 return nullptr;
164 });
165
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700166 injectMockScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800167 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700168 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800169 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800170
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800171 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800172}
173
174DisplayTransactionTest::~DisplayTransactionTest() {
175 const ::testing::TestInfo* const test_info =
176 ::testing::UnitTest::GetInstance()->current_test_info();
177 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
178}
179
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700180void DisplayTransactionTest::injectMockScheduler() {
Ana Krulecafb45842019-02-13 13:33:03 -0800181 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
182 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
183
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700184 mFlinger.setupScheduler(std::unique_ptr<DispSync>(mPrimaryDispSync),
185 std::unique_ptr<EventControlThread>(mEventControlThread),
186 std::unique_ptr<EventThread>(mEventThread),
187 std::unique_ptr<EventThread>(mSFEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800188}
189
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800190void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
191 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800192 EXPECT_CALL(*mComposer, getCapabilities())
193 .WillOnce(Return(std::vector<IComposer::Capability>()));
194 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
195 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800196
Lloyd Piquee39cad22017-12-20 17:01:29 -0800197 Mock::VerifyAndClear(mComposer);
198}
199
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800200void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800201 // This setup is only expected once per test.
202 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
203
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800204 mConsumer = new mock::GraphicBufferConsumer();
205 mProducer = new mock::GraphicBufferProducer();
206
207 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
208 *outProducer = mProducer;
209 *outConsumer = mConsumer;
210 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800211}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800212
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800213void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800214 // This setup is only expected once per test.
215 ASSERT_TRUE(mNativeWindowSurface == nullptr);
216
Lloyd Pique22098362018-09-13 11:46:49 -0700217 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800218
Lloyd Pique22098362018-09-13 11:46:49 -0700219 mFlinger.setCreateNativeWindowSurface([this](auto) {
220 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
221 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800222}
223
Dominik Laskowski075d3172018-05-24 15:50:06 -0700224bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) {
225 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800226}
227
228bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
229 return mFlinger.mutableTransactionFlags() & flag;
230}
231
232bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700233 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800234}
235
236sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700237 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800238}
239
240bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
241 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
242}
243
244const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
245 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
246}
247
248bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
249 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
250}
251
252const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
253 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
254}
255
256/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800257 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800258 */
259
Dominik Laskowski075d3172018-05-24 15:50:06 -0700260template <typename PhysicalDisplay>
261struct PhysicalDisplayId {};
262
Dominik Laskowski34157762018-10-31 13:07:19 -0700263template <DisplayId::Type displayId>
264using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700265
266struct NoDisplayId {};
267
268template <typename>
269struct IsPhysicalDisplayId : std::bool_constant<false> {};
270
271template <typename PhysicalDisplay>
272struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
273
274template <typename>
275struct DisplayIdGetter;
276
277template <typename PhysicalDisplay>
278struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
279 static std::optional<DisplayId> get() {
280 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
281 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
282 ? HWC_DISPLAY_PRIMARY
283 : HWC_DISPLAY_EXTERNAL);
284 }
285
286 const auto info =
287 parseDisplayIdentificationData(PhysicalDisplay::PORT,
288 PhysicalDisplay::GET_IDENTIFICATION_DATA());
289 return info ? std::make_optional(info->id) : std::nullopt;
290 }
291};
292
Dominik Laskowski34157762018-10-31 13:07:19 -0700293template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700294struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700295 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700296};
297
298template <>
299struct DisplayIdGetter<NoDisplayId> {
300 static std::optional<DisplayId> get() { return {}; }
301};
302
303// DisplayIdType can be:
304// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
305// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
306// 3) NoDisplayId for virtual display without HWC backing.
307template <typename DisplayIdType, int width, int height, Critical critical, Async async,
308 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800309struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700310 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
311
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800312 // The display width and height
313 static constexpr int WIDTH = width;
314 static constexpr int HEIGHT = height;
315
316 static constexpr int GRALLOC_USAGE = grallocUsage;
317
Dominik Laskowski075d3172018-05-24 15:50:06 -0700318 // Whether the display is virtual or physical
319 static constexpr Virtual VIRTUAL =
320 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800321
322 // When creating native window surfaces for the framebuffer, whether those should be critical
323 static constexpr Critical CRITICAL = critical;
324
325 // When creating native window surfaces for the framebuffer, whether those should be async
326 static constexpr Async ASYNC = async;
327
328 // Whether the display should be treated as secure
329 static constexpr Secure SECURE = secure;
330
Dominik Laskowski075d3172018-05-24 15:50:06 -0700331 // Whether the display is primary
332 static constexpr Primary PRIMARY = primary;
333
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800334 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700335 auto injector =
336 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(),
337 static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY));
338
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800339 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700340 injector.setNativeWindow(test->mNativeWindow);
341
342 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800343 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700344 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
345 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
346 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
347 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800348 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
349 .WillRepeatedly(Return(0));
350 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
351 .WillRepeatedly(Return(0));
352 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
353 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700354 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
355 .WillRepeatedly(Return(0));
356
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800357 return injector;
358 }
359
360 // Called by tests to set up any native window creation call expectations.
361 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
362 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
363 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800364
Alec Mouriba013fa2018-10-16 12:43:11 -0700365 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
366 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
367 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
368 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800369 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
370 .WillRepeatedly(Return(0));
371 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
372 .WillRepeatedly(Return(0));
373 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
374 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700375 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
376 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800377 }
378
379 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
380 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
381 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
382 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
383 .WillRepeatedly(Return(NO_ERROR));
384 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
385 .WillRepeatedly(Return(NO_ERROR));
386 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
387 .WillRepeatedly(Return(NO_ERROR));
388 }
389
390 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
391 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
392 }
393};
394
Dominik Laskowski075d3172018-05-24 15:50:06 -0700395template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
396 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800397struct HwcDisplayVariant {
398 // The display id supplied by the HWC
399 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
400
401 // The HWC display type
402 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
403
404 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700405 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700406 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800407
408 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
409 HWC2::Connection connection) {
410 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
411 HotplugEvent{HWC_DISPLAY_ID, connection});
412 }
413
414 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800415 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700416 const auto displayId = DisplayVariant::DISPLAY_ID::get();
417 ASSERT_TRUE(displayId);
418 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
419 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800420 .setHwcDisplayId(HWC_DISPLAY_ID)
421 .setWidth(DisplayVariant::WIDTH)
422 .setHeight(DisplayVariant::HEIGHT)
423 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700424 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800425 .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)));
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700433 EXPECT_CALL(*test->mComposer,
434 setPowerMode(HWC_DISPLAY_ID,
435 static_cast<Hwc2::IComposerClient::PowerMode>(INIT_POWER_MODE)))
436 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800437 injectHwcDisplayWithNoDefaultCapabilities(test);
438 }
439
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800440 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
441 EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _))
442 .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>(
443 HWC_DISPLAY_TYPE)),
444 Return(Error::NONE)));
445 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
446 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
447 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
448 Return(Error::NONE)));
449 EXPECT_CALL(*test->mComposer,
450 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
451 IComposerClient::Attribute::WIDTH, _))
452 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
453 EXPECT_CALL(*test->mComposer,
454 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
455 IComposerClient::Attribute::HEIGHT, _))
456 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
457 EXPECT_CALL(*test->mComposer,
458 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
459 IComposerClient::Attribute::VSYNC_PERIOD, _))
460 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
461 EXPECT_CALL(*test->mComposer,
462 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
463 IComposerClient::Attribute::DPI_X, _))
464 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
465 EXPECT_CALL(*test->mComposer,
466 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
467 IComposerClient::Attribute::DPI_Y, _))
468 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700469
470 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
471 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
472 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
473 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
474 Return(Error::NONE)));
475 } else {
476 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
477 .WillOnce(Return(Error::UNSUPPORTED));
478 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800479 }
480
481 // Called by tests to set up HWC call expectations
482 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
483 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700484 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800485 }
486};
487
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800488// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
489constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
490 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
491
Dominik Laskowski075d3172018-05-24 15:50:06 -0700492template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800493 Critical critical>
494struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700495 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
496 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
497 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
498 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
499 critical, Async::FALSE, Secure::TRUE,
500 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
501 PhysicalDisplay> {};
502
503template <bool hasIdentificationData>
504struct PrimaryDisplay {
505 static constexpr Primary PRIMARY = Primary::TRUE;
506 static constexpr uint8_t PORT = 255;
507 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
508 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
509};
510
511template <bool hasIdentificationData>
512struct ExternalDisplay {
513 static constexpr Primary PRIMARY = Primary::FALSE;
514 static constexpr uint8_t PORT = 254;
515 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
516 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
517};
518
519struct TertiaryDisplay {
520 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800521 static constexpr uint8_t PORT = 253;
522 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700523};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800524
525// A primary display is a physical display that is critical
526using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700527 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800528
529// An external display is physical display that is not critical.
530using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700531 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800532
533using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700534 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800535
536// A virtual display not supported by the HWC.
537constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
538
539template <int width, int height, Secure secure>
540struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700541 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
542 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
543 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
544 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
545
546 static void injectHwcDisplay(DisplayTransactionTest*) {}
547
548 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
549 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
550 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800551
552 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
553 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
554 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
555 }
556};
557
558// A virtual display supported by the HWC.
559constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
560
561template <int width, int height, Secure secure>
562struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700563 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
564 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
565 HwcDisplayVariant<
566 1010, HWC2::DisplayType::Virtual,
567 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
568 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
569 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
570 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800571 using Self = HwcVirtualDisplayVariant<width, height, secure>;
572
573 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
574 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
575 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
576 }
577
578 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
579 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
580 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
581 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
582 }
583};
584
585// For this variant, SurfaceFlinger should not configure itself with wide
586// display support, so the display should not be configured for wide-color
587// support.
588struct WideColorSupportNotConfiguredVariant {
589 static constexpr bool WIDE_COLOR_SUPPORTED = false;
590
591 static void injectConfigChange(DisplayTransactionTest* test) {
592 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700593 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800594 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
595 }
596
597 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
598 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
599 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
600 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
601 }
602};
603
604// For this variant, SurfaceFlinger should configure itself with wide display
605// support, and the display should respond with an non-empty list of supported
606// color modes. Wide-color support should be configured.
607template <typename Display>
608struct WideColorP3ColorimetricSupportedVariant {
609 static constexpr bool WIDE_COLOR_SUPPORTED = true;
610
611 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700612 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800613 test->mFlinger.mutableHasWideColorDisplay() = true;
614 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
615 }
616
617 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800618 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
619
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800620 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
621 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
622 Return(Error::NONE)));
623 EXPECT_CALL(*test->mComposer,
624 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
625 .WillOnce(DoAll(SetArgPointee<2>(
626 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
627 Return(Error::NONE)));
628 EXPECT_CALL(*test->mComposer,
629 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
630 RenderIntent::COLORIMETRIC))
631 .WillOnce(Return(Error::NONE));
632 }
633};
634
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800635// For this variant, SurfaceFlinger should configure itself with wide display
636// support, but the display should respond with an empty list of supported color
637// modes. Wide-color support for the display should not be configured.
638template <typename Display>
639struct WideColorNotSupportedVariant {
640 static constexpr bool WIDE_COLOR_SUPPORTED = false;
641
642 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700643 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800644 test->mFlinger.mutableHasWideColorDisplay() = true;
645 }
646
647 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
648 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
649 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700650 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800651 }
652};
653
654// For this variant, the display is not a HWC display, so no HDR support should
655// be configured.
656struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800657 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800658 static constexpr bool HDR10_SUPPORTED = false;
659 static constexpr bool HDR_HLG_SUPPORTED = false;
660 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
661 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
662 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
663 }
664};
665
Valerie Haue9e843a2018-12-18 13:39:23 -0800666template <typename Display>
667struct Hdr10PlusSupportedVariant {
668 static constexpr bool HDR10_PLUS_SUPPORTED = true;
669 static constexpr bool HDR10_SUPPORTED = true;
670 static constexpr bool HDR_HLG_SUPPORTED = false;
671 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
672 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
673 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
674 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
675 Hdr::HDR10_PLUS,
676 Hdr::HDR10,
677 })),
678 Return(Error::NONE)));
679 }
680};
681
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800682// For this variant, the composer should respond with a non-empty list of HDR
683// modes containing HDR10, so HDR10 support should be configured.
684template <typename Display>
685struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800686 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800687 static constexpr bool HDR10_SUPPORTED = true;
688 static constexpr bool HDR_HLG_SUPPORTED = false;
689 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
690 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
691 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
692 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
693 Return(Error::NONE)));
694 }
695};
696
697// For this variant, the composer should respond with a non-empty list of HDR
698// modes containing HLG, so HLG support should be configured.
699template <typename Display>
700struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800701 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800702 static constexpr bool HDR10_SUPPORTED = false;
703 static constexpr bool HDR_HLG_SUPPORTED = true;
704 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
705 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
706 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
707 .WillOnce(
708 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
709 }
710};
711
712// For this variant, the composer should respond with a non-empty list of HDR
713// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
714template <typename Display>
715struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800716 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800717 static constexpr bool HDR10_SUPPORTED = false;
718 static constexpr bool HDR_HLG_SUPPORTED = false;
719 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
720 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
721 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
722 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
723 Return(Error::NONE)));
724 }
725};
726
727// For this variant, the composer should respond with am empty list of HDR
728// modes, so no HDR support should be configured.
729template <typename Display>
730struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800731 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800732 static constexpr bool HDR10_SUPPORTED = false;
733 static constexpr bool HDR_HLG_SUPPORTED = false;
734 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
735 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
736 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
737 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
738 }
739};
740
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700741struct NonHwcPerFrameMetadataSupportVariant {
742 static constexpr int PER_FRAME_METADATA_KEYS = 0;
743 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800744 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700745 }
746};
747
748template <typename Display>
749struct NoPerFrameMetadataSupportVariant {
750 static constexpr int PER_FRAME_METADATA_KEYS = 0;
751 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800752 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
753 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700754 }
755};
756
757template <typename Display>
758struct Smpte2086PerFrameMetadataSupportVariant {
759 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
760 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800761 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
762 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800763 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
764 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
765 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
766 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
767 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
768 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
769 PerFrameMetadataKey::WHITE_POINT_X,
770 PerFrameMetadataKey::WHITE_POINT_Y,
771 PerFrameMetadataKey::MAX_LUMINANCE,
772 PerFrameMetadataKey::MIN_LUMINANCE,
773 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700774 }
775};
776
777template <typename Display>
778struct Cta861_3_PerFrameMetadataSupportVariant {
779 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
780 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800781 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
782 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800783 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
784 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
785 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700786 }
787};
788
Valerie Haue9e843a2018-12-18 13:39:23 -0800789template <typename Display>
790struct Hdr10_Plus_PerFrameMetadataSupportVariant {
791 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
792 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
793 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
794 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
795 PerFrameMetadataKey::HDR10_PLUS_SEI,
796 })));
797 }
798};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800799/* ------------------------------------------------------------------------
800 * Typical display configurations to test
801 */
802
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700803template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
804 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800805struct Case {
806 using Display = DisplayPolicy;
807 using WideColorSupport = WideColorSupportPolicy;
808 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700809 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800810};
811
812using SimplePrimaryDisplayCase =
813 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700814 HdrNotSupportedVariant<PrimaryDisplayVariant>,
815 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800816using SimpleExternalDisplayCase =
817 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700818 HdrNotSupportedVariant<ExternalDisplayVariant>,
819 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800820using SimpleTertiaryDisplayCase =
821 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700822 HdrNotSupportedVariant<TertiaryDisplayVariant>,
823 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800824using NonHwcVirtualDisplayCase =
825 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700826 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
827 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800828using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
829using HwcVirtualDisplayCase =
830 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700831 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800832 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800833using WideColorP3ColorimetricDisplayCase =
834 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700835 HdrNotSupportedVariant<PrimaryDisplayVariant>,
836 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800837using Hdr10PlusDisplayCase =
838 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
839 Hdr10SupportedVariant<PrimaryDisplayVariant>,
840 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800841using Hdr10DisplayCase =
842 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700843 Hdr10SupportedVariant<PrimaryDisplayVariant>,
844 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800845using HdrHlgDisplayCase =
846 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700847 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
848 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800849using HdrDolbyVisionDisplayCase =
850 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700851 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
852 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
853using HdrSmpte2086DisplayCase =
854 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
855 HdrNotSupportedVariant<PrimaryDisplayVariant>,
856 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
857using HdrCta861_3_DisplayCase =
858 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
859 HdrNotSupportedVariant<PrimaryDisplayVariant>,
860 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700861
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800862/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800863 *
864 * SurfaceFlinger::onHotplugReceived
865 */
866
867TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
868 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700869 constexpr hwc2_display_t hwcDisplayId1 = 456;
870 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800871
872 // --------------------------------------------------------------------
873 // Preconditions
874
875 // Set the current sequence id for accepted events
876 mFlinger.mutableComposerSequenceId() = currentSequenceId;
877
878 // Set the main thread id so that the current thread does not appear to be
879 // the main thread.
880 mFlinger.mutableMainThreadId() = std::thread::id();
881
882 // --------------------------------------------------------------------
883 // Call Expectations
884
885 // We expect invalidate() to be invoked once to trigger display transaction
886 // processing.
887 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
888
889 // --------------------------------------------------------------------
890 // Invocation
891
892 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700893 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
894 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800895
896 // --------------------------------------------------------------------
897 // Postconditions
898
899 // The display transaction needed flag should be set.
900 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
901
902 // All events should be in the pending event queue.
903 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
904 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700905 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800906 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700907 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800908 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
909}
910
911TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
912 constexpr int currentSequenceId = 123;
913 constexpr int otherSequenceId = 321;
914 constexpr hwc2_display_t displayId = 456;
915
916 // --------------------------------------------------------------------
917 // Preconditions
918
919 // Set the current sequence id for accepted events
920 mFlinger.mutableComposerSequenceId() = currentSequenceId;
921
922 // Set the main thread id so that the current thread does not appear to be
923 // the main thread.
924 mFlinger.mutableMainThreadId() = std::thread::id();
925
926 // --------------------------------------------------------------------
927 // Call Expectations
928
929 // We do not expect any calls to invalidate().
930 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
931
932 // --------------------------------------------------------------------
933 // Invocation
934
935 // Call with an unexpected sequence id
936 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
937
938 // --------------------------------------------------------------------
939 // Postconditions
940
941 // The display transaction needed flag should not be set
942 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
943
944 // There should be no pending events
945 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
946}
947
948TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
949 constexpr int currentSequenceId = 123;
950 constexpr hwc2_display_t displayId1 = 456;
951
952 // --------------------------------------------------------------------
953 // Note:
954 // --------------------------------------------------------------------
955 // This test case is a bit tricky. We want to verify that
956 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
957 // don't really want to provide coverage for everything the later function
958 // does as there are specific tests for it.
959 // --------------------------------------------------------------------
960
961 // --------------------------------------------------------------------
962 // Preconditions
963
964 // Set the current sequence id for accepted events
965 mFlinger.mutableComposerSequenceId() = currentSequenceId;
966
967 // Set the main thread id so that the current thread does appear to be the
968 // main thread.
969 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
970
971 // --------------------------------------------------------------------
972 // Call Expectations
973
974 // We expect invalidate() to be invoked once to trigger display transaction
975 // processing.
976 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
977
978 // --------------------------------------------------------------------
979 // Invocation
980
981 // Simulate a disconnect on a display id that is not connected. This should
982 // be enqueued by onHotplugReceived(), and dequeued by
983 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
984 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
985
986 // --------------------------------------------------------------------
987 // Postconditions
988
989 // The display transaction needed flag should be set.
990 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
991
992 // There should be no event queued on return, as it should have been
993 // processed.
994 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
995}
996
997/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -0800998 * SurfaceFlinger::createDisplay
999 */
1000
1001TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1002 const String8 name("virtual.test");
1003
1004 // --------------------------------------------------------------------
1005 // Call Expectations
1006
1007 // The call should notify the interceptor that a display was created.
1008 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1009
1010 // --------------------------------------------------------------------
1011 // Invocation
1012
1013 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1014
1015 // --------------------------------------------------------------------
1016 // Postconditions
1017
1018 // The display should have been added to the current state
1019 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1020 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001021 EXPECT_TRUE(display.isVirtual());
1022 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001023 EXPECT_EQ(name.string(), display.displayName);
1024
1025 // --------------------------------------------------------------------
1026 // Cleanup conditions
1027
1028 // Destroying the display invalidates the display state.
1029 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1030}
1031
1032TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1033 const String8 name("virtual.test");
1034
1035 // --------------------------------------------------------------------
1036 // Call Expectations
1037
1038 // The call should notify the interceptor that a display was created.
1039 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1040
1041 // --------------------------------------------------------------------
1042 // Invocation
1043
1044 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1045
1046 // --------------------------------------------------------------------
1047 // Postconditions
1048
1049 // The display should have been added to the current state
1050 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1051 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001052 EXPECT_TRUE(display.isVirtual());
1053 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001054 EXPECT_EQ(name.string(), display.displayName);
1055
1056 // --------------------------------------------------------------------
1057 // Cleanup conditions
1058
1059 // Destroying the display invalidates the display state.
1060 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1061}
1062
1063/* ------------------------------------------------------------------------
1064 * SurfaceFlinger::destroyDisplay
1065 */
1066
1067TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1068 using Case = NonHwcVirtualDisplayCase;
1069
1070 // --------------------------------------------------------------------
1071 // Preconditions
1072
1073 // A virtual display exists
1074 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1075 existing.inject();
1076
1077 // --------------------------------------------------------------------
1078 // Call Expectations
1079
1080 // The call should notify the interceptor that a display was created.
1081 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1082
1083 // Destroying the display invalidates the display state.
1084 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1085
1086 // --------------------------------------------------------------------
1087 // Invocation
1088
1089 mFlinger.destroyDisplay(existing.token());
1090
1091 // --------------------------------------------------------------------
1092 // Postconditions
1093
1094 // The display should have been removed from the current state
1095 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1096
1097 // Ths display should still exist in the drawing state
1098 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1099
1100 // The display transaction needed flasg should be set
1101 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1102}
1103
1104TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1105 // --------------------------------------------------------------------
1106 // Preconditions
1107
1108 sp<BBinder> displayToken = new BBinder();
1109
1110 // --------------------------------------------------------------------
1111 // Invocation
1112
1113 mFlinger.destroyDisplay(displayToken);
1114}
1115
1116/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001117 * SurfaceFlinger::resetDisplayState
1118 */
1119
1120TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1121 using Case = NonHwcVirtualDisplayCase;
1122
1123 // --------------------------------------------------------------------
1124 // Preconditions
1125
1126 // vsync is enabled and available
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001127 mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = true;
1128 mFlinger.scheduler()->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001129
1130 // A display exists
1131 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1132 existing.inject();
1133
1134 // --------------------------------------------------------------------
1135 // Call Expectations
1136
1137 // The call disable vsyncs
1138 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1139
Lloyd Pique41be5d22018-06-21 13:11:48 -07001140 // The call ends any display resyncs
1141 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1142
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001143 // --------------------------------------------------------------------
1144 // Invocation
1145
1146 mFlinger.resetDisplayState();
1147
1148 // --------------------------------------------------------------------
1149 // Postconditions
1150
1151 // vsyncs should be off and not available.
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07001152 EXPECT_FALSE(mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled());
1153 EXPECT_FALSE(mFlinger.scheduler()->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001154
1155 // The display should have been removed from the display map.
1156 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1157
1158 // The display should still exist in the current state
1159 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1160
1161 // The display should have been removed from the drawing state
1162 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1163}
1164
1165/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001166 * DisplayDevice::GetBestColorMode
1167 */
1168class GetBestColorModeTest : public DisplayTransactionTest {
1169public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001170 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001171
Valerie Hau9758ae02018-10-09 16:05:09 -07001172 GetBestColorModeTest()
1173 : DisplayTransactionTest(),
Dominik Laskowski075d3172018-05-24 15:50:06 -07001174 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */,
1175 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001176
1177 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1178
1179 void addHwcColorModesMapping(ui::ColorMode colorMode,
1180 std::vector<ui::RenderIntent> renderIntents) {
1181 mHwcColorModes[colorMode] = renderIntents;
1182 }
1183
1184 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1185
1186 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1187
1188 void getBestColorMode() {
1189 mInjector.setHwcColorModes(mHwcColorModes);
1190 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001191 mInjector.setNativeWindow(mNativeWindow);
1192
1193 // Creating a DisplayDevice requires getting default dimensions from the
1194 // native window.
1195 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1196 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1197 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1198 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001199 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1200 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1201 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07001202 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001203 auto displayDevice = mInjector.inject();
1204
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001205 displayDevice->getCompositionDisplay()
1206 ->getDisplayColorProfile()
1207 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1208 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001209 }
1210
1211 ui::Dataspace mOutDataspace;
1212 ui::ColorMode mOutColorMode;
1213 ui::RenderIntent mOutRenderIntent;
1214
1215private:
1216 ui::Dataspace mInputDataspace;
1217 ui::RenderIntent mInputRenderIntent;
1218 bool mHasWideColorGamut = false;
1219 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1220 FakeDisplayDeviceInjector mInjector;
1221};
1222
1223TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1224 addHwcColorModesMapping(ui::ColorMode::SRGB,
1225 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1226 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1227 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1228 setHasWideColorGamut(true);
1229
1230 getBestColorMode();
1231
Peiyong Lin14724e62018-12-05 07:27:30 -08001232 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001233 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1234 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1235}
1236
1237TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1238 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1239 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1240 addHwcColorModesMapping(ui::ColorMode::SRGB,
1241 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1242 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1243 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1244 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1245 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1246 setHasWideColorGamut(true);
1247
1248 getBestColorMode();
1249
1250 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1251 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1252 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1253}
1254
1255TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1256 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1257 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1258 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1259 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1260 setHasWideColorGamut(true);
1261
1262 getBestColorMode();
1263
1264 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1265 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1266 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1267}
1268
1269/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001270 * SurfaceFlinger::getDisplayNativePrimaries
1271 */
1272
1273class GetDisplayNativePrimaries : public DisplayTransactionTest {
1274public:
1275 GetDisplayNativePrimaries();
1276 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1277 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1278
1279private:
1280 static constexpr float mStartingTestValue = 1.0f;
1281};
1282
1283GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1284 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1285 injectFakeNativeWindowSurfaceFactory();
1286}
1287
1288void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1289 ui::DisplayPrimaries& primaries) {
1290 float startingVal = mStartingTestValue;
1291 primaries.red.X = startingVal++;
1292 primaries.red.Y = startingVal++;
1293 primaries.red.Z = startingVal++;
1294 primaries.green.X = startingVal++;
1295 primaries.green.Y = startingVal++;
1296 primaries.green.Z = startingVal++;
1297 primaries.blue.X = startingVal++;
1298 primaries.blue.Y = startingVal++;
1299 primaries.blue.Z = startingVal++;
1300 primaries.white.X = startingVal++;
1301 primaries.white.Y = startingVal++;
1302 primaries.white.Z = startingVal++;
1303}
1304
1305void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1306 const ui::DisplayPrimaries& primaries) {
1307 float startingVal = mStartingTestValue;
1308 EXPECT_EQ(primaries.red.X, startingVal++);
1309 EXPECT_EQ(primaries.red.Y, startingVal++);
1310 EXPECT_EQ(primaries.red.Z, startingVal++);
1311 EXPECT_EQ(primaries.green.X, startingVal++);
1312 EXPECT_EQ(primaries.green.Y, startingVal++);
1313 EXPECT_EQ(primaries.green.Z, startingVal++);
1314 EXPECT_EQ(primaries.blue.X, startingVal++);
1315 EXPECT_EQ(primaries.blue.Y, startingVal++);
1316 EXPECT_EQ(primaries.blue.Z, startingVal++);
1317 EXPECT_EQ(primaries.white.X, startingVal++);
1318 EXPECT_EQ(primaries.white.Y, startingVal++);
1319 EXPECT_EQ(primaries.white.Z, startingVal++);
1320}
1321
1322TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1323 ui::DisplayPrimaries primaries;
1324 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1325}
1326
Daniel Solomon42d04562019-01-20 21:03:19 -08001327TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1328 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1329 injector.inject();
1330 auto internalDisplayToken = injector.token();
1331
1332 ui::DisplayPrimaries expectedPrimaries;
1333 populateDummyDisplayNativePrimaries(expectedPrimaries);
1334 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1335
1336 ui::DisplayPrimaries primaries;
1337 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1338
1339 checkDummyDisplayNativePrimaries(primaries);
1340}
1341
1342TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1343 sp<BBinder> notInternalDisplayToken = new BBinder();
1344
1345 ui::DisplayPrimaries primaries;
1346 populateDummyDisplayNativePrimaries(primaries);
1347 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1348
1349 // Check primaries argument wasn't modified in case of failure
1350 checkDummyDisplayNativePrimaries(primaries);
1351}
1352
1353/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001354 * SurfaceFlinger::setupNewDisplayDeviceInternal
1355 */
1356
1357class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1358public:
1359 template <typename T>
1360 void setupNewDisplayDeviceInternalTest();
1361};
1362
1363template <typename Case>
1364void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1365 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001366 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1367 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001368 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001369
1370 // --------------------------------------------------------------------
1371 // Preconditions
1372
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001373 // Wide color displays support is configured appropriately
1374 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001375
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001376 // The display is setup with the HWC.
1377 Case::Display::injectHwcDisplay(this);
1378
1379 // SurfaceFlinger will use a test-controlled factory for native window
1380 // surfaces.
1381 injectFakeNativeWindowSurfaceFactory();
1382
1383 // --------------------------------------------------------------------
1384 // Call Expectations
1385
1386 // Various native window calls will be made.
1387 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001388 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001389 Case::WideColorSupport::setupComposerCallExpectations(this);
1390 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001391 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001392
1393 // --------------------------------------------------------------------
1394 // Invocation
1395
1396 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001397 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1398 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001399 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1400
Dominik Laskowski075d3172018-05-24 15:50:06 -07001401 auto device =
1402 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1403 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001404
1405 // --------------------------------------------------------------------
1406 // Postconditions
1407
1408 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001409 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1410 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001411 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001412 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001413 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1414 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1415 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001416 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001417 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1418 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1419 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001420 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1421 // remapped, and the test only ever sets up one config. If there were an error
1422 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
1423 EXPECT_EQ(0, device->getActiveConfig());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001424 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1425 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001426}
1427
1428TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1429 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1430}
1431
1432TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1433 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1434}
1435
1436TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1437 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1438}
1439
1440TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001441 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001442
Dominik Laskowski075d3172018-05-24 15:50:06 -07001443 // Insert display data so that the HWC thinks it created the virtual display.
1444 const auto displayId = Case::Display::DISPLAY_ID::get();
1445 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001446 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001447
1448 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001449}
1450
1451TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1452 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1453}
1454
Valerie Haue9e843a2018-12-18 13:39:23 -08001455TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1456 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1457}
1458
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001459TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1460 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1461}
1462
1463TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1464 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1465}
1466
1467TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1468 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1469}
1470
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001471TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1472 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1473}
1474
1475TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1476 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1477}
1478
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001479/* ------------------------------------------------------------------------
1480 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1481 */
1482
1483class HandleTransactionLockedTest : public DisplayTransactionTest {
1484public:
1485 template <typename Case>
1486 void setupCommonPreconditions();
1487
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001488 template <typename Case, bool connected>
1489 static void expectHotplugReceived(mock::EventThread*);
1490
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001491 template <typename Case>
1492 void setupCommonCallExpectationsForConnectProcessing();
1493
1494 template <typename Case>
1495 void setupCommonCallExpectationsForDisconnectProcessing();
1496
1497 template <typename Case>
1498 void processesHotplugConnectCommon();
1499
1500 template <typename Case>
1501 void ignoresHotplugConnectCommon();
1502
1503 template <typename Case>
1504 void processesHotplugDisconnectCommon();
1505
1506 template <typename Case>
1507 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1508
1509 template <typename Case>
1510 void verifyPhysicalDisplayIsConnected();
1511
1512 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1513};
1514
1515template <typename Case>
1516void HandleTransactionLockedTest::setupCommonPreconditions() {
1517 // Wide color displays support is configured appropriately
1518 Case::WideColorSupport::injectConfigChange(this);
1519
1520 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1521 injectFakeBufferQueueFactory();
1522
1523 // SurfaceFlinger will use a test-controlled factory for native window
1524 // surfaces.
1525 injectFakeNativeWindowSurfaceFactory();
1526}
1527
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001528template <typename Case, bool connected>
1529void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1530 const auto convert = [](auto physicalDisplayId) {
1531 return std::make_optional(DisplayId{physicalDisplayId});
1532 };
1533
1534 EXPECT_CALL(*eventThread,
1535 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1536 .Times(1);
1537}
1538
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001539template <typename Case>
1540void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1541 Case::Display::setupHwcHotplugCallExpectations(this);
1542
1543 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1544 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1545 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1546 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1547
1548 Case::WideColorSupport::setupComposerCallExpectations(this);
1549 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001550 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001551
1552 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001553 expectHotplugReceived<Case, true>(mEventThread);
1554 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001555}
1556
1557template <typename Case>
1558void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1559 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001560
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001561 expectHotplugReceived<Case, false>(mEventThread);
1562 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001563}
1564
1565template <typename Case>
1566void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1567 // The display device should have been set up in the list of displays.
1568 ASSERT_TRUE(hasDisplayDevice(displayToken));
1569 const auto& device = getDisplayDevice(displayToken);
1570 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001571 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001572
1573 // The display should have been set up in the current display state
1574 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1575 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001576 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1577 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1578 : Case::Display::DISPLAY_ID::get(),
1579 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001580
1581 // The display should have been set up in the drawing display state
1582 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1583 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001584 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1585 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1586 : Case::Display::DISPLAY_ID::get(),
1587 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001588}
1589
1590template <typename Case>
1591void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1592 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001593 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001594
Dominik Laskowski075d3172018-05-24 15:50:06 -07001595 // SF should have a display token.
1596 const auto displayId = Case::Display::DISPLAY_ID::get();
1597 ASSERT_TRUE(displayId);
1598 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1599 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001600
1601 verifyDisplayIsConnected<Case>(displayToken);
1602}
1603
1604void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1605 EXPECT_FALSE(hasDisplayDevice(displayToken));
1606 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1607 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1608}
1609
1610template <typename Case>
1611void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1612 // --------------------------------------------------------------------
1613 // Preconditions
1614
1615 setupCommonPreconditions<Case>();
1616
1617 // A hotplug connect event is enqueued for a display
1618 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001619
1620 // --------------------------------------------------------------------
1621 // Call Expectations
1622
1623 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001624
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001625 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001626
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001627 // --------------------------------------------------------------------
1628 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001629
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001630 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001631
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001632 // --------------------------------------------------------------------
1633 // Postconditions
1634
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001635 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001636
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001637 // --------------------------------------------------------------------
1638 // Cleanup conditions
1639
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001640 EXPECT_CALL(*mComposer,
1641 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001642 .WillOnce(Return(Error::NONE));
1643 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001644}
1645
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001646template <typename Case>
1647void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1648 // --------------------------------------------------------------------
1649 // Preconditions
1650
1651 setupCommonPreconditions<Case>();
1652
1653 // A hotplug connect event is enqueued for a display
1654 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1655
1656 // --------------------------------------------------------------------
1657 // Invocation
1658
1659 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1660
1661 // --------------------------------------------------------------------
1662 // Postconditions
1663
1664 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001665 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001666}
1667
1668template <typename Case>
1669void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1670 // --------------------------------------------------------------------
1671 // Preconditions
1672
1673 setupCommonPreconditions<Case>();
1674
1675 // A hotplug disconnect event is enqueued for a display
1676 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1677
1678 // The display is already completely set up.
1679 Case::Display::injectHwcDisplay(this);
1680 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1681 existing.inject();
1682
1683 // --------------------------------------------------------------------
1684 // Call Expectations
1685
1686 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001687 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1688 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001689
1690 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1691
1692 // --------------------------------------------------------------------
1693 // Invocation
1694
1695 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1696
1697 // --------------------------------------------------------------------
1698 // Postconditions
1699
1700 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001701 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001702
Dominik Laskowski075d3172018-05-24 15:50:06 -07001703 // SF should not have a display token.
1704 const auto displayId = Case::Display::DISPLAY_ID::get();
1705 ASSERT_TRUE(displayId);
1706 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001707
1708 // The existing token should have been removed
1709 verifyDisplayIsNotConnected(existing.token());
1710}
1711
1712TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1713 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1714}
1715
1716TEST_F(HandleTransactionLockedTest,
1717 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1718 // Inject an external display.
1719 ExternalDisplayVariant::injectHwcDisplay(this);
1720
1721 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1722}
1723
1724TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1725 // Inject a primary display.
1726 PrimaryDisplayVariant::injectHwcDisplay(this);
1727
1728 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1729}
1730
1731TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1732 // Inject both a primary and external display.
1733 PrimaryDisplayVariant::injectHwcDisplay(this);
1734 ExternalDisplayVariant::injectHwcDisplay(this);
1735
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001736 // TODO: This is an unnecessary call.
1737 EXPECT_CALL(*mComposer,
1738 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
1739 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
1740 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
1741 Return(Error::NONE)));
1742
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001743 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1744
1745 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1746}
1747
1748TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1749 // Inject a primary display.
1750 PrimaryDisplayVariant::injectHwcDisplay(this);
1751
1752 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1753
1754 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1755}
1756
1757TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1758 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1759}
1760
1761TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1762 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1763}
1764
1765TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1766 using Case = SimplePrimaryDisplayCase;
1767
1768 // --------------------------------------------------------------------
1769 // Preconditions
1770
1771 setupCommonPreconditions<Case>();
1772
1773 // A hotplug connect event is enqueued for a display
1774 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1775 // A hotplug disconnect event is also enqueued for the same display
1776 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1777
1778 // --------------------------------------------------------------------
1779 // Call Expectations
1780
1781 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1782
1783 setupCommonCallExpectationsForConnectProcessing<Case>();
1784 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1785
1786 EXPECT_CALL(*mComposer,
1787 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1788 .WillOnce(Return(Error::NONE));
1789 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1790
1791 // --------------------------------------------------------------------
1792 // Invocation
1793
1794 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1795
1796 // --------------------------------------------------------------------
1797 // Postconditions
1798
1799 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001800 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001801
Dominik Laskowski075d3172018-05-24 15:50:06 -07001802 // SF should not have a display token.
1803 const auto displayId = Case::Display::DISPLAY_ID::get();
1804 ASSERT_TRUE(displayId);
1805 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001806}
1807
1808TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1809 using Case = SimplePrimaryDisplayCase;
1810
1811 // --------------------------------------------------------------------
1812 // Preconditions
1813
1814 setupCommonPreconditions<Case>();
1815
1816 // The display is already completely set up.
1817 Case::Display::injectHwcDisplay(this);
1818 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1819 existing.inject();
1820
1821 // A hotplug disconnect event is enqueued for a display
1822 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1823 // A hotplug connect event is also enqueued for the same display
1824 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1825
1826 // --------------------------------------------------------------------
1827 // Call Expectations
1828
1829 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1830
1831 setupCommonCallExpectationsForConnectProcessing<Case>();
1832 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1833
1834 // --------------------------------------------------------------------
1835 // Invocation
1836
1837 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1838
1839 // --------------------------------------------------------------------
1840 // Postconditions
1841
1842 // The existing token should have been removed
1843 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001844 const auto displayId = Case::Display::DISPLAY_ID::get();
1845 ASSERT_TRUE(displayId);
1846 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1847 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001848
1849 // A new display should be connected in its place
1850
1851 verifyPhysicalDisplayIsConnected<Case>();
1852
1853 // --------------------------------------------------------------------
1854 // Cleanup conditions
1855
1856 EXPECT_CALL(*mComposer,
1857 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1858 .WillOnce(Return(Error::NONE));
1859 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1860}
1861
1862TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1863 using Case = HwcVirtualDisplayCase;
1864
1865 // --------------------------------------------------------------------
1866 // Preconditions
1867
1868 // The HWC supports at least one virtual display
1869 injectMockComposer(1);
1870
1871 setupCommonPreconditions<Case>();
1872
1873 // A virtual display was added to the current state, and it has a
1874 // surface(producer)
1875 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07001876
Dominik Laskowski075d3172018-05-24 15:50:06 -07001877 DisplayDeviceState state;
1878 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001879
1880 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001881 state.surface = surface;
1882 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001883
1884 // --------------------------------------------------------------------
1885 // Call Expectations
1886
1887 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1888 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1889
1890 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1891 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1892 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1893 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1894 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1895 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1896 Return(NO_ERROR)));
1897 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1898 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1899
1900 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1901
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001902 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001903 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1904
1905 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1906 Case::WideColorSupport::setupComposerCallExpectations(this);
1907 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001908 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001909
1910 // --------------------------------------------------------------------
1911 // Invocation
1912
1913 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1914
1915 // --------------------------------------------------------------------
1916 // Postconditions
1917
1918 // The display device should have been set up in the list of displays.
1919 verifyDisplayIsConnected<Case>(displayToken);
1920
1921 // --------------------------------------------------------------------
1922 // Cleanup conditions
1923
1924 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1925 .WillOnce(Return(Error::NONE));
1926 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08001927
1928 // Cleanup
1929 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
1930 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001931}
1932
1933TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1934 using Case = HwcVirtualDisplayCase;
1935
1936 // --------------------------------------------------------------------
1937 // Preconditions
1938
1939 // The HWC supports at least one virtual display
1940 injectMockComposer(1);
1941
1942 setupCommonPreconditions<Case>();
1943
1944 // A virtual display was added to the current state, but it does not have a
1945 // surface.
1946 sp<BBinder> displayToken = new BBinder();
1947
Dominik Laskowski075d3172018-05-24 15:50:06 -07001948 DisplayDeviceState state;
1949 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001950
Dominik Laskowski075d3172018-05-24 15:50:06 -07001951 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001952
1953 // --------------------------------------------------------------------
1954 // Call Expectations
1955
1956 // --------------------------------------------------------------------
1957 // Invocation
1958
1959 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1960
1961 // --------------------------------------------------------------------
1962 // Postconditions
1963
1964 // There will not be a display device set up.
1965 EXPECT_FALSE(hasDisplayDevice(displayToken));
1966
1967 // The drawing display state will be set from the current display state.
1968 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1969 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001970 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001971}
1972
1973TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1974 using Case = HwcVirtualDisplayCase;
1975
1976 // --------------------------------------------------------------------
1977 // Preconditions
1978
1979 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07001980 const auto displayId = Case::Display::DISPLAY_ID::get();
1981 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001982 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001983 Case::Display::injectHwcDisplay(this);
1984 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1985 existing.inject();
1986 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1987
1988 // --------------------------------------------------------------------
1989 // Call Expectations
1990
1991 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1992
1993 // --------------------------------------------------------------------
1994 // Invocation
1995
1996 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1997
1998 // --------------------------------------------------------------------
1999 // Postconditions
2000
2001 // The existing token should have been removed
2002 verifyDisplayIsNotConnected(existing.token());
2003}
2004
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002005TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2006 using Case = NonHwcVirtualDisplayCase;
2007
2008 constexpr uint32_t oldLayerStack = 0u;
2009 constexpr uint32_t newLayerStack = 123u;
2010
2011 // --------------------------------------------------------------------
2012 // Preconditions
2013
2014 // A display is set up
2015 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2016 display.inject();
2017
2018 // There is a change to the layerStack state
2019 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2020 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2021
2022 // --------------------------------------------------------------------
2023 // Invocation
2024
2025 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2026
2027 // --------------------------------------------------------------------
2028 // Postconditions
2029
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002030 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002031}
2032
2033TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2034 using Case = NonHwcVirtualDisplayCase;
2035
2036 constexpr int oldTransform = 0;
2037 constexpr int newTransform = 2;
2038
2039 // --------------------------------------------------------------------
2040 // Preconditions
2041
2042 // A display is set up
2043 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2044 display.inject();
2045
2046 // There is a change to the orientation state
2047 display.mutableDrawingDisplayState().orientation = oldTransform;
2048 display.mutableCurrentDisplayState().orientation = newTransform;
2049
2050 // --------------------------------------------------------------------
2051 // Invocation
2052
2053 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2054
2055 // --------------------------------------------------------------------
2056 // Postconditions
2057
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002058 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002059}
2060
2061TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2062 using Case = NonHwcVirtualDisplayCase;
2063
2064 const Rect oldViewport(0, 0, 0, 0);
2065 const Rect newViewport(0, 0, 123, 456);
2066
2067 // --------------------------------------------------------------------
2068 // Preconditions
2069
2070 // A display is set up
2071 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2072 display.inject();
2073
2074 // There is a change to the viewport state
2075 display.mutableDrawingDisplayState().viewport = oldViewport;
2076 display.mutableCurrentDisplayState().viewport = newViewport;
2077
2078 // --------------------------------------------------------------------
2079 // Invocation
2080
2081 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2082
2083 // --------------------------------------------------------------------
2084 // Postconditions
2085
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002086 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002087}
2088
2089TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2090 using Case = NonHwcVirtualDisplayCase;
2091
2092 const Rect oldFrame(0, 0, 0, 0);
2093 const Rect newFrame(0, 0, 123, 456);
2094
2095 // --------------------------------------------------------------------
2096 // Preconditions
2097
2098 // A display is set up
2099 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2100 display.inject();
2101
2102 // There is a change to the viewport state
2103 display.mutableDrawingDisplayState().frame = oldFrame;
2104 display.mutableCurrentDisplayState().frame = newFrame;
2105
2106 // --------------------------------------------------------------------
2107 // Invocation
2108
2109 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2110
2111 // --------------------------------------------------------------------
2112 // Postconditions
2113
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002114 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002115}
2116
2117TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2118 using Case = NonHwcVirtualDisplayCase;
2119
2120 constexpr int oldWidth = 0;
2121 constexpr int oldHeight = 10;
2122 constexpr int newWidth = 123;
2123
2124 // --------------------------------------------------------------------
2125 // Preconditions
2126
2127 // A display is set up
2128 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002129 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002130 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002131 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2132 display.setNativeWindow(nativeWindow);
2133 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002134 // Setup injection expections
2135 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2136 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2137 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2138 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002139 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2140 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2141 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002142 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002143 display.inject();
2144
2145 // There is a change to the viewport state
2146 display.mutableDrawingDisplayState().width = oldWidth;
2147 display.mutableDrawingDisplayState().height = oldHeight;
2148 display.mutableCurrentDisplayState().width = newWidth;
2149 display.mutableCurrentDisplayState().height = oldHeight;
2150
2151 // --------------------------------------------------------------------
2152 // Call Expectations
2153
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002154 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002155
2156 // --------------------------------------------------------------------
2157 // Invocation
2158
2159 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2160}
2161
2162TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2163 using Case = NonHwcVirtualDisplayCase;
2164
2165 constexpr int oldWidth = 0;
2166 constexpr int oldHeight = 10;
2167 constexpr int newHeight = 123;
2168
2169 // --------------------------------------------------------------------
2170 // Preconditions
2171
2172 // A display is set up
2173 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002174 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002175 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002176 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2177 display.setNativeWindow(nativeWindow);
2178 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002179 // Setup injection expections
2180 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2181 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2182 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2183 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002184 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2185 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2186 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002187 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002188 display.inject();
2189
2190 // There is a change to the viewport state
2191 display.mutableDrawingDisplayState().width = oldWidth;
2192 display.mutableDrawingDisplayState().height = oldHeight;
2193 display.mutableCurrentDisplayState().width = oldWidth;
2194 display.mutableCurrentDisplayState().height = newHeight;
2195
2196 // --------------------------------------------------------------------
2197 // Call Expectations
2198
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002199 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002200
2201 // --------------------------------------------------------------------
2202 // Invocation
2203
2204 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2205}
2206
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002207/* ------------------------------------------------------------------------
2208 * SurfaceFlinger::setDisplayStateLocked
2209 */
2210
2211TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2212 // --------------------------------------------------------------------
2213 // Preconditions
2214
2215 // We have an unknown display token not associated with a known display
2216 sp<BBinder> displayToken = new BBinder();
2217
2218 // The requested display state references the unknown display.
2219 DisplayState state;
2220 state.what = DisplayState::eLayerStackChanged;
2221 state.token = displayToken;
2222 state.layerStack = 456;
2223
2224 // --------------------------------------------------------------------
2225 // Invocation
2226
2227 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2228
2229 // --------------------------------------------------------------------
2230 // Postconditions
2231
2232 // The returned flags are empty
2233 EXPECT_EQ(0u, flags);
2234
2235 // The display token still doesn't match anything known.
2236 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2237}
2238
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002239TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2240 using Case = SimplePrimaryDisplayCase;
2241
2242 // --------------------------------------------------------------------
2243 // Preconditions
2244
2245 // A display is already set up
2246 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2247 display.inject();
2248
2249 // No changes are made to the display
2250 DisplayState state;
2251 state.what = 0;
2252 state.token = display.token();
2253
2254 // --------------------------------------------------------------------
2255 // Invocation
2256
2257 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2258
2259 // --------------------------------------------------------------------
2260 // Postconditions
2261
2262 // The returned flags are empty
2263 EXPECT_EQ(0u, flags);
2264}
2265
2266TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2267 using Case = SimplePrimaryDisplayCase;
2268
2269 // --------------------------------------------------------------------
2270 // Preconditions
2271
2272 // A display is already set up
2273 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2274 display.inject();
2275
2276 // There is a surface that can be set.
2277 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2278
2279 // The current display state has the surface set
2280 display.mutableCurrentDisplayState().surface = surface;
2281
2282 // The incoming request sets the same surface
2283 DisplayState state;
2284 state.what = DisplayState::eSurfaceChanged;
2285 state.token = display.token();
2286 state.surface = surface;
2287
2288 // --------------------------------------------------------------------
2289 // Invocation
2290
2291 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2292
2293 // --------------------------------------------------------------------
2294 // Postconditions
2295
2296 // The returned flags are empty
2297 EXPECT_EQ(0u, flags);
2298
2299 // The current display state is unchanged.
2300 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2301}
2302
2303TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2304 using Case = SimplePrimaryDisplayCase;
2305
2306 // --------------------------------------------------------------------
2307 // Preconditions
2308
2309 // A display is already set up
2310 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2311 display.inject();
2312
2313 // There is a surface that can be set.
2314 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2315
2316 // The current display state does not have a surface
2317 display.mutableCurrentDisplayState().surface = nullptr;
2318
2319 // The incoming request sets a surface
2320 DisplayState state;
2321 state.what = DisplayState::eSurfaceChanged;
2322 state.token = display.token();
2323 state.surface = surface;
2324
2325 // --------------------------------------------------------------------
2326 // Invocation
2327
2328 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2329
2330 // --------------------------------------------------------------------
2331 // Postconditions
2332
2333 // The returned flags indicate a transaction is needed
2334 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2335
2336 // The current display layer stack state is set to the new value
2337 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2338}
2339
2340TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2341 using Case = SimplePrimaryDisplayCase;
2342
2343 // --------------------------------------------------------------------
2344 // Preconditions
2345
2346 // A display is already set up
2347 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2348 display.inject();
2349
2350 // The display has a layer stack set
2351 display.mutableCurrentDisplayState().layerStack = 456u;
2352
2353 // The incoming request sets the same layer stack
2354 DisplayState state;
2355 state.what = DisplayState::eLayerStackChanged;
2356 state.token = display.token();
2357 state.layerStack = 456u;
2358
2359 // --------------------------------------------------------------------
2360 // Invocation
2361
2362 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2363
2364 // --------------------------------------------------------------------
2365 // Postconditions
2366
2367 // The returned flags are empty
2368 EXPECT_EQ(0u, flags);
2369
2370 // The current display state is unchanged
2371 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2372}
2373
2374TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2375 using Case = SimplePrimaryDisplayCase;
2376
2377 // --------------------------------------------------------------------
2378 // Preconditions
2379
2380 // A display is set up
2381 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2382 display.inject();
2383
2384 // The display has a layer stack set
2385 display.mutableCurrentDisplayState().layerStack = 654u;
2386
2387 // The incoming request sets a different layer stack
2388 DisplayState state;
2389 state.what = DisplayState::eLayerStackChanged;
2390 state.token = display.token();
2391 state.layerStack = 456u;
2392
2393 // --------------------------------------------------------------------
2394 // Invocation
2395
2396 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2397
2398 // --------------------------------------------------------------------
2399 // Postconditions
2400
2401 // The returned flags indicate a transaction is needed
2402 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2403
2404 // The desired display state has been set to the new value.
2405 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2406}
2407
2408TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2409 using Case = SimplePrimaryDisplayCase;
2410 constexpr int initialOrientation = 180;
2411 const Rect initialFrame = {1, 2, 3, 4};
2412 const Rect initialViewport = {5, 6, 7, 8};
2413
2414 // --------------------------------------------------------------------
2415 // Preconditions
2416
2417 // A display is set up
2418 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2419 display.inject();
2420
2421 // The current display state projection state is all set
2422 display.mutableCurrentDisplayState().orientation = initialOrientation;
2423 display.mutableCurrentDisplayState().frame = initialFrame;
2424 display.mutableCurrentDisplayState().viewport = initialViewport;
2425
2426 // The incoming request sets the same projection state
2427 DisplayState state;
2428 state.what = DisplayState::eDisplayProjectionChanged;
2429 state.token = display.token();
2430 state.orientation = initialOrientation;
2431 state.frame = initialFrame;
2432 state.viewport = initialViewport;
2433
2434 // --------------------------------------------------------------------
2435 // Invocation
2436
2437 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2438
2439 // --------------------------------------------------------------------
2440 // Postconditions
2441
2442 // The returned flags are empty
2443 EXPECT_EQ(0u, flags);
2444
2445 // The current display state is unchanged
2446 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2447
2448 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2449 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2450}
2451
2452TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2453 using Case = SimplePrimaryDisplayCase;
2454 constexpr int initialOrientation = 90;
2455 constexpr int desiredOrientation = 180;
2456
2457 // --------------------------------------------------------------------
2458 // Preconditions
2459
2460 // A display is set up
2461 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2462 display.inject();
2463
2464 // The current display state has an orientation set
2465 display.mutableCurrentDisplayState().orientation = initialOrientation;
2466
2467 // The incoming request sets a different orientation
2468 DisplayState state;
2469 state.what = DisplayState::eDisplayProjectionChanged;
2470 state.token = display.token();
2471 state.orientation = desiredOrientation;
2472
2473 // --------------------------------------------------------------------
2474 // Invocation
2475
2476 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2477
2478 // --------------------------------------------------------------------
2479 // Postconditions
2480
2481 // The returned flags indicate a transaction is needed
2482 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2483
2484 // The current display state has the new value.
2485 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2486}
2487
2488TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2489 using Case = SimplePrimaryDisplayCase;
2490 const Rect initialFrame = {0, 0, 0, 0};
2491 const Rect desiredFrame = {5, 6, 7, 8};
2492
2493 // --------------------------------------------------------------------
2494 // Preconditions
2495
2496 // A display is set up
2497 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2498 display.inject();
2499
2500 // The current display state does not have a frame
2501 display.mutableCurrentDisplayState().frame = initialFrame;
2502
2503 // The incoming request sets a frame
2504 DisplayState state;
2505 state.what = DisplayState::eDisplayProjectionChanged;
2506 state.token = display.token();
2507 state.frame = desiredFrame;
2508
2509 // --------------------------------------------------------------------
2510 // Invocation
2511
2512 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2513
2514 // --------------------------------------------------------------------
2515 // Postconditions
2516
2517 // The returned flags indicate a transaction is needed
2518 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2519
2520 // The current display state has the new value.
2521 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2522}
2523
2524TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2525 using Case = SimplePrimaryDisplayCase;
2526 const Rect initialViewport = {0, 0, 0, 0};
2527 const Rect desiredViewport = {5, 6, 7, 8};
2528
2529 // --------------------------------------------------------------------
2530 // Preconditions
2531
2532 // A display is set up
2533 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2534 display.inject();
2535
2536 // The current display state does not have a viewport
2537 display.mutableCurrentDisplayState().viewport = initialViewport;
2538
2539 // The incoming request sets a viewport
2540 DisplayState state;
2541 state.what = DisplayState::eDisplayProjectionChanged;
2542 state.token = display.token();
2543 state.viewport = desiredViewport;
2544
2545 // --------------------------------------------------------------------
2546 // Invocation
2547
2548 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2549
2550 // --------------------------------------------------------------------
2551 // Postconditions
2552
2553 // The returned flags indicate a transaction is needed
2554 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2555
2556 // The current display state has the new value.
2557 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2558}
2559
2560TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2561 using Case = SimplePrimaryDisplayCase;
2562 constexpr uint32_t initialWidth = 1024;
2563 constexpr uint32_t initialHeight = 768;
2564
2565 // --------------------------------------------------------------------
2566 // Preconditions
2567
2568 // A display is set up
2569 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2570 display.inject();
2571
2572 // The current display state has a size set
2573 display.mutableCurrentDisplayState().width = initialWidth;
2574 display.mutableCurrentDisplayState().height = initialHeight;
2575
2576 // The incoming request sets the same display size
2577 DisplayState state;
2578 state.what = DisplayState::eDisplaySizeChanged;
2579 state.token = display.token();
2580 state.width = initialWidth;
2581 state.height = initialHeight;
2582
2583 // --------------------------------------------------------------------
2584 // Invocation
2585
2586 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2587
2588 // --------------------------------------------------------------------
2589 // Postconditions
2590
2591 // The returned flags are empty
2592 EXPECT_EQ(0u, flags);
2593
2594 // The current display state is unchanged
2595 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2596 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2597}
2598
2599TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2600 using Case = SimplePrimaryDisplayCase;
2601 constexpr uint32_t initialWidth = 0;
2602 constexpr uint32_t desiredWidth = 1024;
2603
2604 // --------------------------------------------------------------------
2605 // Preconditions
2606
2607 // A display is set up
2608 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2609 display.inject();
2610
2611 // The display does not yet have a width
2612 display.mutableCurrentDisplayState().width = initialWidth;
2613
2614 // The incoming request sets a display width
2615 DisplayState state;
2616 state.what = DisplayState::eDisplaySizeChanged;
2617 state.token = display.token();
2618 state.width = desiredWidth;
2619
2620 // --------------------------------------------------------------------
2621 // Invocation
2622
2623 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2624
2625 // --------------------------------------------------------------------
2626 // Postconditions
2627
2628 // The returned flags indicate a transaction is needed
2629 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2630
2631 // The current display state has the new value.
2632 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2633}
2634
2635TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2636 using Case = SimplePrimaryDisplayCase;
2637 constexpr uint32_t initialHeight = 0;
2638 constexpr uint32_t desiredHeight = 768;
2639
2640 // --------------------------------------------------------------------
2641 // Preconditions
2642
2643 // A display is set up
2644 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2645 display.inject();
2646
2647 // The display does not yet have a height
2648 display.mutableCurrentDisplayState().height = initialHeight;
2649
2650 // The incoming request sets a display height
2651 DisplayState state;
2652 state.what = DisplayState::eDisplaySizeChanged;
2653 state.token = display.token();
2654 state.height = desiredHeight;
2655
2656 // --------------------------------------------------------------------
2657 // Invocation
2658
2659 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2660
2661 // --------------------------------------------------------------------
2662 // Postconditions
2663
2664 // The returned flags indicate a transaction is needed
2665 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2666
2667 // The current display state has the new value.
2668 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2669}
2670
Lloyd Pique86016da2018-03-01 16:09:38 -08002671/* ------------------------------------------------------------------------
2672 * SurfaceFlinger::onInitializeDisplays
2673 */
2674
2675TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2676 using Case = SimplePrimaryDisplayCase;
2677
2678 // --------------------------------------------------------------------
2679 // Preconditions
2680
2681 // A primary display is set up
2682 Case::Display::injectHwcDisplay(this);
2683 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2684 primaryDisplay.inject();
2685
2686 // --------------------------------------------------------------------
2687 // Call Expectations
2688
2689 // We expect the surface interceptor to possibly be used, but we treat it as
2690 // disabled since it is called as a side effect rather than directly by this
2691 // function.
2692 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2693
2694 // We expect a call to get the active display config.
2695 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2696
2697 // We expect invalidate() to be invoked once to trigger display transaction
2698 // processing.
2699 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2700
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002701 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2702
Lloyd Pique86016da2018-03-01 16:09:38 -08002703 // --------------------------------------------------------------------
2704 // Invocation
2705
2706 mFlinger.onInitializeDisplays();
2707
2708 // --------------------------------------------------------------------
2709 // Postconditions
2710
2711 // The primary display should have a current state
2712 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2713 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2714 // The layer stack state should be set to zero
2715 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2716 // The orientation state should be set to zero
2717 EXPECT_EQ(0, primaryDisplayState.orientation);
2718
2719 // The frame state should be set to INVALID
2720 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2721
2722 // The viewport state should be set to INVALID
2723 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2724
2725 // The width and height should both be zero
2726 EXPECT_EQ(0u, primaryDisplayState.width);
2727 EXPECT_EQ(0u, primaryDisplayState.height);
2728
2729 // The display should be set to HWC_POWER_MODE_NORMAL
2730 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2731 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2732 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2733
2734 // The display refresh period should be set in the frame tracker.
2735 FrameStats stats;
2736 mFlinger.getAnimFrameTracker().getStats(&stats);
2737 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2738
2739 // The display transaction needed flag should be set.
2740 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2741
2742 // The compositor timing should be set to default values
2743 const auto& compositorTiming = mFlinger.getCompositorTiming();
2744 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2745 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2746 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2747}
2748
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002749/* ------------------------------------------------------------------------
2750 * SurfaceFlinger::setPowerModeInternal
2751 */
2752
2753// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07002754template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002755struct DozeIsSupportedVariant {
2756 static constexpr bool DOZE_SUPPORTED = true;
2757 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2758 IComposerClient::PowerMode::DOZE;
2759 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2760 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07002761
2762 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2763 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2764 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
2765 {Hwc2::DisplayCapability::DOZE})),
2766 Return(Error::NONE)));
2767 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002768};
2769
Peiyong Lined531a32018-10-26 18:27:56 -07002770template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002771// Used when we simulate a display that does not support doze.
2772struct DozeNotSupportedVariant {
2773 static constexpr bool DOZE_SUPPORTED = false;
2774 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2775 IComposerClient::PowerMode::ON;
2776 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2777 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07002778
2779 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2780 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2781 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
2782 Return(Error::NONE)));
2783 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002784};
2785
2786struct EventThreadBaseSupportedVariant {
2787 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
2788 // The event control thread should not be notified.
2789 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
2790
2791 // The event thread should not be notified.
2792 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
2793 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
2794 }
2795};
2796
2797struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
2798 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2799 // These calls are only expected for the primary display.
2800
2801 // Instead expect no calls.
2802 setupEventAndEventControlThreadNoCallExpectations(test);
2803 }
2804
2805 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2806 // These calls are only expected for the primary display.
2807
2808 // Instead expect no calls.
2809 setupEventAndEventControlThreadNoCallExpectations(test);
2810 }
2811};
2812
2813struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
2814 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2815 // The event control thread should be notified to enable vsyncs
2816 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
2817
2818 // The event thread should be notified that the screen was acquired.
2819 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
2820 }
2821
2822 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2823 // There should be a call to setVsyncEnabled(false)
2824 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
2825
2826 // The event thread should not be notified that the screen was released.
2827 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
2828 }
2829};
2830
Lloyd Pique41be5d22018-06-21 13:11:48 -07002831struct DispSyncIsSupportedVariant {
2832 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique41be5d22018-06-21 13:11:48 -07002833 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
2834 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
2835 }
2836
2837 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
2838 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
2839 }
2840};
2841
2842struct DispSyncNotSupportedVariant {
2843 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2844
2845 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2846};
2847
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002848// --------------------------------------------------------------------
2849// Note:
2850//
2851// There are a large number of transitions we could test, however we only test a
2852// selected subset which provides complete test coverage of the implementation.
2853// --------------------------------------------------------------------
2854
2855template <int initialPowerMode, int targetPowerMode>
2856struct TransitionVariantCommon {
2857 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
2858 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
2859
2860 static void verifyPostconditions(DisplayTransactionTest*) {}
2861};
2862
2863struct TransitionOffToOnVariant
2864 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
2865 template <typename Case>
2866 static void setupCallExpectations(DisplayTransactionTest* test) {
2867 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2868 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002869 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002870 Case::setupRepaintEverythingCallExpectations(test);
2871 }
2872
2873 static void verifyPostconditions(DisplayTransactionTest* test) {
2874 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2875 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2876 }
2877};
2878
2879struct TransitionOffToDozeSuspendVariant
2880 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
2881 template <typename Case>
2882 static void setupCallExpectations(DisplayTransactionTest* test) {
2883 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2884 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2885 Case::setupRepaintEverythingCallExpectations(test);
2886 }
2887
2888 static void verifyPostconditions(DisplayTransactionTest* test) {
2889 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2890 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2891 }
2892};
2893
2894struct TransitionOnToOffVariant
2895 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
2896 template <typename Case>
2897 static void setupCallExpectations(DisplayTransactionTest* test) {
2898 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002899 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002900 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2901 }
2902
2903 static void verifyPostconditions(DisplayTransactionTest* test) {
2904 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2905 }
2906};
2907
2908struct TransitionDozeSuspendToOffVariant
2909 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
2910 template <typename Case>
2911 static void setupCallExpectations(DisplayTransactionTest* test) {
2912 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2913 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2914 }
2915
2916 static void verifyPostconditions(DisplayTransactionTest* test) {
2917 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2918 }
2919};
2920
2921struct TransitionOnToDozeVariant
2922 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
2923 template <typename Case>
2924 static void setupCallExpectations(DisplayTransactionTest* test) {
2925 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2926 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2927 }
2928};
2929
2930struct TransitionDozeSuspendToDozeVariant
2931 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
2932 template <typename Case>
2933 static void setupCallExpectations(DisplayTransactionTest* test) {
2934 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002935 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002936 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2937 }
2938};
2939
2940struct TransitionDozeToOnVariant
2941 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
2942 template <typename Case>
2943 static void setupCallExpectations(DisplayTransactionTest* test) {
2944 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2945 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2946 }
2947};
2948
2949struct TransitionDozeSuspendToOnVariant
2950 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
2951 template <typename Case>
2952 static void setupCallExpectations(DisplayTransactionTest* test) {
2953 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002954 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002955 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2956 }
2957};
2958
2959struct TransitionOnToDozeSuspendVariant
2960 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
2961 template <typename Case>
2962 static void setupCallExpectations(DisplayTransactionTest* test) {
2963 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002964 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002965 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2966 }
2967};
2968
2969struct TransitionOnToUnknownVariant
2970 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
2971 template <typename Case>
2972 static void setupCallExpectations(DisplayTransactionTest* test) {
2973 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2974 Case::setupNoComposerPowerModeCallExpectations(test);
2975 }
2976};
2977
2978// --------------------------------------------------------------------
2979// Note:
2980//
2981// Rather than testing the cartesian product of of
2982// DozeIsSupported/DozeNotSupported with all other options, we use one for one
2983// display type, and the other for another display type.
2984// --------------------------------------------------------------------
2985
2986template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07002987 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002988struct DisplayPowerCase {
2989 using Display = DisplayVariant;
2990 using Doze = DozeVariant;
2991 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07002992 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002993 using Transition = TransitionVariant;
2994
2995 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002996 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002997 auto display = Display::makeFakeExistingDisplayInjector(test);
2998 display.inject();
2999 display.mutableDisplayDevice()->setPowerMode(mode);
3000 return display;
3001 }
3002
3003 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003004 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003005 }
3006
3007 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3008 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3009 }
3010
3011 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3012 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3013 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3014 }
3015
3016 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3017 IComposerClient::PowerMode mode) {
3018 // Any calls to get the active config will return a default value.
3019 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3020 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3021 Return(Error::NONE)));
3022
3023 // Any calls to get whether the display supports dozing will return the value set by the
3024 // policy variant.
3025 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3026 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3027
3028 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3029 }
3030
3031 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3032 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3033 }
3034};
3035
3036// A sample configuration for the primary display.
3037// In addition to having event thread support, we emulate doze support.
3038template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003039using PrimaryDisplayPowerCase =
3040 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3041 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3042 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003043
3044// A sample configuration for the external display.
3045// In addition to not having event thread support, we emulate not having doze
3046// support.
3047template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003048using ExternalDisplayPowerCase =
3049 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3050 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3051 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003052
3053class SetPowerModeInternalTest : public DisplayTransactionTest {
3054public:
3055 template <typename Case>
3056 void transitionDisplayCommon();
3057};
3058
3059template <int PowerMode>
3060struct PowerModeInitialVSyncEnabled : public std::false_type {};
3061
3062template <>
3063struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3064
3065template <>
3066struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3067
3068template <typename Case>
3069void SetPowerModeInternalTest::transitionDisplayCommon() {
3070 // --------------------------------------------------------------------
3071 // Preconditions
3072
Peiyong Lined531a32018-10-26 18:27:56 -07003073 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003074 auto display =
3075 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3076 Case::setInitialPrimaryHWVsyncEnabled(this,
3077 PowerModeInitialVSyncEnabled<
3078 Case::Transition::INITIAL_POWER_MODE>::value);
3079
3080 // --------------------------------------------------------------------
3081 // Call Expectations
3082
3083 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3084 Case::Transition::template setupCallExpectations<Case>(this);
3085
3086 // --------------------------------------------------------------------
3087 // Invocation
3088
3089 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3090 Case::Transition::TARGET_POWER_MODE);
3091
3092 // --------------------------------------------------------------------
3093 // Postconditions
3094
3095 Case::Transition::verifyPostconditions(this);
3096}
3097
3098TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3099 using Case = SimplePrimaryDisplayCase;
3100
3101 // --------------------------------------------------------------------
3102 // Preconditions
3103
3104 // A primary display device is set up
3105 Case::Display::injectHwcDisplay(this);
3106 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3107 display.inject();
3108
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003109 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003110 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3111
3112 // --------------------------------------------------------------------
3113 // Invocation
3114
3115 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3116
3117 // --------------------------------------------------------------------
3118 // Postconditions
3119
3120 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3121}
3122
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003123TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003124 using Case = HwcVirtualDisplayCase;
3125
3126 // --------------------------------------------------------------------
3127 // Preconditions
3128
Dominik Laskowski075d3172018-05-24 15:50:06 -07003129 // Insert display data so that the HWC thinks it created the virtual display.
3130 const auto displayId = Case::Display::DISPLAY_ID::get();
3131 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003132 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003133
3134 // A virtual display device is set up
3135 Case::Display::injectHwcDisplay(this);
3136 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3137 display.inject();
3138
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003139 // The display is set to HWC_POWER_MODE_NORMAL
3140 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003141
3142 // --------------------------------------------------------------------
3143 // Invocation
3144
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003145 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003146
3147 // --------------------------------------------------------------------
3148 // Postconditions
3149
3150 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3151}
3152
3153TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3154 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3155}
3156
3157TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3158 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3159}
3160
3161TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3162 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3163}
3164
3165TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3166 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3167}
3168
3169TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3170 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3171}
3172
3173TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3174 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3175}
3176
3177TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3178 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3179}
3180
3181TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3182 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3183}
3184
3185TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3186 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3187}
3188
3189TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3190 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3191}
3192
3193TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3194 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3195}
3196
3197TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3198 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3199}
3200
3201TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3202 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3203}
3204
3205TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3206 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3207}
3208
3209TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3210 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3211}
3212
3213TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3214 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3215}
3216
3217TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3218 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3219}
3220
3221TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3222 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3223}
3224
3225TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3226 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3227}
3228
3229TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3230 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3231}
3232
Lloyd Piquef58625d2017-12-19 13:22:33 -08003233} // namespace
3234} // namespace android