blob: f40996eecf9524eaf97b08d41f6be93857a19cb8 [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"
Steven Thomase9eb1832019-08-28 16:08:35 -070032#include "Scheduler/RefreshRateConfigs.h"
Ana Krulecafb45842019-02-13 13:33:03 -080033#include "TestableScheduler.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080034#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080035#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070036#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080037#include "mock/MockEventControlThread.h"
38#include "mock/MockEventThread.h"
39#include "mock/MockMessageQueue.h"
40#include "mock/MockNativeWindowSurface.h"
41#include "mock/MockSurfaceInterceptor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080042#include "mock/gui/MockGraphicBufferConsumer.h"
43#include "mock/gui/MockGraphicBufferProducer.h"
44#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080045
46namespace android {
47namespace {
48
Lloyd Piquee39cad22017-12-20 17:01:29 -080049using testing::_;
Lloyd Piquee39cad22017-12-20 17:01:29 -080050using testing::DoAll;
51using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080052using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080053using testing::Return;
54using testing::SetArgPointee;
55
Lloyd Piqued883d5a2018-04-27 19:32:30 -070056using android::Hwc2::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080057using android::Hwc2::Error;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070058using android::Hwc2::Hdr;
Lloyd Piquee39cad22017-12-20 17:01:29 -080059using android::Hwc2::IComposer;
60using android::Hwc2::IComposerClient;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070061using android::Hwc2::PerFrameMetadataKey;
62using android::Hwc2::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080063
Lloyd Piquec11e0d32018-01-22 18:44:59 -080064using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
65using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080066using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080067using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080068
Lloyd Piquec11e0d32018-01-22 18:44:59 -080069constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080070constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080071constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080072
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080073constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value
74
Lloyd Piquec11e0d32018-01-22 18:44:59 -080075/* ------------------------------------------------------------------------
76 * Boolean avoidance
77 *
78 * To make calls and template instantiations more readable, we define some
79 * local enums along with an implicit bool conversion.
80 */
81
82#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
83
Lloyd Piquec11e0d32018-01-22 18:44:59 -080084BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -070085BOOL_SUBSTITUTE(Critical);
86BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080087BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -070088BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080089
90/* ------------------------------------------------------------------------
91 *
92 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080093
Lloyd Piquef58625d2017-12-19 13:22:33 -080094class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -080095public:
Lloyd Piquef58625d2017-12-19 13:22:33 -080096 DisplayTransactionTest();
97 ~DisplayTransactionTest() override;
98
Ana Krulecafb45842019-02-13 13:33:03 -080099 void setupScheduler();
100
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800101 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800102 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800103
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800104 void injectMockComposer(int virtualDisplayCount);
105 void injectFakeBufferQueueFactory();
106 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800107
108 // --------------------------------------------------------------------
109 // Postcondition helpers
110
Dominik Laskowski075d3172018-05-24 15:50:06 -0700111 bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800112 bool hasTransactionFlagSet(int flag);
113 bool hasDisplayDevice(sp<IBinder> displayToken);
114 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
115 bool hasCurrentDisplayState(sp<IBinder> displayToken);
116 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
117 bool hasDrawingDisplayState(sp<IBinder> displayToken);
118 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
119
120 // --------------------------------------------------------------------
121 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800122
Ana Krulecafb45842019-02-13 13:33:03 -0800123 TestableScheduler* mScheduler;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800124 TestableSurfaceFlinger mFlinger;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800125 mock::EventThread* mEventThread = new mock::EventThread();
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800126 mock::EventThread* mSFEventThread = new mock::EventThread();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800127 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
Alec Mouriba013fa2018-10-16 12:43:11 -0700128 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800129 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800130
131 // These mocks are created by the test, but are destroyed by SurfaceFlinger
132 // by virtue of being stored into a std::unique_ptr. However we still need
133 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700134 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800135 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800136 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
137 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Lloyd Pique41be5d22018-06-21 13:11:48 -0700138 mock::DispSync* mPrimaryDispSync = new mock::DispSync();
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800139
140 // These mocks are created only when expected to be created via a factory.
141 sp<mock::GraphicBufferConsumer> mConsumer;
142 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700143 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800144};
145
146DisplayTransactionTest::DisplayTransactionTest() {
147 const ::testing::TestInfo* const test_info =
148 ::testing::UnitTest::GetInstance()->current_test_info();
149 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800150
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800151 // Default to no wide color display support configured
152 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700153 mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800154 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
155
156 // Default to using HWC virtual displays
157 mFlinger.mutableUseHwcVirtualDisplays() = true;
158
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800159 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
160 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
161 });
162
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800163 mFlinger.setCreateNativeWindowSurface([](auto) {
164 ADD_FAILURE() << "Unexpected request to create a native window surface.";
165 return nullptr;
166 });
167
Ana Krulecafb45842019-02-13 13:33:03 -0800168 setupScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800169 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700170 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800171 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800172
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800173 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800174}
175
176DisplayTransactionTest::~DisplayTransactionTest() {
177 const ::testing::TestInfo* const test_info =
178 ::testing::UnitTest::GetInstance()->current_test_info();
179 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
180}
181
Ana Krulecafb45842019-02-13 13:33:03 -0800182void DisplayTransactionTest::setupScheduler() {
Steven Thomase9eb1832019-08-28 16:08:35 -0700183 std::vector<scheduler::RefreshRateConfigs::InputConfig> configs{{/*hwcId=*/0, 16666667}};
184 mFlinger.mutableRefreshRateConfigs() =
185 std::make_unique<scheduler::RefreshRateConfigs>(/*refreshRateSwitching=*/false, configs,
186 /*currentConfig=*/0);
187 mFlinger.mutableRefreshRateStats() =
188 std::make_unique<scheduler::RefreshRateStats>(*mFlinger.mutableRefreshRateConfigs(),
189 *mFlinger.mutableTimeStats(),
190 /*currentConfig=*/0,
191 /*powerMode=*/HWC_POWER_MODE_OFF);
192 mScheduler = new TestableScheduler(*mFlinger.mutableRefreshRateConfigs());
Ana Krulecafb45842019-02-13 13:33:03 -0800193 mScheduler->mutableEventControlThread().reset(mEventControlThread);
194 mScheduler->mutablePrimaryDispSync().reset(mPrimaryDispSync);
195 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
196 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
197
198 sp<Scheduler::ConnectionHandle> sfConnectionHandle =
199 mScheduler->addConnection(std::unique_ptr<EventThread>(mSFEventThread));
200 mFlinger.mutableSfConnectionHandle() = std::move(sfConnectionHandle);
201 sp<Scheduler::ConnectionHandle> appConnectionHandle =
202 mScheduler->addConnection(std::unique_ptr<EventThread>(mEventThread));
203 mFlinger.mutableAppConnectionHandle() = std::move(appConnectionHandle);
204 mFlinger.mutableScheduler().reset(mScheduler);
205}
206
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800207void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
208 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800209 EXPECT_CALL(*mComposer, getCapabilities())
210 .WillOnce(Return(std::vector<IComposer::Capability>()));
211 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
212 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800213
Lloyd Piquee39cad22017-12-20 17:01:29 -0800214 Mock::VerifyAndClear(mComposer);
215}
216
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800217void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800218 // This setup is only expected once per test.
219 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
220
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800221 mConsumer = new mock::GraphicBufferConsumer();
222 mProducer = new mock::GraphicBufferProducer();
223
224 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
225 *outProducer = mProducer;
226 *outConsumer = mConsumer;
227 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800228}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800229
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800230void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800231 // This setup is only expected once per test.
232 ASSERT_TRUE(mNativeWindowSurface == nullptr);
233
Lloyd Pique22098362018-09-13 11:46:49 -0700234 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800235
Lloyd Pique22098362018-09-13 11:46:49 -0700236 mFlinger.setCreateNativeWindowSurface([this](auto) {
237 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
238 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800239}
240
Dominik Laskowski075d3172018-05-24 15:50:06 -0700241bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) {
242 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800243}
244
245bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
246 return mFlinger.mutableTransactionFlags() & flag;
247}
248
249bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700250 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800251}
252
253sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700254 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800255}
256
257bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
258 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
259}
260
261const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
262 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
263}
264
265bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
266 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
267}
268
269const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
270 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
271}
272
273/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800274 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800275 */
276
Dominik Laskowski075d3172018-05-24 15:50:06 -0700277template <typename PhysicalDisplay>
278struct PhysicalDisplayId {};
279
Dominik Laskowski34157762018-10-31 13:07:19 -0700280template <DisplayId::Type displayId>
281using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700282
283struct NoDisplayId {};
284
285template <typename>
286struct IsPhysicalDisplayId : std::bool_constant<false> {};
287
288template <typename PhysicalDisplay>
289struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
290
291template <typename>
292struct DisplayIdGetter;
293
294template <typename PhysicalDisplay>
295struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
296 static std::optional<DisplayId> get() {
297 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
298 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
299 ? HWC_DISPLAY_PRIMARY
300 : HWC_DISPLAY_EXTERNAL);
301 }
302
303 const auto info =
304 parseDisplayIdentificationData(PhysicalDisplay::PORT,
305 PhysicalDisplay::GET_IDENTIFICATION_DATA());
306 return info ? std::make_optional(info->id) : std::nullopt;
307 }
308};
309
Dominik Laskowski34157762018-10-31 13:07:19 -0700310template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700311struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700312 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700313};
314
315template <>
316struct DisplayIdGetter<NoDisplayId> {
317 static std::optional<DisplayId> get() { return {}; }
318};
319
320// DisplayIdType can be:
321// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
322// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
323// 3) NoDisplayId for virtual display without HWC backing.
324template <typename DisplayIdType, int width, int height, Critical critical, Async async,
325 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800326struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700327 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
328
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800329 // The display width and height
330 static constexpr int WIDTH = width;
331 static constexpr int HEIGHT = height;
332
333 static constexpr int GRALLOC_USAGE = grallocUsage;
334
Dominik Laskowski075d3172018-05-24 15:50:06 -0700335 // Whether the display is virtual or physical
336 static constexpr Virtual VIRTUAL =
337 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800338
339 // When creating native window surfaces for the framebuffer, whether those should be critical
340 static constexpr Critical CRITICAL = critical;
341
342 // When creating native window surfaces for the framebuffer, whether those should be async
343 static constexpr Async ASYNC = async;
344
345 // Whether the display should be treated as secure
346 static constexpr Secure SECURE = secure;
347
Dominik Laskowski075d3172018-05-24 15:50:06 -0700348 // Whether the display is primary
349 static constexpr Primary PRIMARY = primary;
350
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800351 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700352 auto injector =
353 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(),
354 static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY));
355
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800356 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700357 injector.setNativeWindow(test->mNativeWindow);
358
359 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800360 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700361 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
362 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
363 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
364 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800365 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
366 .WillRepeatedly(Return(0));
367 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
368 .WillRepeatedly(Return(0));
369 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
370 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700371 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
372 .WillRepeatedly(Return(0));
373
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800374 return injector;
375 }
376
377 // Called by tests to set up any native window creation call expectations.
378 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
379 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
380 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800381
Alec Mouriba013fa2018-10-16 12:43:11 -0700382 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
383 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
384 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
385 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800386 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
387 .WillRepeatedly(Return(0));
388 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
389 .WillRepeatedly(Return(0));
390 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
391 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700392 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
393 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800394 }
395
396 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
397 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
398 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
399 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
400 .WillRepeatedly(Return(NO_ERROR));
401 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
402 .WillRepeatedly(Return(NO_ERROR));
403 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
404 .WillRepeatedly(Return(NO_ERROR));
405 }
406
407 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
408 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
409 }
410};
411
Dominik Laskowski075d3172018-05-24 15:50:06 -0700412template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
413 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800414struct HwcDisplayVariant {
415 // The display id supplied by the HWC
416 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
417
418 // The HWC display type
419 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
420
421 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700422 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700423 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800424
425 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
426 HWC2::Connection connection) {
427 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
428 HotplugEvent{HWC_DISPLAY_ID, connection});
429 }
430
431 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800432 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700433 const auto displayId = DisplayVariant::DISPLAY_ID::get();
434 ASSERT_TRUE(displayId);
435 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
436 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800437 .setHwcDisplayId(HWC_DISPLAY_ID)
438 .setWidth(DisplayVariant::WIDTH)
439 .setHeight(DisplayVariant::HEIGHT)
440 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700441 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800442 .inject(&test->mFlinger, test->mComposer);
443 }
444
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800445 // Called by tests to inject a HWC display setup
446 static void injectHwcDisplay(DisplayTransactionTest* test) {
447 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
448 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
449 Return(Error::NONE)));
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700450 EXPECT_CALL(*test->mComposer,
451 setPowerMode(HWC_DISPLAY_ID,
452 static_cast<Hwc2::IComposerClient::PowerMode>(INIT_POWER_MODE)))
453 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800454 injectHwcDisplayWithNoDefaultCapabilities(test);
455 }
456
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800457 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
458 EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _))
459 .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>(
460 HWC_DISPLAY_TYPE)),
461 Return(Error::NONE)));
462 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
463 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
464 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
465 Return(Error::NONE)));
466 EXPECT_CALL(*test->mComposer,
467 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
468 IComposerClient::Attribute::WIDTH, _))
469 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
470 EXPECT_CALL(*test->mComposer,
471 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
472 IComposerClient::Attribute::HEIGHT, _))
473 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
474 EXPECT_CALL(*test->mComposer,
475 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
476 IComposerClient::Attribute::VSYNC_PERIOD, _))
477 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
478 EXPECT_CALL(*test->mComposer,
479 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
480 IComposerClient::Attribute::DPI_X, _))
481 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
482 EXPECT_CALL(*test->mComposer,
483 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
484 IComposerClient::Attribute::DPI_Y, _))
485 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700486
487 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
488 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
489 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
490 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
491 Return(Error::NONE)));
492 } else {
493 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
494 .WillOnce(Return(Error::UNSUPPORTED));
495 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800496 }
497
498 // Called by tests to set up HWC call expectations
499 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
500 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700501 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800502 }
503};
504
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800505// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
506constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
507 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
508
Dominik Laskowski075d3172018-05-24 15:50:06 -0700509template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800510 Critical critical>
511struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700512 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
513 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
514 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
515 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
516 critical, Async::FALSE, Secure::TRUE,
517 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
518 PhysicalDisplay> {};
519
520template <bool hasIdentificationData>
521struct PrimaryDisplay {
522 static constexpr Primary PRIMARY = Primary::TRUE;
523 static constexpr uint8_t PORT = 255;
524 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
525 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
526};
527
528template <bool hasIdentificationData>
529struct ExternalDisplay {
530 static constexpr Primary PRIMARY = Primary::FALSE;
531 static constexpr uint8_t PORT = 254;
532 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
533 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
534};
535
536struct TertiaryDisplay {
537 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800538 static constexpr uint8_t PORT = 253;
539 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700540};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800541
542// A primary display is a physical display that is critical
543using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700544 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800545
546// An external display is physical display that is not critical.
547using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700548 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800549
550using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700551 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800552
553// A virtual display not supported by the HWC.
554constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
555
556template <int width, int height, Secure secure>
557struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700558 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
559 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
560 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
561 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
562
563 static void injectHwcDisplay(DisplayTransactionTest*) {}
564
565 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
566 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
567 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800568
569 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
570 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
571 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
572 }
573};
574
575// A virtual display supported by the HWC.
576constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
577
578template <int width, int height, Secure secure>
579struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700580 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
581 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
582 HwcDisplayVariant<
583 1010, HWC2::DisplayType::Virtual,
584 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
585 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
586 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
587 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800588 using Self = HwcVirtualDisplayVariant<width, height, secure>;
589
590 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
591 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
592 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
593 }
594
595 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
596 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
597 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
598 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
599 }
600};
601
602// For this variant, SurfaceFlinger should not configure itself with wide
603// display support, so the display should not be configured for wide-color
604// support.
605struct WideColorSupportNotConfiguredVariant {
606 static constexpr bool WIDE_COLOR_SUPPORTED = false;
607
608 static void injectConfigChange(DisplayTransactionTest* test) {
609 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700610 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800611 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
612 }
613
614 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
615 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
616 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
617 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
618 }
619};
620
621// For this variant, SurfaceFlinger should configure itself with wide display
622// support, and the display should respond with an non-empty list of supported
623// color modes. Wide-color support should be configured.
624template <typename Display>
625struct WideColorP3ColorimetricSupportedVariant {
626 static constexpr bool WIDE_COLOR_SUPPORTED = true;
627
628 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700629 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800630 test->mFlinger.mutableHasWideColorDisplay() = true;
631 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
632 }
633
634 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800635 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
636
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800637 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
638 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
639 Return(Error::NONE)));
640 EXPECT_CALL(*test->mComposer,
641 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
642 .WillOnce(DoAll(SetArgPointee<2>(
643 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
644 Return(Error::NONE)));
645 EXPECT_CALL(*test->mComposer,
646 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
647 RenderIntent::COLORIMETRIC))
648 .WillOnce(Return(Error::NONE));
649 }
650};
651
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800652// For this variant, SurfaceFlinger should configure itself with wide display
653// support, but the display should respond with an empty list of supported color
654// modes. Wide-color support for the display should not be configured.
655template <typename Display>
656struct WideColorNotSupportedVariant {
657 static constexpr bool WIDE_COLOR_SUPPORTED = false;
658
659 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700660 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800661 test->mFlinger.mutableHasWideColorDisplay() = true;
662 }
663
664 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
665 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
666 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700667 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800668 }
669};
670
671// For this variant, the display is not a HWC display, so no HDR support should
672// be configured.
673struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800674 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800675 static constexpr bool HDR10_SUPPORTED = false;
676 static constexpr bool HDR_HLG_SUPPORTED = false;
677 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
678 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
679 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
680 }
681};
682
Valerie Haue9e843a2018-12-18 13:39:23 -0800683template <typename Display>
684struct Hdr10PlusSupportedVariant {
685 static constexpr bool HDR10_PLUS_SUPPORTED = true;
686 static constexpr bool HDR10_SUPPORTED = true;
687 static constexpr bool HDR_HLG_SUPPORTED = false;
688 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
689 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
690 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
691 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
692 Hdr::HDR10_PLUS,
693 Hdr::HDR10,
694 })),
695 Return(Error::NONE)));
696 }
697};
698
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800699// For this variant, the composer should respond with a non-empty list of HDR
700// modes containing HDR10, so HDR10 support should be configured.
701template <typename Display>
702struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800703 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800704 static constexpr bool HDR10_SUPPORTED = true;
705 static constexpr bool HDR_HLG_SUPPORTED = false;
706 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
707 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
708 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
709 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
710 Return(Error::NONE)));
711 }
712};
713
714// For this variant, the composer should respond with a non-empty list of HDR
715// modes containing HLG, so HLG support should be configured.
716template <typename Display>
717struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800718 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800719 static constexpr bool HDR10_SUPPORTED = false;
720 static constexpr bool HDR_HLG_SUPPORTED = true;
721 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
722 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
723 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
724 .WillOnce(
725 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
726 }
727};
728
729// For this variant, the composer should respond with a non-empty list of HDR
730// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
731template <typename Display>
732struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800733 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800734 static constexpr bool HDR10_SUPPORTED = false;
735 static constexpr bool HDR_HLG_SUPPORTED = false;
736 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
737 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
738 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
739 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
740 Return(Error::NONE)));
741 }
742};
743
744// For this variant, the composer should respond with am empty list of HDR
745// modes, so no HDR support should be configured.
746template <typename Display>
747struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800748 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800749 static constexpr bool HDR10_SUPPORTED = false;
750 static constexpr bool HDR_HLG_SUPPORTED = false;
751 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
752 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
753 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
754 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
755 }
756};
757
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700758struct NonHwcPerFrameMetadataSupportVariant {
759 static constexpr int PER_FRAME_METADATA_KEYS = 0;
760 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800761 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700762 }
763};
764
765template <typename Display>
766struct NoPerFrameMetadataSupportVariant {
767 static constexpr int PER_FRAME_METADATA_KEYS = 0;
768 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800769 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
770 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700771 }
772};
773
774template <typename Display>
775struct Smpte2086PerFrameMetadataSupportVariant {
776 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
777 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800778 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
779 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800780 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
781 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
782 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
783 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
784 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
785 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
786 PerFrameMetadataKey::WHITE_POINT_X,
787 PerFrameMetadataKey::WHITE_POINT_Y,
788 PerFrameMetadataKey::MAX_LUMINANCE,
789 PerFrameMetadataKey::MIN_LUMINANCE,
790 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700791 }
792};
793
794template <typename Display>
795struct Cta861_3_PerFrameMetadataSupportVariant {
796 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
797 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800798 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
799 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800800 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
801 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
802 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700803 }
804};
805
Valerie Haue9e843a2018-12-18 13:39:23 -0800806template <typename Display>
807struct Hdr10_Plus_PerFrameMetadataSupportVariant {
808 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
809 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
810 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
811 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
812 PerFrameMetadataKey::HDR10_PLUS_SEI,
813 })));
814 }
815};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800816/* ------------------------------------------------------------------------
817 * Typical display configurations to test
818 */
819
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700820template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
821 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800822struct Case {
823 using Display = DisplayPolicy;
824 using WideColorSupport = WideColorSupportPolicy;
825 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700826 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800827};
828
829using SimplePrimaryDisplayCase =
830 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700831 HdrNotSupportedVariant<PrimaryDisplayVariant>,
832 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800833using SimpleExternalDisplayCase =
834 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700835 HdrNotSupportedVariant<ExternalDisplayVariant>,
836 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800837using SimpleTertiaryDisplayCase =
838 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700839 HdrNotSupportedVariant<TertiaryDisplayVariant>,
840 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800841using NonHwcVirtualDisplayCase =
842 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700843 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
844 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800845using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
846using HwcVirtualDisplayCase =
847 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700848 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800849 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800850using WideColorP3ColorimetricDisplayCase =
851 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700852 HdrNotSupportedVariant<PrimaryDisplayVariant>,
853 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800854using Hdr10PlusDisplayCase =
855 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
856 Hdr10SupportedVariant<PrimaryDisplayVariant>,
857 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800858using Hdr10DisplayCase =
859 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700860 Hdr10SupportedVariant<PrimaryDisplayVariant>,
861 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800862using HdrHlgDisplayCase =
863 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700864 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
865 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800866using HdrDolbyVisionDisplayCase =
867 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700868 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
869 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
870using HdrSmpte2086DisplayCase =
871 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
872 HdrNotSupportedVariant<PrimaryDisplayVariant>,
873 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
874using HdrCta861_3_DisplayCase =
875 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
876 HdrNotSupportedVariant<PrimaryDisplayVariant>,
877 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700878
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800879/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800880 *
881 * SurfaceFlinger::onHotplugReceived
882 */
883
884TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
885 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700886 constexpr hwc2_display_t hwcDisplayId1 = 456;
887 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800888
889 // --------------------------------------------------------------------
890 // Preconditions
891
892 // Set the current sequence id for accepted events
893 mFlinger.mutableComposerSequenceId() = currentSequenceId;
894
895 // Set the main thread id so that the current thread does not appear to be
896 // the main thread.
897 mFlinger.mutableMainThreadId() = std::thread::id();
898
899 // --------------------------------------------------------------------
900 // Call Expectations
901
902 // We expect invalidate() to be invoked once to trigger display transaction
903 // processing.
904 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
905
906 // --------------------------------------------------------------------
907 // Invocation
908
909 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700910 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
911 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800912
913 // --------------------------------------------------------------------
914 // Postconditions
915
916 // The display transaction needed flag should be set.
917 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
918
919 // All events should be in the pending event queue.
920 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
921 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700922 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800923 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700924 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800925 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
926}
927
928TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
929 constexpr int currentSequenceId = 123;
930 constexpr int otherSequenceId = 321;
931 constexpr hwc2_display_t displayId = 456;
932
933 // --------------------------------------------------------------------
934 // Preconditions
935
936 // Set the current sequence id for accepted events
937 mFlinger.mutableComposerSequenceId() = currentSequenceId;
938
939 // Set the main thread id so that the current thread does not appear to be
940 // the main thread.
941 mFlinger.mutableMainThreadId() = std::thread::id();
942
943 // --------------------------------------------------------------------
944 // Call Expectations
945
946 // We do not expect any calls to invalidate().
947 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
948
949 // --------------------------------------------------------------------
950 // Invocation
951
952 // Call with an unexpected sequence id
953 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
954
955 // --------------------------------------------------------------------
956 // Postconditions
957
958 // The display transaction needed flag should not be set
959 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
960
961 // There should be no pending events
962 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
963}
964
965TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
966 constexpr int currentSequenceId = 123;
967 constexpr hwc2_display_t displayId1 = 456;
968
969 // --------------------------------------------------------------------
970 // Note:
971 // --------------------------------------------------------------------
972 // This test case is a bit tricky. We want to verify that
973 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
974 // don't really want to provide coverage for everything the later function
975 // does as there are specific tests for it.
976 // --------------------------------------------------------------------
977
978 // --------------------------------------------------------------------
979 // Preconditions
980
981 // Set the current sequence id for accepted events
982 mFlinger.mutableComposerSequenceId() = currentSequenceId;
983
984 // Set the main thread id so that the current thread does appear to be the
985 // main thread.
986 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
987
988 // --------------------------------------------------------------------
989 // Call Expectations
990
991 // We expect invalidate() to be invoked once to trigger display transaction
992 // processing.
993 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
994
995 // --------------------------------------------------------------------
996 // Invocation
997
998 // Simulate a disconnect on a display id that is not connected. This should
999 // be enqueued by onHotplugReceived(), and dequeued by
1000 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
1001 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
1002
1003 // --------------------------------------------------------------------
1004 // Postconditions
1005
1006 // The display transaction needed flag should be set.
1007 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1008
1009 // There should be no event queued on return, as it should have been
1010 // processed.
1011 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1012}
1013
1014/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001015 * SurfaceFlinger::createDisplay
1016 */
1017
1018TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1019 const String8 name("virtual.test");
1020
1021 // --------------------------------------------------------------------
1022 // Call Expectations
1023
1024 // The call should notify the interceptor that a display was created.
1025 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1026
1027 // --------------------------------------------------------------------
1028 // Invocation
1029
1030 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1031
1032 // --------------------------------------------------------------------
1033 // Postconditions
1034
1035 // The display should have been added to the current state
1036 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1037 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001038 EXPECT_TRUE(display.isVirtual());
1039 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001040 EXPECT_EQ(name.string(), display.displayName);
1041
1042 // --------------------------------------------------------------------
1043 // Cleanup conditions
1044
1045 // Destroying the display invalidates the display state.
1046 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1047}
1048
1049TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1050 const String8 name("virtual.test");
1051
1052 // --------------------------------------------------------------------
1053 // Call Expectations
1054
1055 // The call should notify the interceptor that a display was created.
1056 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1057
1058 // --------------------------------------------------------------------
1059 // Invocation
1060
1061 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1062
1063 // --------------------------------------------------------------------
1064 // Postconditions
1065
1066 // The display should have been added to the current state
1067 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1068 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001069 EXPECT_TRUE(display.isVirtual());
1070 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001071 EXPECT_EQ(name.string(), display.displayName);
1072
1073 // --------------------------------------------------------------------
1074 // Cleanup conditions
1075
1076 // Destroying the display invalidates the display state.
1077 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1078}
1079
1080/* ------------------------------------------------------------------------
1081 * SurfaceFlinger::destroyDisplay
1082 */
1083
1084TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1085 using Case = NonHwcVirtualDisplayCase;
1086
1087 // --------------------------------------------------------------------
1088 // Preconditions
1089
1090 // A virtual display exists
1091 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1092 existing.inject();
1093
1094 // --------------------------------------------------------------------
1095 // Call Expectations
1096
1097 // The call should notify the interceptor that a display was created.
1098 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1099
1100 // Destroying the display invalidates the display state.
1101 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1102
1103 // --------------------------------------------------------------------
1104 // Invocation
1105
1106 mFlinger.destroyDisplay(existing.token());
1107
1108 // --------------------------------------------------------------------
1109 // Postconditions
1110
1111 // The display should have been removed from the current state
1112 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1113
1114 // Ths display should still exist in the drawing state
1115 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1116
1117 // The display transaction needed flasg should be set
1118 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1119}
1120
1121TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1122 // --------------------------------------------------------------------
1123 // Preconditions
1124
1125 sp<BBinder> displayToken = new BBinder();
1126
1127 // --------------------------------------------------------------------
1128 // Invocation
1129
1130 mFlinger.destroyDisplay(displayToken);
1131}
1132
1133/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001134 * SurfaceFlinger::resetDisplayState
1135 */
1136
1137TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1138 using Case = NonHwcVirtualDisplayCase;
1139
1140 // --------------------------------------------------------------------
1141 // Preconditions
1142
1143 // vsync is enabled and available
Ana Krulecafb45842019-02-13 13:33:03 -08001144 mScheduler->mutablePrimaryHWVsyncEnabled() = true;
1145 mScheduler->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001146
1147 // A display exists
1148 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1149 existing.inject();
1150
1151 // --------------------------------------------------------------------
1152 // Call Expectations
1153
1154 // The call disable vsyncs
1155 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1156
Lloyd Pique41be5d22018-06-21 13:11:48 -07001157 // The call ends any display resyncs
1158 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1159
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001160 // --------------------------------------------------------------------
1161 // Invocation
1162
1163 mFlinger.resetDisplayState();
1164
1165 // --------------------------------------------------------------------
1166 // Postconditions
1167
1168 // vsyncs should be off and not available.
Ana Krulecafb45842019-02-13 13:33:03 -08001169 EXPECT_FALSE(mScheduler->mutablePrimaryHWVsyncEnabled());
1170 EXPECT_FALSE(mScheduler->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001171
1172 // The display should have been removed from the display map.
1173 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1174
1175 // The display should still exist in the current state
1176 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1177
1178 // The display should have been removed from the drawing state
1179 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1180}
1181
1182/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001183 * DisplayDevice::GetBestColorMode
1184 */
1185class GetBestColorModeTest : public DisplayTransactionTest {
1186public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001187 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001188
Valerie Hau9758ae02018-10-09 16:05:09 -07001189 GetBestColorModeTest()
1190 : DisplayTransactionTest(),
Dominik Laskowski075d3172018-05-24 15:50:06 -07001191 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */,
1192 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001193
1194 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1195
1196 void addHwcColorModesMapping(ui::ColorMode colorMode,
1197 std::vector<ui::RenderIntent> renderIntents) {
1198 mHwcColorModes[colorMode] = renderIntents;
1199 }
1200
1201 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1202
1203 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1204
1205 void getBestColorMode() {
1206 mInjector.setHwcColorModes(mHwcColorModes);
1207 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001208 mInjector.setNativeWindow(mNativeWindow);
1209
1210 // Creating a DisplayDevice requires getting default dimensions from the
1211 // native window.
1212 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1213 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1214 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1215 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001216 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1217 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1218 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07001219 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001220 auto displayDevice = mInjector.inject();
1221
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001222 displayDevice->getCompositionDisplay()
1223 ->getDisplayColorProfile()
1224 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1225 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001226 }
1227
1228 ui::Dataspace mOutDataspace;
1229 ui::ColorMode mOutColorMode;
1230 ui::RenderIntent mOutRenderIntent;
1231
1232private:
1233 ui::Dataspace mInputDataspace;
1234 ui::RenderIntent mInputRenderIntent;
1235 bool mHasWideColorGamut = false;
1236 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1237 FakeDisplayDeviceInjector mInjector;
1238};
1239
1240TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1241 addHwcColorModesMapping(ui::ColorMode::SRGB,
1242 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1243 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1244 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1245 setHasWideColorGamut(true);
1246
1247 getBestColorMode();
1248
Peiyong Lin14724e62018-12-05 07:27:30 -08001249 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001250 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1251 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1252}
1253
1254TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1255 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1256 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1257 addHwcColorModesMapping(ui::ColorMode::SRGB,
1258 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1259 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1260 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1261 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1262 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1263 setHasWideColorGamut(true);
1264
1265 getBestColorMode();
1266
1267 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1268 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1269 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1270}
1271
1272TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1273 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1274 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1275 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1276 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1277 setHasWideColorGamut(true);
1278
1279 getBestColorMode();
1280
1281 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1282 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1283 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1284}
1285
1286/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001287 * SurfaceFlinger::getDisplayNativePrimaries
1288 */
1289
1290class GetDisplayNativePrimaries : public DisplayTransactionTest {
1291public:
1292 GetDisplayNativePrimaries();
1293 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1294 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1295
1296private:
1297 static constexpr float mStartingTestValue = 1.0f;
1298};
1299
1300GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1301 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1302 injectFakeNativeWindowSurfaceFactory();
1303}
1304
1305void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1306 ui::DisplayPrimaries& primaries) {
1307 float startingVal = mStartingTestValue;
1308 primaries.red.X = startingVal++;
1309 primaries.red.Y = startingVal++;
1310 primaries.red.Z = startingVal++;
1311 primaries.green.X = startingVal++;
1312 primaries.green.Y = startingVal++;
1313 primaries.green.Z = startingVal++;
1314 primaries.blue.X = startingVal++;
1315 primaries.blue.Y = startingVal++;
1316 primaries.blue.Z = startingVal++;
1317 primaries.white.X = startingVal++;
1318 primaries.white.Y = startingVal++;
1319 primaries.white.Z = startingVal++;
1320}
1321
1322void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1323 const ui::DisplayPrimaries& primaries) {
1324 float startingVal = mStartingTestValue;
1325 EXPECT_EQ(primaries.red.X, startingVal++);
1326 EXPECT_EQ(primaries.red.Y, startingVal++);
1327 EXPECT_EQ(primaries.red.Z, startingVal++);
1328 EXPECT_EQ(primaries.green.X, startingVal++);
1329 EXPECT_EQ(primaries.green.Y, startingVal++);
1330 EXPECT_EQ(primaries.green.Z, startingVal++);
1331 EXPECT_EQ(primaries.blue.X, startingVal++);
1332 EXPECT_EQ(primaries.blue.Y, startingVal++);
1333 EXPECT_EQ(primaries.blue.Z, startingVal++);
1334 EXPECT_EQ(primaries.white.X, startingVal++);
1335 EXPECT_EQ(primaries.white.Y, startingVal++);
1336 EXPECT_EQ(primaries.white.Z, startingVal++);
1337}
1338
1339TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1340 ui::DisplayPrimaries primaries;
1341 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1342}
1343
Daniel Solomon42d04562019-01-20 21:03:19 -08001344TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1345 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1346 injector.inject();
1347 auto internalDisplayToken = injector.token();
1348
1349 ui::DisplayPrimaries expectedPrimaries;
1350 populateDummyDisplayNativePrimaries(expectedPrimaries);
1351 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1352
1353 ui::DisplayPrimaries primaries;
1354 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1355
1356 checkDummyDisplayNativePrimaries(primaries);
1357}
1358
1359TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1360 sp<BBinder> notInternalDisplayToken = new BBinder();
1361
1362 ui::DisplayPrimaries primaries;
1363 populateDummyDisplayNativePrimaries(primaries);
1364 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1365
1366 // Check primaries argument wasn't modified in case of failure
1367 checkDummyDisplayNativePrimaries(primaries);
1368}
1369
1370/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001371 * SurfaceFlinger::setupNewDisplayDeviceInternal
1372 */
1373
1374class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1375public:
1376 template <typename T>
1377 void setupNewDisplayDeviceInternalTest();
1378};
1379
1380template <typename Case>
1381void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1382 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001383 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1384 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001385 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001386
1387 // --------------------------------------------------------------------
1388 // Preconditions
1389
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001390 // Wide color displays support is configured appropriately
1391 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001392
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001393 // The display is setup with the HWC.
1394 Case::Display::injectHwcDisplay(this);
1395
1396 // SurfaceFlinger will use a test-controlled factory for native window
1397 // surfaces.
1398 injectFakeNativeWindowSurfaceFactory();
1399
1400 // --------------------------------------------------------------------
1401 // Call Expectations
1402
1403 // Various native window calls will be made.
1404 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001405 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001406 Case::WideColorSupport::setupComposerCallExpectations(this);
1407 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001408 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001409
1410 // --------------------------------------------------------------------
1411 // Invocation
1412
1413 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001414 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1415 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001416 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1417
Dominik Laskowski075d3172018-05-24 15:50:06 -07001418 auto device =
1419 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1420 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001421
1422 // --------------------------------------------------------------------
1423 // Postconditions
1424
1425 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001426 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1427 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001428 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001429 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001430 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1431 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1432 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001433 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001434 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1435 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1436 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001437 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1438 // remapped, and the test only ever sets up one config. If there were an error
1439 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
1440 EXPECT_EQ(0, device->getActiveConfig());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001441 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1442 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001443}
1444
1445TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1446 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1447}
1448
1449TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1450 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1451}
1452
1453TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1454 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1455}
1456
1457TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001458 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001459
Dominik Laskowski075d3172018-05-24 15:50:06 -07001460 // Insert display data so that the HWC thinks it created the virtual display.
1461 const auto displayId = Case::Display::DISPLAY_ID::get();
1462 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001463 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001464
1465 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001466}
1467
1468TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1469 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1470}
1471
Valerie Haue9e843a2018-12-18 13:39:23 -08001472TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1473 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1474}
1475
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001476TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1477 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1478}
1479
1480TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1481 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1482}
1483
1484TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1485 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1486}
1487
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001488TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1489 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1490}
1491
1492TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1493 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1494}
1495
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001496/* ------------------------------------------------------------------------
1497 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1498 */
1499
1500class HandleTransactionLockedTest : public DisplayTransactionTest {
1501public:
1502 template <typename Case>
1503 void setupCommonPreconditions();
1504
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001505 template <typename Case, bool connected>
1506 static void expectHotplugReceived(mock::EventThread*);
1507
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001508 template <typename Case>
1509 void setupCommonCallExpectationsForConnectProcessing();
1510
1511 template <typename Case>
1512 void setupCommonCallExpectationsForDisconnectProcessing();
1513
1514 template <typename Case>
1515 void processesHotplugConnectCommon();
1516
1517 template <typename Case>
1518 void ignoresHotplugConnectCommon();
1519
1520 template <typename Case>
1521 void processesHotplugDisconnectCommon();
1522
1523 template <typename Case>
1524 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1525
1526 template <typename Case>
1527 void verifyPhysicalDisplayIsConnected();
1528
1529 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1530};
1531
1532template <typename Case>
1533void HandleTransactionLockedTest::setupCommonPreconditions() {
1534 // Wide color displays support is configured appropriately
1535 Case::WideColorSupport::injectConfigChange(this);
1536
1537 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1538 injectFakeBufferQueueFactory();
1539
1540 // SurfaceFlinger will use a test-controlled factory for native window
1541 // surfaces.
1542 injectFakeNativeWindowSurfaceFactory();
1543}
1544
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001545template <typename Case, bool connected>
1546void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1547 const auto convert = [](auto physicalDisplayId) {
1548 return std::make_optional(DisplayId{physicalDisplayId});
1549 };
1550
1551 EXPECT_CALL(*eventThread,
1552 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1553 .Times(1);
1554}
1555
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001556template <typename Case>
1557void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1558 Case::Display::setupHwcHotplugCallExpectations(this);
1559
1560 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1561 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1562 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1563 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1564
1565 Case::WideColorSupport::setupComposerCallExpectations(this);
1566 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001567 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001568
1569 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001570 expectHotplugReceived<Case, true>(mEventThread);
1571 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001572}
1573
1574template <typename Case>
1575void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1576 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001577
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001578 expectHotplugReceived<Case, false>(mEventThread);
1579 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001580}
1581
1582template <typename Case>
1583void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1584 // The display device should have been set up in the list of displays.
1585 ASSERT_TRUE(hasDisplayDevice(displayToken));
1586 const auto& device = getDisplayDevice(displayToken);
1587 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001588 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001589
1590 // The display should have been set up in the current display state
1591 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1592 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001593 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1594 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1595 : Case::Display::DISPLAY_ID::get(),
1596 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001597
1598 // The display should have been set up in the drawing display state
1599 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1600 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001601 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1602 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1603 : Case::Display::DISPLAY_ID::get(),
1604 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001605}
1606
1607template <typename Case>
1608void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1609 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001610 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001611
Dominik Laskowski075d3172018-05-24 15:50:06 -07001612 // SF should have a display token.
1613 const auto displayId = Case::Display::DISPLAY_ID::get();
1614 ASSERT_TRUE(displayId);
1615 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1616 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001617
1618 verifyDisplayIsConnected<Case>(displayToken);
1619}
1620
1621void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1622 EXPECT_FALSE(hasDisplayDevice(displayToken));
1623 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1624 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1625}
1626
1627template <typename Case>
1628void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1629 // --------------------------------------------------------------------
1630 // Preconditions
1631
1632 setupCommonPreconditions<Case>();
1633
1634 // A hotplug connect event is enqueued for a display
1635 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001636
1637 // --------------------------------------------------------------------
1638 // Call Expectations
1639
1640 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001641
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001642 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001643
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001644 // --------------------------------------------------------------------
1645 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001646
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001647 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001648
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001649 // --------------------------------------------------------------------
1650 // Postconditions
1651
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001652 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001653
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001654 // --------------------------------------------------------------------
1655 // Cleanup conditions
1656
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001657 EXPECT_CALL(*mComposer,
1658 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001659 .WillOnce(Return(Error::NONE));
1660 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001661}
1662
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001663template <typename Case>
1664void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1665 // --------------------------------------------------------------------
1666 // Preconditions
1667
1668 setupCommonPreconditions<Case>();
1669
1670 // A hotplug connect event is enqueued for a display
1671 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1672
1673 // --------------------------------------------------------------------
1674 // Invocation
1675
1676 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1677
1678 // --------------------------------------------------------------------
1679 // Postconditions
1680
1681 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001682 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001683}
1684
1685template <typename Case>
1686void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1687 // --------------------------------------------------------------------
1688 // Preconditions
1689
1690 setupCommonPreconditions<Case>();
1691
1692 // A hotplug disconnect event is enqueued for a display
1693 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1694
1695 // The display is already completely set up.
1696 Case::Display::injectHwcDisplay(this);
1697 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1698 existing.inject();
1699
1700 // --------------------------------------------------------------------
1701 // Call Expectations
1702
1703 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001704 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1705 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001706
1707 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1708
1709 // --------------------------------------------------------------------
1710 // Invocation
1711
1712 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1713
1714 // --------------------------------------------------------------------
1715 // Postconditions
1716
1717 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001718 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001719
Dominik Laskowski075d3172018-05-24 15:50:06 -07001720 // SF should not have a display token.
1721 const auto displayId = Case::Display::DISPLAY_ID::get();
1722 ASSERT_TRUE(displayId);
1723 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001724
1725 // The existing token should have been removed
1726 verifyDisplayIsNotConnected(existing.token());
1727}
1728
1729TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1730 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1731}
1732
1733TEST_F(HandleTransactionLockedTest,
1734 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1735 // Inject an external display.
1736 ExternalDisplayVariant::injectHwcDisplay(this);
1737
1738 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1739}
1740
1741TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1742 // Inject a primary display.
1743 PrimaryDisplayVariant::injectHwcDisplay(this);
1744
1745 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1746}
1747
1748TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1749 // Inject both a primary and external display.
1750 PrimaryDisplayVariant::injectHwcDisplay(this);
1751 ExternalDisplayVariant::injectHwcDisplay(this);
1752
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001753 // TODO: This is an unnecessary call.
1754 EXPECT_CALL(*mComposer,
1755 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
1756 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
1757 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
1758 Return(Error::NONE)));
1759
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001760 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1761
1762 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1763}
1764
1765TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1766 // Inject a primary display.
1767 PrimaryDisplayVariant::injectHwcDisplay(this);
1768
1769 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1770
1771 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1772}
1773
1774TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1775 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1776}
1777
1778TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1779 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1780}
1781
1782TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1783 using Case = SimplePrimaryDisplayCase;
1784
1785 // --------------------------------------------------------------------
1786 // Preconditions
1787
1788 setupCommonPreconditions<Case>();
1789
1790 // A hotplug connect event is enqueued for a display
1791 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1792 // A hotplug disconnect event is also enqueued for the same display
1793 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1794
1795 // --------------------------------------------------------------------
1796 // Call Expectations
1797
1798 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1799
1800 setupCommonCallExpectationsForConnectProcessing<Case>();
1801 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1802
1803 EXPECT_CALL(*mComposer,
1804 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1805 .WillOnce(Return(Error::NONE));
1806 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1807
1808 // --------------------------------------------------------------------
1809 // Invocation
1810
1811 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1812
1813 // --------------------------------------------------------------------
1814 // Postconditions
1815
1816 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001817 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001818
Dominik Laskowski075d3172018-05-24 15:50:06 -07001819 // SF should not have a display token.
1820 const auto displayId = Case::Display::DISPLAY_ID::get();
1821 ASSERT_TRUE(displayId);
1822 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001823}
1824
1825TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1826 using Case = SimplePrimaryDisplayCase;
1827
1828 // --------------------------------------------------------------------
1829 // Preconditions
1830
1831 setupCommonPreconditions<Case>();
1832
1833 // The display is already completely set up.
1834 Case::Display::injectHwcDisplay(this);
1835 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1836 existing.inject();
1837
1838 // A hotplug disconnect event is enqueued for a display
1839 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1840 // A hotplug connect event is also enqueued for the same display
1841 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1842
1843 // --------------------------------------------------------------------
1844 // Call Expectations
1845
1846 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1847
1848 setupCommonCallExpectationsForConnectProcessing<Case>();
1849 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1850
1851 // --------------------------------------------------------------------
1852 // Invocation
1853
1854 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1855
1856 // --------------------------------------------------------------------
1857 // Postconditions
1858
1859 // The existing token should have been removed
1860 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001861 const auto displayId = Case::Display::DISPLAY_ID::get();
1862 ASSERT_TRUE(displayId);
1863 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1864 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001865
1866 // A new display should be connected in its place
1867
1868 verifyPhysicalDisplayIsConnected<Case>();
1869
1870 // --------------------------------------------------------------------
1871 // Cleanup conditions
1872
1873 EXPECT_CALL(*mComposer,
1874 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1875 .WillOnce(Return(Error::NONE));
1876 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1877}
1878
1879TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1880 using Case = HwcVirtualDisplayCase;
1881
1882 // --------------------------------------------------------------------
1883 // Preconditions
1884
1885 // The HWC supports at least one virtual display
1886 injectMockComposer(1);
1887
1888 setupCommonPreconditions<Case>();
1889
1890 // A virtual display was added to the current state, and it has a
1891 // surface(producer)
1892 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07001893
Dominik Laskowski075d3172018-05-24 15:50:06 -07001894 DisplayDeviceState state;
1895 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001896
1897 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001898 state.surface = surface;
1899 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001900
1901 // --------------------------------------------------------------------
1902 // Call Expectations
1903
1904 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1905 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1906
1907 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1908 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1909 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1910 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1911 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1912 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1913 Return(NO_ERROR)));
1914 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1915 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1916
1917 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1918
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001919 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001920 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1921
1922 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1923 Case::WideColorSupport::setupComposerCallExpectations(this);
1924 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001925 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001926
1927 // --------------------------------------------------------------------
1928 // Invocation
1929
1930 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1931
1932 // --------------------------------------------------------------------
1933 // Postconditions
1934
1935 // The display device should have been set up in the list of displays.
1936 verifyDisplayIsConnected<Case>(displayToken);
1937
1938 // --------------------------------------------------------------------
1939 // Cleanup conditions
1940
1941 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1942 .WillOnce(Return(Error::NONE));
1943 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08001944
1945 // Cleanup
1946 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
1947 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001948}
1949
1950TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1951 using Case = HwcVirtualDisplayCase;
1952
1953 // --------------------------------------------------------------------
1954 // Preconditions
1955
1956 // The HWC supports at least one virtual display
1957 injectMockComposer(1);
1958
1959 setupCommonPreconditions<Case>();
1960
1961 // A virtual display was added to the current state, but it does not have a
1962 // surface.
1963 sp<BBinder> displayToken = new BBinder();
1964
Dominik Laskowski075d3172018-05-24 15:50:06 -07001965 DisplayDeviceState state;
1966 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001967
Dominik Laskowski075d3172018-05-24 15:50:06 -07001968 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001969
1970 // --------------------------------------------------------------------
1971 // Call Expectations
1972
1973 // --------------------------------------------------------------------
1974 // Invocation
1975
1976 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1977
1978 // --------------------------------------------------------------------
1979 // Postconditions
1980
1981 // There will not be a display device set up.
1982 EXPECT_FALSE(hasDisplayDevice(displayToken));
1983
1984 // The drawing display state will be set from the current display state.
1985 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1986 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001987 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001988}
1989
1990TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1991 using Case = HwcVirtualDisplayCase;
1992
1993 // --------------------------------------------------------------------
1994 // Preconditions
1995
1996 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07001997 const auto displayId = Case::Display::DISPLAY_ID::get();
1998 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001999 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002000 Case::Display::injectHwcDisplay(this);
2001 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2002 existing.inject();
2003 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2004
2005 // --------------------------------------------------------------------
2006 // Call Expectations
2007
2008 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2009
2010 // --------------------------------------------------------------------
2011 // Invocation
2012
2013 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2014
2015 // --------------------------------------------------------------------
2016 // Postconditions
2017
2018 // The existing token should have been removed
2019 verifyDisplayIsNotConnected(existing.token());
2020}
2021
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002022TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2023 using Case = NonHwcVirtualDisplayCase;
2024
2025 constexpr uint32_t oldLayerStack = 0u;
2026 constexpr uint32_t newLayerStack = 123u;
2027
2028 // --------------------------------------------------------------------
2029 // Preconditions
2030
2031 // A display is set up
2032 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2033 display.inject();
2034
2035 // There is a change to the layerStack state
2036 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2037 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2038
2039 // --------------------------------------------------------------------
2040 // Invocation
2041
2042 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2043
2044 // --------------------------------------------------------------------
2045 // Postconditions
2046
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002047 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002048}
2049
2050TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2051 using Case = NonHwcVirtualDisplayCase;
2052
2053 constexpr int oldTransform = 0;
2054 constexpr int newTransform = 2;
2055
2056 // --------------------------------------------------------------------
2057 // Preconditions
2058
2059 // A display is set up
2060 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2061 display.inject();
2062
2063 // There is a change to the orientation state
2064 display.mutableDrawingDisplayState().orientation = oldTransform;
2065 display.mutableCurrentDisplayState().orientation = newTransform;
2066
2067 // --------------------------------------------------------------------
2068 // Invocation
2069
2070 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2071
2072 // --------------------------------------------------------------------
2073 // Postconditions
2074
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002075 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002076}
2077
2078TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2079 using Case = NonHwcVirtualDisplayCase;
2080
2081 const Rect oldViewport(0, 0, 0, 0);
2082 const Rect newViewport(0, 0, 123, 456);
2083
2084 // --------------------------------------------------------------------
2085 // Preconditions
2086
2087 // A display is set up
2088 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2089 display.inject();
2090
2091 // There is a change to the viewport state
2092 display.mutableDrawingDisplayState().viewport = oldViewport;
2093 display.mutableCurrentDisplayState().viewport = newViewport;
2094
2095 // --------------------------------------------------------------------
2096 // Invocation
2097
2098 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2099
2100 // --------------------------------------------------------------------
2101 // Postconditions
2102
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002103 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002104}
2105
2106TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2107 using Case = NonHwcVirtualDisplayCase;
2108
2109 const Rect oldFrame(0, 0, 0, 0);
2110 const Rect newFrame(0, 0, 123, 456);
2111
2112 // --------------------------------------------------------------------
2113 // Preconditions
2114
2115 // A display is set up
2116 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2117 display.inject();
2118
2119 // There is a change to the viewport state
2120 display.mutableDrawingDisplayState().frame = oldFrame;
2121 display.mutableCurrentDisplayState().frame = newFrame;
2122
2123 // --------------------------------------------------------------------
2124 // Invocation
2125
2126 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2127
2128 // --------------------------------------------------------------------
2129 // Postconditions
2130
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002131 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002132}
2133
2134TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2135 using Case = NonHwcVirtualDisplayCase;
2136
2137 constexpr int oldWidth = 0;
2138 constexpr int oldHeight = 10;
2139 constexpr int newWidth = 123;
2140
2141 // --------------------------------------------------------------------
2142 // Preconditions
2143
2144 // A display is set up
2145 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002146 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002147 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002148 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2149 display.setNativeWindow(nativeWindow);
2150 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002151 // Setup injection expections
2152 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2153 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2154 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2155 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002156 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2157 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2158 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002159 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002160 display.inject();
2161
2162 // There is a change to the viewport state
2163 display.mutableDrawingDisplayState().width = oldWidth;
2164 display.mutableDrawingDisplayState().height = oldHeight;
2165 display.mutableCurrentDisplayState().width = newWidth;
2166 display.mutableCurrentDisplayState().height = oldHeight;
2167
2168 // --------------------------------------------------------------------
2169 // Call Expectations
2170
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002171 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002172
2173 // --------------------------------------------------------------------
2174 // Invocation
2175
2176 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2177}
2178
2179TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2180 using Case = NonHwcVirtualDisplayCase;
2181
2182 constexpr int oldWidth = 0;
2183 constexpr int oldHeight = 10;
2184 constexpr int newHeight = 123;
2185
2186 // --------------------------------------------------------------------
2187 // Preconditions
2188
2189 // A display is set up
2190 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002191 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002192 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002193 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2194 display.setNativeWindow(nativeWindow);
2195 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002196 // Setup injection expections
2197 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2198 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2199 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2200 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002201 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2202 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2203 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002204 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002205 display.inject();
2206
2207 // There is a change to the viewport state
2208 display.mutableDrawingDisplayState().width = oldWidth;
2209 display.mutableDrawingDisplayState().height = oldHeight;
2210 display.mutableCurrentDisplayState().width = oldWidth;
2211 display.mutableCurrentDisplayState().height = newHeight;
2212
2213 // --------------------------------------------------------------------
2214 // Call Expectations
2215
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002216 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002217
2218 // --------------------------------------------------------------------
2219 // Invocation
2220
2221 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2222}
2223
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002224/* ------------------------------------------------------------------------
2225 * SurfaceFlinger::setDisplayStateLocked
2226 */
2227
2228TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2229 // --------------------------------------------------------------------
2230 // Preconditions
2231
2232 // We have an unknown display token not associated with a known display
2233 sp<BBinder> displayToken = new BBinder();
2234
2235 // The requested display state references the unknown display.
2236 DisplayState state;
2237 state.what = DisplayState::eLayerStackChanged;
2238 state.token = displayToken;
2239 state.layerStack = 456;
2240
2241 // --------------------------------------------------------------------
2242 // Invocation
2243
2244 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2245
2246 // --------------------------------------------------------------------
2247 // Postconditions
2248
2249 // The returned flags are empty
2250 EXPECT_EQ(0u, flags);
2251
2252 // The display token still doesn't match anything known.
2253 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2254}
2255
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002256TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2257 using Case = SimplePrimaryDisplayCase;
2258
2259 // --------------------------------------------------------------------
2260 // Preconditions
2261
2262 // A display is already set up
2263 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2264 display.inject();
2265
2266 // No changes are made to the display
2267 DisplayState state;
2268 state.what = 0;
2269 state.token = display.token();
2270
2271 // --------------------------------------------------------------------
2272 // Invocation
2273
2274 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2275
2276 // --------------------------------------------------------------------
2277 // Postconditions
2278
2279 // The returned flags are empty
2280 EXPECT_EQ(0u, flags);
2281}
2282
2283TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2284 using Case = SimplePrimaryDisplayCase;
2285
2286 // --------------------------------------------------------------------
2287 // Preconditions
2288
2289 // A display is already set up
2290 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2291 display.inject();
2292
2293 // There is a surface that can be set.
2294 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2295
2296 // The current display state has the surface set
2297 display.mutableCurrentDisplayState().surface = surface;
2298
2299 // The incoming request sets the same surface
2300 DisplayState state;
2301 state.what = DisplayState::eSurfaceChanged;
2302 state.token = display.token();
2303 state.surface = surface;
2304
2305 // --------------------------------------------------------------------
2306 // Invocation
2307
2308 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2309
2310 // --------------------------------------------------------------------
2311 // Postconditions
2312
2313 // The returned flags are empty
2314 EXPECT_EQ(0u, flags);
2315
2316 // The current display state is unchanged.
2317 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2318}
2319
2320TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2321 using Case = SimplePrimaryDisplayCase;
2322
2323 // --------------------------------------------------------------------
2324 // Preconditions
2325
2326 // A display is already set up
2327 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2328 display.inject();
2329
2330 // There is a surface that can be set.
2331 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2332
2333 // The current display state does not have a surface
2334 display.mutableCurrentDisplayState().surface = nullptr;
2335
2336 // The incoming request sets a surface
2337 DisplayState state;
2338 state.what = DisplayState::eSurfaceChanged;
2339 state.token = display.token();
2340 state.surface = surface;
2341
2342 // --------------------------------------------------------------------
2343 // Invocation
2344
2345 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2346
2347 // --------------------------------------------------------------------
2348 // Postconditions
2349
2350 // The returned flags indicate a transaction is needed
2351 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2352
2353 // The current display layer stack state is set to the new value
2354 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2355}
2356
2357TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2358 using Case = SimplePrimaryDisplayCase;
2359
2360 // --------------------------------------------------------------------
2361 // Preconditions
2362
2363 // A display is already set up
2364 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2365 display.inject();
2366
2367 // The display has a layer stack set
2368 display.mutableCurrentDisplayState().layerStack = 456u;
2369
2370 // The incoming request sets the same layer stack
2371 DisplayState state;
2372 state.what = DisplayState::eLayerStackChanged;
2373 state.token = display.token();
2374 state.layerStack = 456u;
2375
2376 // --------------------------------------------------------------------
2377 // Invocation
2378
2379 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2380
2381 // --------------------------------------------------------------------
2382 // Postconditions
2383
2384 // The returned flags are empty
2385 EXPECT_EQ(0u, flags);
2386
2387 // The current display state is unchanged
2388 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2389}
2390
2391TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2392 using Case = SimplePrimaryDisplayCase;
2393
2394 // --------------------------------------------------------------------
2395 // Preconditions
2396
2397 // A display is set up
2398 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2399 display.inject();
2400
2401 // The display has a layer stack set
2402 display.mutableCurrentDisplayState().layerStack = 654u;
2403
2404 // The incoming request sets a different layer stack
2405 DisplayState state;
2406 state.what = DisplayState::eLayerStackChanged;
2407 state.token = display.token();
2408 state.layerStack = 456u;
2409
2410 // --------------------------------------------------------------------
2411 // Invocation
2412
2413 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2414
2415 // --------------------------------------------------------------------
2416 // Postconditions
2417
2418 // The returned flags indicate a transaction is needed
2419 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2420
2421 // The desired display state has been set to the new value.
2422 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2423}
2424
2425TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2426 using Case = SimplePrimaryDisplayCase;
2427 constexpr int initialOrientation = 180;
2428 const Rect initialFrame = {1, 2, 3, 4};
2429 const Rect initialViewport = {5, 6, 7, 8};
2430
2431 // --------------------------------------------------------------------
2432 // Preconditions
2433
2434 // A display is set up
2435 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2436 display.inject();
2437
2438 // The current display state projection state is all set
2439 display.mutableCurrentDisplayState().orientation = initialOrientation;
2440 display.mutableCurrentDisplayState().frame = initialFrame;
2441 display.mutableCurrentDisplayState().viewport = initialViewport;
2442
2443 // The incoming request sets the same projection state
2444 DisplayState state;
2445 state.what = DisplayState::eDisplayProjectionChanged;
2446 state.token = display.token();
2447 state.orientation = initialOrientation;
2448 state.frame = initialFrame;
2449 state.viewport = initialViewport;
2450
2451 // --------------------------------------------------------------------
2452 // Invocation
2453
2454 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2455
2456 // --------------------------------------------------------------------
2457 // Postconditions
2458
2459 // The returned flags are empty
2460 EXPECT_EQ(0u, flags);
2461
2462 // The current display state is unchanged
2463 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2464
2465 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2466 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2467}
2468
2469TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2470 using Case = SimplePrimaryDisplayCase;
2471 constexpr int initialOrientation = 90;
2472 constexpr int desiredOrientation = 180;
2473
2474 // --------------------------------------------------------------------
2475 // Preconditions
2476
2477 // A display is set up
2478 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2479 display.inject();
2480
2481 // The current display state has an orientation set
2482 display.mutableCurrentDisplayState().orientation = initialOrientation;
2483
2484 // The incoming request sets a different orientation
2485 DisplayState state;
2486 state.what = DisplayState::eDisplayProjectionChanged;
2487 state.token = display.token();
2488 state.orientation = desiredOrientation;
2489
2490 // --------------------------------------------------------------------
2491 // Invocation
2492
2493 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2494
2495 // --------------------------------------------------------------------
2496 // Postconditions
2497
2498 // The returned flags indicate a transaction is needed
2499 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2500
2501 // The current display state has the new value.
2502 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2503}
2504
2505TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2506 using Case = SimplePrimaryDisplayCase;
2507 const Rect initialFrame = {0, 0, 0, 0};
2508 const Rect desiredFrame = {5, 6, 7, 8};
2509
2510 // --------------------------------------------------------------------
2511 // Preconditions
2512
2513 // A display is set up
2514 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2515 display.inject();
2516
2517 // The current display state does not have a frame
2518 display.mutableCurrentDisplayState().frame = initialFrame;
2519
2520 // The incoming request sets a frame
2521 DisplayState state;
2522 state.what = DisplayState::eDisplayProjectionChanged;
2523 state.token = display.token();
2524 state.frame = desiredFrame;
2525
2526 // --------------------------------------------------------------------
2527 // Invocation
2528
2529 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2530
2531 // --------------------------------------------------------------------
2532 // Postconditions
2533
2534 // The returned flags indicate a transaction is needed
2535 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2536
2537 // The current display state has the new value.
2538 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2539}
2540
2541TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2542 using Case = SimplePrimaryDisplayCase;
2543 const Rect initialViewport = {0, 0, 0, 0};
2544 const Rect desiredViewport = {5, 6, 7, 8};
2545
2546 // --------------------------------------------------------------------
2547 // Preconditions
2548
2549 // A display is set up
2550 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2551 display.inject();
2552
2553 // The current display state does not have a viewport
2554 display.mutableCurrentDisplayState().viewport = initialViewport;
2555
2556 // The incoming request sets a viewport
2557 DisplayState state;
2558 state.what = DisplayState::eDisplayProjectionChanged;
2559 state.token = display.token();
2560 state.viewport = desiredViewport;
2561
2562 // --------------------------------------------------------------------
2563 // Invocation
2564
2565 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2566
2567 // --------------------------------------------------------------------
2568 // Postconditions
2569
2570 // The returned flags indicate a transaction is needed
2571 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2572
2573 // The current display state has the new value.
2574 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2575}
2576
2577TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2578 using Case = SimplePrimaryDisplayCase;
2579 constexpr uint32_t initialWidth = 1024;
2580 constexpr uint32_t initialHeight = 768;
2581
2582 // --------------------------------------------------------------------
2583 // Preconditions
2584
2585 // A display is set up
2586 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2587 display.inject();
2588
2589 // The current display state has a size set
2590 display.mutableCurrentDisplayState().width = initialWidth;
2591 display.mutableCurrentDisplayState().height = initialHeight;
2592
2593 // The incoming request sets the same display size
2594 DisplayState state;
2595 state.what = DisplayState::eDisplaySizeChanged;
2596 state.token = display.token();
2597 state.width = initialWidth;
2598 state.height = initialHeight;
2599
2600 // --------------------------------------------------------------------
2601 // Invocation
2602
2603 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2604
2605 // --------------------------------------------------------------------
2606 // Postconditions
2607
2608 // The returned flags are empty
2609 EXPECT_EQ(0u, flags);
2610
2611 // The current display state is unchanged
2612 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2613 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2614}
2615
2616TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2617 using Case = SimplePrimaryDisplayCase;
2618 constexpr uint32_t initialWidth = 0;
2619 constexpr uint32_t desiredWidth = 1024;
2620
2621 // --------------------------------------------------------------------
2622 // Preconditions
2623
2624 // A display is set up
2625 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2626 display.inject();
2627
2628 // The display does not yet have a width
2629 display.mutableCurrentDisplayState().width = initialWidth;
2630
2631 // The incoming request sets a display width
2632 DisplayState state;
2633 state.what = DisplayState::eDisplaySizeChanged;
2634 state.token = display.token();
2635 state.width = desiredWidth;
2636
2637 // --------------------------------------------------------------------
2638 // Invocation
2639
2640 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2641
2642 // --------------------------------------------------------------------
2643 // Postconditions
2644
2645 // The returned flags indicate a transaction is needed
2646 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2647
2648 // The current display state has the new value.
2649 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2650}
2651
2652TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2653 using Case = SimplePrimaryDisplayCase;
2654 constexpr uint32_t initialHeight = 0;
2655 constexpr uint32_t desiredHeight = 768;
2656
2657 // --------------------------------------------------------------------
2658 // Preconditions
2659
2660 // A display is set up
2661 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2662 display.inject();
2663
2664 // The display does not yet have a height
2665 display.mutableCurrentDisplayState().height = initialHeight;
2666
2667 // The incoming request sets a display height
2668 DisplayState state;
2669 state.what = DisplayState::eDisplaySizeChanged;
2670 state.token = display.token();
2671 state.height = desiredHeight;
2672
2673 // --------------------------------------------------------------------
2674 // Invocation
2675
2676 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2677
2678 // --------------------------------------------------------------------
2679 // Postconditions
2680
2681 // The returned flags indicate a transaction is needed
2682 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2683
2684 // The current display state has the new value.
2685 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2686}
2687
Lloyd Pique86016da2018-03-01 16:09:38 -08002688/* ------------------------------------------------------------------------
2689 * SurfaceFlinger::onInitializeDisplays
2690 */
2691
2692TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2693 using Case = SimplePrimaryDisplayCase;
2694
2695 // --------------------------------------------------------------------
2696 // Preconditions
2697
2698 // A primary display is set up
2699 Case::Display::injectHwcDisplay(this);
2700 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2701 primaryDisplay.inject();
2702
2703 // --------------------------------------------------------------------
2704 // Call Expectations
2705
2706 // We expect the surface interceptor to possibly be used, but we treat it as
2707 // disabled since it is called as a side effect rather than directly by this
2708 // function.
2709 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2710
2711 // We expect a call to get the active display config.
2712 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2713
2714 // We expect invalidate() to be invoked once to trigger display transaction
2715 // processing.
2716 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2717
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002718 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2719
Lloyd Pique86016da2018-03-01 16:09:38 -08002720 // --------------------------------------------------------------------
2721 // Invocation
2722
2723 mFlinger.onInitializeDisplays();
2724
2725 // --------------------------------------------------------------------
2726 // Postconditions
2727
2728 // The primary display should have a current state
2729 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2730 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2731 // The layer stack state should be set to zero
2732 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2733 // The orientation state should be set to zero
2734 EXPECT_EQ(0, primaryDisplayState.orientation);
2735
2736 // The frame state should be set to INVALID
2737 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2738
2739 // The viewport state should be set to INVALID
2740 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2741
2742 // The width and height should both be zero
2743 EXPECT_EQ(0u, primaryDisplayState.width);
2744 EXPECT_EQ(0u, primaryDisplayState.height);
2745
2746 // The display should be set to HWC_POWER_MODE_NORMAL
2747 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2748 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2749 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2750
2751 // The display refresh period should be set in the frame tracker.
2752 FrameStats stats;
2753 mFlinger.getAnimFrameTracker().getStats(&stats);
2754 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2755
2756 // The display transaction needed flag should be set.
2757 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2758
2759 // The compositor timing should be set to default values
2760 const auto& compositorTiming = mFlinger.getCompositorTiming();
2761 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2762 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2763 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2764}
2765
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002766/* ------------------------------------------------------------------------
2767 * SurfaceFlinger::setPowerModeInternal
2768 */
2769
2770// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07002771template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002772struct DozeIsSupportedVariant {
2773 static constexpr bool DOZE_SUPPORTED = true;
2774 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2775 IComposerClient::PowerMode::DOZE;
2776 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2777 IComposerClient::PowerMode::DOZE_SUSPEND;
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 {Hwc2::DisplayCapability::DOZE})),
2783 Return(Error::NONE)));
2784 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002785};
2786
Peiyong Lined531a32018-10-26 18:27:56 -07002787template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002788// Used when we simulate a display that does not support doze.
2789struct DozeNotSupportedVariant {
2790 static constexpr bool DOZE_SUPPORTED = false;
2791 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2792 IComposerClient::PowerMode::ON;
2793 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2794 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07002795
2796 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2797 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2798 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
2799 Return(Error::NONE)));
2800 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002801};
2802
2803struct EventThreadBaseSupportedVariant {
2804 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
2805 // The event control thread should not be notified.
2806 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
2807
2808 // The event thread should not be notified.
2809 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
2810 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
2811 }
2812};
2813
2814struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
2815 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2816 // These calls are only expected for the primary display.
2817
2818 // Instead expect no calls.
2819 setupEventAndEventControlThreadNoCallExpectations(test);
2820 }
2821
2822 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2823 // These calls are only expected for the primary display.
2824
2825 // Instead expect no calls.
2826 setupEventAndEventControlThreadNoCallExpectations(test);
2827 }
2828};
2829
2830struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
2831 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2832 // The event control thread should be notified to enable vsyncs
2833 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
2834
2835 // The event thread should be notified that the screen was acquired.
2836 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
2837 }
2838
2839 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2840 // There should be a call to setVsyncEnabled(false)
2841 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
2842
2843 // The event thread should not be notified that the screen was released.
2844 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
2845 }
2846};
2847
Lloyd Pique41be5d22018-06-21 13:11:48 -07002848struct DispSyncIsSupportedVariant {
2849 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique41be5d22018-06-21 13:11:48 -07002850 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
2851 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
2852 }
2853
2854 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
2855 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
2856 }
2857};
2858
2859struct DispSyncNotSupportedVariant {
2860 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2861
2862 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2863};
2864
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002865// --------------------------------------------------------------------
2866// Note:
2867//
2868// There are a large number of transitions we could test, however we only test a
2869// selected subset which provides complete test coverage of the implementation.
2870// --------------------------------------------------------------------
2871
2872template <int initialPowerMode, int targetPowerMode>
2873struct TransitionVariantCommon {
2874 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
2875 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
2876
2877 static void verifyPostconditions(DisplayTransactionTest*) {}
2878};
2879
2880struct TransitionOffToOnVariant
2881 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
2882 template <typename Case>
2883 static void setupCallExpectations(DisplayTransactionTest* test) {
2884 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2885 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002886 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002887 Case::setupRepaintEverythingCallExpectations(test);
2888 }
2889
2890 static void verifyPostconditions(DisplayTransactionTest* test) {
2891 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2892 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2893 }
2894};
2895
2896struct TransitionOffToDozeSuspendVariant
2897 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
2898 template <typename Case>
2899 static void setupCallExpectations(DisplayTransactionTest* test) {
2900 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2901 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2902 Case::setupRepaintEverythingCallExpectations(test);
2903 }
2904
2905 static void verifyPostconditions(DisplayTransactionTest* test) {
2906 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2907 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2908 }
2909};
2910
2911struct TransitionOnToOffVariant
2912 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
2913 template <typename Case>
2914 static void setupCallExpectations(DisplayTransactionTest* test) {
2915 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002916 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002917 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2918 }
2919
2920 static void verifyPostconditions(DisplayTransactionTest* test) {
2921 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2922 }
2923};
2924
2925struct TransitionDozeSuspendToOffVariant
2926 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
2927 template <typename Case>
2928 static void setupCallExpectations(DisplayTransactionTest* test) {
2929 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2930 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2931 }
2932
2933 static void verifyPostconditions(DisplayTransactionTest* test) {
2934 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2935 }
2936};
2937
2938struct TransitionOnToDozeVariant
2939 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
2940 template <typename Case>
2941 static void setupCallExpectations(DisplayTransactionTest* test) {
2942 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2943 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2944 }
2945};
2946
2947struct TransitionDozeSuspendToDozeVariant
2948 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
2949 template <typename Case>
2950 static void setupCallExpectations(DisplayTransactionTest* test) {
2951 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002952 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002953 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2954 }
2955};
2956
2957struct TransitionDozeToOnVariant
2958 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
2959 template <typename Case>
2960 static void setupCallExpectations(DisplayTransactionTest* test) {
2961 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2962 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2963 }
2964};
2965
2966struct TransitionDozeSuspendToOnVariant
2967 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
2968 template <typename Case>
2969 static void setupCallExpectations(DisplayTransactionTest* test) {
2970 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002971 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002972 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2973 }
2974};
2975
2976struct TransitionOnToDozeSuspendVariant
2977 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
2978 template <typename Case>
2979 static void setupCallExpectations(DisplayTransactionTest* test) {
2980 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002981 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002982 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2983 }
2984};
2985
2986struct TransitionOnToUnknownVariant
2987 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
2988 template <typename Case>
2989 static void setupCallExpectations(DisplayTransactionTest* test) {
2990 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2991 Case::setupNoComposerPowerModeCallExpectations(test);
2992 }
2993};
2994
2995// --------------------------------------------------------------------
2996// Note:
2997//
2998// Rather than testing the cartesian product of of
2999// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3000// display type, and the other for another display type.
3001// --------------------------------------------------------------------
3002
3003template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003004 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003005struct DisplayPowerCase {
3006 using Display = DisplayVariant;
3007 using Doze = DozeVariant;
3008 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003009 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003010 using Transition = TransitionVariant;
3011
3012 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003013 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003014 auto display = Display::makeFakeExistingDisplayInjector(test);
3015 display.inject();
3016 display.mutableDisplayDevice()->setPowerMode(mode);
3017 return display;
3018 }
3019
3020 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Ana Krulecafb45842019-02-13 13:33:03 -08003021 test->mScheduler->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003022 }
3023
3024 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3025 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3026 }
3027
3028 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3029 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3030 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3031 }
3032
3033 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3034 IComposerClient::PowerMode mode) {
3035 // Any calls to get the active config will return a default value.
3036 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3037 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3038 Return(Error::NONE)));
3039
3040 // Any calls to get whether the display supports dozing will return the value set by the
3041 // policy variant.
3042 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3043 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3044
3045 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3046 }
3047
3048 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3049 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3050 }
3051};
3052
3053// A sample configuration for the primary display.
3054// In addition to having event thread support, we emulate doze support.
3055template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003056using PrimaryDisplayPowerCase =
3057 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3058 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3059 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003060
3061// A sample configuration for the external display.
3062// In addition to not having event thread support, we emulate not having doze
3063// support.
3064template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003065using ExternalDisplayPowerCase =
3066 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3067 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3068 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003069
3070class SetPowerModeInternalTest : public DisplayTransactionTest {
3071public:
3072 template <typename Case>
3073 void transitionDisplayCommon();
3074};
3075
3076template <int PowerMode>
3077struct PowerModeInitialVSyncEnabled : public std::false_type {};
3078
3079template <>
3080struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3081
3082template <>
3083struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3084
3085template <typename Case>
3086void SetPowerModeInternalTest::transitionDisplayCommon() {
3087 // --------------------------------------------------------------------
3088 // Preconditions
3089
Peiyong Lined531a32018-10-26 18:27:56 -07003090 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003091 auto display =
3092 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3093 Case::setInitialPrimaryHWVsyncEnabled(this,
3094 PowerModeInitialVSyncEnabled<
3095 Case::Transition::INITIAL_POWER_MODE>::value);
3096
3097 // --------------------------------------------------------------------
3098 // Call Expectations
3099
3100 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3101 Case::Transition::template setupCallExpectations<Case>(this);
3102
3103 // --------------------------------------------------------------------
3104 // Invocation
3105
3106 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3107 Case::Transition::TARGET_POWER_MODE);
3108
3109 // --------------------------------------------------------------------
3110 // Postconditions
3111
3112 Case::Transition::verifyPostconditions(this);
3113}
3114
3115TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3116 using Case = SimplePrimaryDisplayCase;
3117
3118 // --------------------------------------------------------------------
3119 // Preconditions
3120
3121 // A primary display device is set up
3122 Case::Display::injectHwcDisplay(this);
3123 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3124 display.inject();
3125
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003126 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003127 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3128
3129 // --------------------------------------------------------------------
3130 // Invocation
3131
3132 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3133
3134 // --------------------------------------------------------------------
3135 // Postconditions
3136
3137 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3138}
3139
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003140TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003141 using Case = HwcVirtualDisplayCase;
3142
3143 // --------------------------------------------------------------------
3144 // Preconditions
3145
Dominik Laskowski075d3172018-05-24 15:50:06 -07003146 // Insert display data so that the HWC thinks it created the virtual display.
3147 const auto displayId = Case::Display::DISPLAY_ID::get();
3148 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003149 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003150
3151 // A virtual display device is set up
3152 Case::Display::injectHwcDisplay(this);
3153 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3154 display.inject();
3155
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003156 // The display is set to HWC_POWER_MODE_NORMAL
3157 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003158
3159 // --------------------------------------------------------------------
3160 // Invocation
3161
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003162 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003163
3164 // --------------------------------------------------------------------
3165 // Postconditions
3166
3167 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3168}
3169
3170TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3171 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3172}
3173
3174TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3175 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3176}
3177
3178TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3179 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3180}
3181
3182TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3183 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3184}
3185
3186TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3187 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3188}
3189
3190TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3191 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3192}
3193
3194TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3195 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3196}
3197
3198TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3199 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3200}
3201
3202TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3203 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3204}
3205
3206TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3207 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3208}
3209
3210TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3211 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3212}
3213
3214TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3215 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3216}
3217
3218TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3219 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3220}
3221
3222TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3223 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3224}
3225
3226TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3227 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3228}
3229
3230TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3231 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3232}
3233
3234TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3235 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3236}
3237
3238TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3239 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3240}
3241
3242TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3243 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3244}
3245
3246TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3247 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3248}
3249
Lloyd Piquef58625d2017-12-19 13:22:33 -08003250} // namespace
3251} // namespace android