blob: 97f9e6abc5a47921a0830c47a4fd019e7dbda7d8 [file] [log] [blame]
Lloyd Piquef58625d2017-12-19 13:22:33 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#undef LOG_TAG
18#define LOG_TAG "LibSurfaceFlingerUnittests"
19
Dominik Laskowski075d3172018-05-24 15:50:06 -070020#include <type_traits>
21
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070022#include <compositionengine/Display.h>
23#include <compositionengine/DisplayColorProfile.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070024#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080025#include <gmock/gmock.h>
26#include <gtest/gtest.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080027#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070028#include <renderengine/mock/RenderEngine.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070029#include <ui/DebugUtils.h>
Dominik Laskowski075d3172018-05-24 15:50:06 -070030
31#include "DisplayIdentificationTest.h"
Ana Krulecafb45842019-02-13 13:33:03 -080032#include "TestableScheduler.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080033#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080034#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070035#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080036#include "mock/MockEventControlThread.h"
37#include "mock/MockEventThread.h"
38#include "mock/MockMessageQueue.h"
39#include "mock/MockNativeWindowSurface.h"
40#include "mock/MockSurfaceInterceptor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080041#include "mock/gui/MockGraphicBufferConsumer.h"
42#include "mock/gui/MockGraphicBufferProducer.h"
43#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080044
45namespace android {
46namespace {
47
Lloyd Piquee39cad22017-12-20 17:01:29 -080048using testing::_;
Lloyd Piquee39cad22017-12-20 17:01:29 -080049using testing::DoAll;
50using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080051using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080052using testing::Return;
53using testing::SetArgPointee;
54
Lloyd Piqued883d5a2018-04-27 19:32:30 -070055using android::Hwc2::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080056using android::Hwc2::Error;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070057using android::Hwc2::Hdr;
Lloyd Piquee39cad22017-12-20 17:01:29 -080058using android::Hwc2::IComposer;
59using android::Hwc2::IComposerClient;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070060using android::Hwc2::PerFrameMetadataKey;
61using android::Hwc2::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080062
Lloyd Piquec11e0d32018-01-22 18:44:59 -080063using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
64using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080065using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080066using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080067
Lloyd Piquec11e0d32018-01-22 18:44:59 -080068constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080069constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080070constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080071
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080072constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value
73
Lloyd Piquec11e0d32018-01-22 18:44:59 -080074/* ------------------------------------------------------------------------
75 * Boolean avoidance
76 *
77 * To make calls and template instantiations more readable, we define some
78 * local enums along with an implicit bool conversion.
79 */
80
81#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
82
Lloyd Piquec11e0d32018-01-22 18:44:59 -080083BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -070084BOOL_SUBSTITUTE(Critical);
85BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080086BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -070087BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080088
89/* ------------------------------------------------------------------------
90 *
91 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080092
Lloyd Piquef58625d2017-12-19 13:22:33 -080093class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -080094public:
Lloyd Piquef58625d2017-12-19 13:22:33 -080095 DisplayTransactionTest();
96 ~DisplayTransactionTest() override;
97
Ana Krulecafb45842019-02-13 13:33:03 -080098 void setupScheduler();
99
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800100 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800101 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800102
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800103 void injectMockComposer(int virtualDisplayCount);
104 void injectFakeBufferQueueFactory();
105 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800106
107 // --------------------------------------------------------------------
108 // Postcondition helpers
109
Dominik Laskowski075d3172018-05-24 15:50:06 -0700110 bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800111 bool hasTransactionFlagSet(int flag);
112 bool hasDisplayDevice(sp<IBinder> displayToken);
113 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
114 bool hasCurrentDisplayState(sp<IBinder> displayToken);
115 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
116 bool hasDrawingDisplayState(sp<IBinder> displayToken);
117 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
118
119 // --------------------------------------------------------------------
120 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800121
Ana Krulecafb45842019-02-13 13:33:03 -0800122 TestableScheduler* mScheduler;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800123 TestableSurfaceFlinger mFlinger;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800124 mock::EventThread* mEventThread = new mock::EventThread();
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800125 mock::EventThread* mSFEventThread = new mock::EventThread();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800126 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
Alec Mouriba013fa2018-10-16 12:43:11 -0700127 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800128 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800129
130 // These mocks are created by the test, but are destroyed by SurfaceFlinger
131 // by virtue of being stored into a std::unique_ptr. However we still need
132 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700133 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800134 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800135 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
136 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Lloyd Pique41be5d22018-06-21 13:11:48 -0700137 mock::DispSync* mPrimaryDispSync = new mock::DispSync();
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800138
139 // These mocks are created only when expected to be created via a factory.
140 sp<mock::GraphicBufferConsumer> mConsumer;
141 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700142 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800143};
144
145DisplayTransactionTest::DisplayTransactionTest() {
146 const ::testing::TestInfo* const test_info =
147 ::testing::UnitTest::GetInstance()->current_test_info();
148 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800149
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800150 // Default to no wide color display support configured
151 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700152 mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800153 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
154
155 // Default to using HWC virtual displays
156 mFlinger.mutableUseHwcVirtualDisplays() = true;
157
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800158 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
159 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
160 });
161
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800162 mFlinger.setCreateNativeWindowSurface([](auto) {
163 ADD_FAILURE() << "Unexpected request to create a native window surface.";
164 return nullptr;
165 });
166
Ana Krulecafb45842019-02-13 13:33:03 -0800167 setupScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800168 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700169 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800170 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800171
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800172 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800173}
174
175DisplayTransactionTest::~DisplayTransactionTest() {
176 const ::testing::TestInfo* const test_info =
177 ::testing::UnitTest::GetInstance()->current_test_info();
178 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
179}
180
Ana Krulecafb45842019-02-13 13:33:03 -0800181void DisplayTransactionTest::setupScheduler() {
Ady Abraham09bd3922019-04-08 10:44:56 -0700182 mScheduler = new TestableScheduler(mFlinger.mutableRefreshRateConfigs());
Ana Krulecafb45842019-02-13 13:33:03 -0800183 mScheduler->mutableEventControlThread().reset(mEventControlThread);
184 mScheduler->mutablePrimaryDispSync().reset(mPrimaryDispSync);
185 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
186 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
187
188 sp<Scheduler::ConnectionHandle> sfConnectionHandle =
189 mScheduler->addConnection(std::unique_ptr<EventThread>(mSFEventThread));
190 mFlinger.mutableSfConnectionHandle() = std::move(sfConnectionHandle);
191 sp<Scheduler::ConnectionHandle> appConnectionHandle =
192 mScheduler->addConnection(std::unique_ptr<EventThread>(mEventThread));
193 mFlinger.mutableAppConnectionHandle() = std::move(appConnectionHandle);
194 mFlinger.mutableScheduler().reset(mScheduler);
195}
196
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800197void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
198 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800199 EXPECT_CALL(*mComposer, getCapabilities())
200 .WillOnce(Return(std::vector<IComposer::Capability>()));
201 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
202 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800203
Lloyd Piquee39cad22017-12-20 17:01:29 -0800204 Mock::VerifyAndClear(mComposer);
205}
206
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800207void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800208 // This setup is only expected once per test.
209 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
210
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800211 mConsumer = new mock::GraphicBufferConsumer();
212 mProducer = new mock::GraphicBufferProducer();
213
214 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
215 *outProducer = mProducer;
216 *outConsumer = mConsumer;
217 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800218}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800219
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800220void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800221 // This setup is only expected once per test.
222 ASSERT_TRUE(mNativeWindowSurface == nullptr);
223
Lloyd Pique22098362018-09-13 11:46:49 -0700224 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800225
Lloyd Pique22098362018-09-13 11:46:49 -0700226 mFlinger.setCreateNativeWindowSurface([this](auto) {
227 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
228 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800229}
230
Dominik Laskowski075d3172018-05-24 15:50:06 -0700231bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) {
232 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800233}
234
235bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
236 return mFlinger.mutableTransactionFlags() & flag;
237}
238
239bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700240 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800241}
242
243sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700244 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800245}
246
247bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
248 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
249}
250
251const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
252 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
253}
254
255bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
256 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
257}
258
259const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
260 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
261}
262
263/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800264 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800265 */
266
Dominik Laskowski075d3172018-05-24 15:50:06 -0700267template <typename PhysicalDisplay>
268struct PhysicalDisplayId {};
269
Dominik Laskowski34157762018-10-31 13:07:19 -0700270template <DisplayId::Type displayId>
271using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700272
273struct NoDisplayId {};
274
275template <typename>
276struct IsPhysicalDisplayId : std::bool_constant<false> {};
277
278template <typename PhysicalDisplay>
279struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
280
281template <typename>
282struct DisplayIdGetter;
283
284template <typename PhysicalDisplay>
285struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
286 static std::optional<DisplayId> get() {
287 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
288 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
289 ? HWC_DISPLAY_PRIMARY
290 : HWC_DISPLAY_EXTERNAL);
291 }
292
293 const auto info =
294 parseDisplayIdentificationData(PhysicalDisplay::PORT,
295 PhysicalDisplay::GET_IDENTIFICATION_DATA());
296 return info ? std::make_optional(info->id) : std::nullopt;
297 }
298};
299
Dominik Laskowski34157762018-10-31 13:07:19 -0700300template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700301struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700302 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700303};
304
305template <>
306struct DisplayIdGetter<NoDisplayId> {
307 static std::optional<DisplayId> get() { return {}; }
308};
309
310// DisplayIdType can be:
311// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
312// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
313// 3) NoDisplayId for virtual display without HWC backing.
314template <typename DisplayIdType, int width, int height, Critical critical, Async async,
315 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800316struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700317 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
318
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800319 // The display width and height
320 static constexpr int WIDTH = width;
321 static constexpr int HEIGHT = height;
322
323 static constexpr int GRALLOC_USAGE = grallocUsage;
324
Dominik Laskowski075d3172018-05-24 15:50:06 -0700325 // Whether the display is virtual or physical
326 static constexpr Virtual VIRTUAL =
327 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800328
329 // When creating native window surfaces for the framebuffer, whether those should be critical
330 static constexpr Critical CRITICAL = critical;
331
332 // When creating native window surfaces for the framebuffer, whether those should be async
333 static constexpr Async ASYNC = async;
334
335 // Whether the display should be treated as secure
336 static constexpr Secure SECURE = secure;
337
Dominik Laskowski075d3172018-05-24 15:50:06 -0700338 // Whether the display is primary
339 static constexpr Primary PRIMARY = primary;
340
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800341 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700342 auto injector =
343 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(),
344 static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY));
345
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800346 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700347 injector.setNativeWindow(test->mNativeWindow);
348
349 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800350 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700351 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
352 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
353 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
354 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800355 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
356 .WillRepeatedly(Return(0));
357 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
358 .WillRepeatedly(Return(0));
359 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
360 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700361 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
362 .WillRepeatedly(Return(0));
363
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800364 return injector;
365 }
366
367 // Called by tests to set up any native window creation call expectations.
368 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
369 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
370 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800371
Alec Mouriba013fa2018-10-16 12:43:11 -0700372 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
373 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
374 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
375 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800376 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
377 .WillRepeatedly(Return(0));
378 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
379 .WillRepeatedly(Return(0));
380 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
381 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700382 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
383 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800384 }
385
386 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
387 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
388 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
389 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
390 .WillRepeatedly(Return(NO_ERROR));
391 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
392 .WillRepeatedly(Return(NO_ERROR));
393 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
394 .WillRepeatedly(Return(NO_ERROR));
395 }
396
397 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
398 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
399 }
400};
401
Dominik Laskowski075d3172018-05-24 15:50:06 -0700402template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
403 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800404struct HwcDisplayVariant {
405 // The display id supplied by the HWC
406 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
407
408 // The HWC display type
409 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
410
411 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700412 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800413
414 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
415 HWC2::Connection connection) {
416 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
417 HotplugEvent{HWC_DISPLAY_ID, connection});
418 }
419
420 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800421 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700422 const auto displayId = DisplayVariant::DISPLAY_ID::get();
423 ASSERT_TRUE(displayId);
424 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
425 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800426 .setHwcDisplayId(HWC_DISPLAY_ID)
427 .setWidth(DisplayVariant::WIDTH)
428 .setHeight(DisplayVariant::HEIGHT)
429 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
430 .inject(&test->mFlinger, test->mComposer);
431 }
432
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800433 // Called by tests to inject a HWC display setup
434 static void injectHwcDisplay(DisplayTransactionTest* test) {
435 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
436 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
437 Return(Error::NONE)));
438 injectHwcDisplayWithNoDefaultCapabilities(test);
439 }
440
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800441 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
442 EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _))
443 .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>(
444 HWC_DISPLAY_TYPE)),
445 Return(Error::NONE)));
446 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
447 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
448 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
449 Return(Error::NONE)));
450 EXPECT_CALL(*test->mComposer,
451 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
452 IComposerClient::Attribute::WIDTH, _))
453 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
454 EXPECT_CALL(*test->mComposer,
455 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
456 IComposerClient::Attribute::HEIGHT, _))
457 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
458 EXPECT_CALL(*test->mComposer,
459 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
460 IComposerClient::Attribute::VSYNC_PERIOD, _))
461 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
462 EXPECT_CALL(*test->mComposer,
463 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
464 IComposerClient::Attribute::DPI_X, _))
465 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
466 EXPECT_CALL(*test->mComposer,
467 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
468 IComposerClient::Attribute::DPI_Y, _))
469 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800470 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
471 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
472 Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700473
474 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
475 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
476 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
477 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
478 Return(Error::NONE)));
479 } else {
480 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
481 .WillOnce(Return(Error::UNSUPPORTED));
482 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800483 }
484
485 // Called by tests to set up HWC call expectations
486 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
487 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700488 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800489 }
490};
491
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800492// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
493constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
494 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
495
Dominik Laskowski075d3172018-05-24 15:50:06 -0700496template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800497 Critical critical>
498struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700499 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
500 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
501 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
502 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
503 critical, Async::FALSE, Secure::TRUE,
504 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
505 PhysicalDisplay> {};
506
507template <bool hasIdentificationData>
508struct PrimaryDisplay {
509 static constexpr Primary PRIMARY = Primary::TRUE;
510 static constexpr uint8_t PORT = 255;
511 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
512 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
513};
514
515template <bool hasIdentificationData>
516struct ExternalDisplay {
517 static constexpr Primary PRIMARY = Primary::FALSE;
518 static constexpr uint8_t PORT = 254;
519 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
520 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
521};
522
523struct TertiaryDisplay {
524 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800525 static constexpr uint8_t PORT = 253;
526 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700527};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800528
529// A primary display is a physical display that is critical
530using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700531 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800532
533// An external display is physical display that is not critical.
534using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700535 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800536
537using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700538 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800539
540// A virtual display not supported by the HWC.
541constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
542
543template <int width, int height, Secure secure>
544struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700545 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
546 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
547 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
548 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
549
550 static void injectHwcDisplay(DisplayTransactionTest*) {}
551
552 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
553 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
554 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800555
556 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
557 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
558 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
559 }
560};
561
562// A virtual display supported by the HWC.
563constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
564
565template <int width, int height, Secure secure>
566struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700567 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
568 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
569 HwcDisplayVariant<
570 1010, HWC2::DisplayType::Virtual,
571 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
572 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
573 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
574 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800575 using Self = HwcVirtualDisplayVariant<width, height, secure>;
576
577 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
578 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
579 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
580 }
581
582 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
583 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
584 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
585 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
586 }
587};
588
589// For this variant, SurfaceFlinger should not configure itself with wide
590// display support, so the display should not be configured for wide-color
591// support.
592struct WideColorSupportNotConfiguredVariant {
593 static constexpr bool WIDE_COLOR_SUPPORTED = false;
594
595 static void injectConfigChange(DisplayTransactionTest* test) {
596 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700597 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800598 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
599 }
600
601 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
602 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
603 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
604 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
605 }
606};
607
608// For this variant, SurfaceFlinger should configure itself with wide display
609// support, and the display should respond with an non-empty list of supported
610// color modes. Wide-color support should be configured.
611template <typename Display>
612struct WideColorP3ColorimetricSupportedVariant {
613 static constexpr bool WIDE_COLOR_SUPPORTED = true;
614
615 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700616 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800617 test->mFlinger.mutableHasWideColorDisplay() = true;
618 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
619 }
620
621 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800622 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
623
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800624 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
625 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
626 Return(Error::NONE)));
627 EXPECT_CALL(*test->mComposer,
628 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
629 .WillOnce(DoAll(SetArgPointee<2>(
630 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
631 Return(Error::NONE)));
632 EXPECT_CALL(*test->mComposer,
633 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
634 RenderIntent::COLORIMETRIC))
635 .WillOnce(Return(Error::NONE));
636 }
637};
638
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800639// For this variant, SurfaceFlinger should configure itself with wide display
640// support, but the display should respond with an empty list of supported color
641// modes. Wide-color support for the display should not be configured.
642template <typename Display>
643struct WideColorNotSupportedVariant {
644 static constexpr bool WIDE_COLOR_SUPPORTED = false;
645
646 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700647 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800648 test->mFlinger.mutableHasWideColorDisplay() = true;
649 }
650
651 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
652 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
653 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700654 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800655 }
656};
657
658// For this variant, the display is not a HWC display, so no HDR support should
659// be configured.
660struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800661 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800662 static constexpr bool HDR10_SUPPORTED = false;
663 static constexpr bool HDR_HLG_SUPPORTED = false;
664 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
665 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
666 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
667 }
668};
669
Valerie Haue9e843a2018-12-18 13:39:23 -0800670template <typename Display>
671struct Hdr10PlusSupportedVariant {
672 static constexpr bool HDR10_PLUS_SUPPORTED = true;
673 static constexpr bool HDR10_SUPPORTED = true;
674 static constexpr bool HDR_HLG_SUPPORTED = false;
675 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
676 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
677 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
678 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
679 Hdr::HDR10_PLUS,
680 Hdr::HDR10,
681 })),
682 Return(Error::NONE)));
683 }
684};
685
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800686// For this variant, the composer should respond with a non-empty list of HDR
687// modes containing HDR10, so HDR10 support should be configured.
688template <typename Display>
689struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800690 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800691 static constexpr bool HDR10_SUPPORTED = true;
692 static constexpr bool HDR_HLG_SUPPORTED = false;
693 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
694 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
695 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
696 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
697 Return(Error::NONE)));
698 }
699};
700
701// For this variant, the composer should respond with a non-empty list of HDR
702// modes containing HLG, so HLG support should be configured.
703template <typename Display>
704struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800705 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800706 static constexpr bool HDR10_SUPPORTED = false;
707 static constexpr bool HDR_HLG_SUPPORTED = true;
708 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
709 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
710 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
711 .WillOnce(
712 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
713 }
714};
715
716// For this variant, the composer should respond with a non-empty list of HDR
717// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
718template <typename Display>
719struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800720 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800721 static constexpr bool HDR10_SUPPORTED = false;
722 static constexpr bool HDR_HLG_SUPPORTED = false;
723 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
724 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
725 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
726 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
727 Return(Error::NONE)));
728 }
729};
730
731// For this variant, the composer should respond with am empty list of HDR
732// modes, so no HDR support should be configured.
733template <typename Display>
734struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800735 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800736 static constexpr bool HDR10_SUPPORTED = false;
737 static constexpr bool HDR_HLG_SUPPORTED = false;
738 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
739 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
740 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
741 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
742 }
743};
744
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700745struct NonHwcPerFrameMetadataSupportVariant {
746 static constexpr int PER_FRAME_METADATA_KEYS = 0;
747 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800748 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700749 }
750};
751
752template <typename Display>
753struct NoPerFrameMetadataSupportVariant {
754 static constexpr int PER_FRAME_METADATA_KEYS = 0;
755 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800756 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
757 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700758 }
759};
760
761template <typename Display>
762struct Smpte2086PerFrameMetadataSupportVariant {
763 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
764 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800765 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
766 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800767 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
768 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
769 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
770 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
771 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
772 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
773 PerFrameMetadataKey::WHITE_POINT_X,
774 PerFrameMetadataKey::WHITE_POINT_Y,
775 PerFrameMetadataKey::MAX_LUMINANCE,
776 PerFrameMetadataKey::MIN_LUMINANCE,
777 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700778 }
779};
780
781template <typename Display>
782struct Cta861_3_PerFrameMetadataSupportVariant {
783 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
784 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800785 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
786 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800787 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
788 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
789 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700790 }
791};
792
Valerie Haue9e843a2018-12-18 13:39:23 -0800793template <typename Display>
794struct Hdr10_Plus_PerFrameMetadataSupportVariant {
795 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
796 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
797 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
798 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
799 PerFrameMetadataKey::HDR10_PLUS_SEI,
800 })));
801 }
802};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800803/* ------------------------------------------------------------------------
804 * Typical display configurations to test
805 */
806
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700807template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
808 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800809struct Case {
810 using Display = DisplayPolicy;
811 using WideColorSupport = WideColorSupportPolicy;
812 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700813 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800814};
815
816using SimplePrimaryDisplayCase =
817 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700818 HdrNotSupportedVariant<PrimaryDisplayVariant>,
819 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800820using SimpleExternalDisplayCase =
821 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700822 HdrNotSupportedVariant<ExternalDisplayVariant>,
823 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800824using SimpleTertiaryDisplayCase =
825 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700826 HdrNotSupportedVariant<TertiaryDisplayVariant>,
827 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800828using NonHwcVirtualDisplayCase =
829 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700830 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
831 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800832using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
833using HwcVirtualDisplayCase =
834 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700835 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800836 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800837using WideColorP3ColorimetricDisplayCase =
838 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700839 HdrNotSupportedVariant<PrimaryDisplayVariant>,
840 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800841using Hdr10PlusDisplayCase =
842 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
843 Hdr10SupportedVariant<PrimaryDisplayVariant>,
844 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800845using Hdr10DisplayCase =
846 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700847 Hdr10SupportedVariant<PrimaryDisplayVariant>,
848 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800849using HdrHlgDisplayCase =
850 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700851 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
852 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800853using HdrDolbyVisionDisplayCase =
854 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700855 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
856 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
857using HdrSmpte2086DisplayCase =
858 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
859 HdrNotSupportedVariant<PrimaryDisplayVariant>,
860 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
861using HdrCta861_3_DisplayCase =
862 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
863 HdrNotSupportedVariant<PrimaryDisplayVariant>,
864 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700865
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800866/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800867 *
868 * SurfaceFlinger::onHotplugReceived
869 */
870
871TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
872 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700873 constexpr hwc2_display_t hwcDisplayId1 = 456;
874 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800875
876 // --------------------------------------------------------------------
877 // Preconditions
878
879 // Set the current sequence id for accepted events
880 mFlinger.mutableComposerSequenceId() = currentSequenceId;
881
882 // Set the main thread id so that the current thread does not appear to be
883 // the main thread.
884 mFlinger.mutableMainThreadId() = std::thread::id();
885
886 // --------------------------------------------------------------------
887 // Call Expectations
888
889 // We expect invalidate() to be invoked once to trigger display transaction
890 // processing.
891 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
892
893 // --------------------------------------------------------------------
894 // Invocation
895
896 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700897 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
898 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800899
900 // --------------------------------------------------------------------
901 // Postconditions
902
903 // The display transaction needed flag should be set.
904 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
905
906 // All events should be in the pending event queue.
907 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
908 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700909 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800910 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700911 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800912 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
913}
914
915TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
916 constexpr int currentSequenceId = 123;
917 constexpr int otherSequenceId = 321;
918 constexpr hwc2_display_t displayId = 456;
919
920 // --------------------------------------------------------------------
921 // Preconditions
922
923 // Set the current sequence id for accepted events
924 mFlinger.mutableComposerSequenceId() = currentSequenceId;
925
926 // Set the main thread id so that the current thread does not appear to be
927 // the main thread.
928 mFlinger.mutableMainThreadId() = std::thread::id();
929
930 // --------------------------------------------------------------------
931 // Call Expectations
932
933 // We do not expect any calls to invalidate().
934 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
935
936 // --------------------------------------------------------------------
937 // Invocation
938
939 // Call with an unexpected sequence id
940 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
941
942 // --------------------------------------------------------------------
943 // Postconditions
944
945 // The display transaction needed flag should not be set
946 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
947
948 // There should be no pending events
949 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
950}
951
952TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
953 constexpr int currentSequenceId = 123;
954 constexpr hwc2_display_t displayId1 = 456;
955
956 // --------------------------------------------------------------------
957 // Note:
958 // --------------------------------------------------------------------
959 // This test case is a bit tricky. We want to verify that
960 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
961 // don't really want to provide coverage for everything the later function
962 // does as there are specific tests for it.
963 // --------------------------------------------------------------------
964
965 // --------------------------------------------------------------------
966 // Preconditions
967
968 // Set the current sequence id for accepted events
969 mFlinger.mutableComposerSequenceId() = currentSequenceId;
970
971 // Set the main thread id so that the current thread does appear to be the
972 // main thread.
973 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
974
975 // --------------------------------------------------------------------
976 // Call Expectations
977
978 // We expect invalidate() to be invoked once to trigger display transaction
979 // processing.
980 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
981
982 // --------------------------------------------------------------------
983 // Invocation
984
985 // Simulate a disconnect on a display id that is not connected. This should
986 // be enqueued by onHotplugReceived(), and dequeued by
987 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
988 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
989
990 // --------------------------------------------------------------------
991 // Postconditions
992
993 // The display transaction needed flag should be set.
994 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
995
996 // There should be no event queued on return, as it should have been
997 // processed.
998 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
999}
1000
1001/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001002 * SurfaceFlinger::createDisplay
1003 */
1004
1005TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1006 const String8 name("virtual.test");
1007
1008 // --------------------------------------------------------------------
1009 // Call Expectations
1010
1011 // The call should notify the interceptor that a display was created.
1012 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1013
1014 // --------------------------------------------------------------------
1015 // Invocation
1016
1017 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1018
1019 // --------------------------------------------------------------------
1020 // Postconditions
1021
1022 // The display should have been added to the current state
1023 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1024 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001025 EXPECT_TRUE(display.isVirtual());
1026 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001027 EXPECT_EQ(name.string(), display.displayName);
1028
1029 // --------------------------------------------------------------------
1030 // Cleanup conditions
1031
1032 // Destroying the display invalidates the display state.
1033 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1034}
1035
1036TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1037 const String8 name("virtual.test");
1038
1039 // --------------------------------------------------------------------
1040 // Call Expectations
1041
1042 // The call should notify the interceptor that a display was created.
1043 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1044
1045 // --------------------------------------------------------------------
1046 // Invocation
1047
1048 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1049
1050 // --------------------------------------------------------------------
1051 // Postconditions
1052
1053 // The display should have been added to the current state
1054 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1055 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001056 EXPECT_TRUE(display.isVirtual());
1057 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001058 EXPECT_EQ(name.string(), display.displayName);
1059
1060 // --------------------------------------------------------------------
1061 // Cleanup conditions
1062
1063 // Destroying the display invalidates the display state.
1064 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1065}
1066
1067/* ------------------------------------------------------------------------
1068 * SurfaceFlinger::destroyDisplay
1069 */
1070
1071TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1072 using Case = NonHwcVirtualDisplayCase;
1073
1074 // --------------------------------------------------------------------
1075 // Preconditions
1076
1077 // A virtual display exists
1078 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1079 existing.inject();
1080
1081 // --------------------------------------------------------------------
1082 // Call Expectations
1083
1084 // The call should notify the interceptor that a display was created.
1085 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1086
1087 // Destroying the display invalidates the display state.
1088 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1089
1090 // --------------------------------------------------------------------
1091 // Invocation
1092
1093 mFlinger.destroyDisplay(existing.token());
1094
1095 // --------------------------------------------------------------------
1096 // Postconditions
1097
1098 // The display should have been removed from the current state
1099 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1100
1101 // Ths display should still exist in the drawing state
1102 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1103
1104 // The display transaction needed flasg should be set
1105 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1106}
1107
1108TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1109 // --------------------------------------------------------------------
1110 // Preconditions
1111
1112 sp<BBinder> displayToken = new BBinder();
1113
1114 // --------------------------------------------------------------------
1115 // Invocation
1116
1117 mFlinger.destroyDisplay(displayToken);
1118}
1119
1120/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001121 * SurfaceFlinger::resetDisplayState
1122 */
1123
1124TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1125 using Case = NonHwcVirtualDisplayCase;
1126
1127 // --------------------------------------------------------------------
1128 // Preconditions
1129
1130 // vsync is enabled and available
Ana Krulecafb45842019-02-13 13:33:03 -08001131 mScheduler->mutablePrimaryHWVsyncEnabled() = true;
1132 mScheduler->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001133
1134 // A display exists
1135 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1136 existing.inject();
1137
1138 // --------------------------------------------------------------------
1139 // Call Expectations
1140
1141 // The call disable vsyncs
1142 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1143
Lloyd Pique41be5d22018-06-21 13:11:48 -07001144 // The call ends any display resyncs
1145 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1146
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001147 // --------------------------------------------------------------------
1148 // Invocation
1149
1150 mFlinger.resetDisplayState();
1151
1152 // --------------------------------------------------------------------
1153 // Postconditions
1154
1155 // vsyncs should be off and not available.
Ana Krulecafb45842019-02-13 13:33:03 -08001156 EXPECT_FALSE(mScheduler->mutablePrimaryHWVsyncEnabled());
1157 EXPECT_FALSE(mScheduler->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001158
1159 // The display should have been removed from the display map.
1160 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1161
1162 // The display should still exist in the current state
1163 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1164
1165 // The display should have been removed from the drawing state
1166 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1167}
1168
1169/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001170 * DisplayDevice::GetBestColorMode
1171 */
1172class GetBestColorModeTest : public DisplayTransactionTest {
1173public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001174 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001175
Valerie Hau9758ae02018-10-09 16:05:09 -07001176 GetBestColorModeTest()
1177 : DisplayTransactionTest(),
Dominik Laskowski075d3172018-05-24 15:50:06 -07001178 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */,
1179 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001180
1181 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1182
1183 void addHwcColorModesMapping(ui::ColorMode colorMode,
1184 std::vector<ui::RenderIntent> renderIntents) {
1185 mHwcColorModes[colorMode] = renderIntents;
1186 }
1187
1188 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1189
1190 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1191
1192 void getBestColorMode() {
1193 mInjector.setHwcColorModes(mHwcColorModes);
1194 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001195 mInjector.setNativeWindow(mNativeWindow);
1196
1197 // Creating a DisplayDevice requires getting default dimensions from the
1198 // native window.
1199 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1200 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1201 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1202 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001203 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1204 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1205 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07001206 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001207 auto displayDevice = mInjector.inject();
1208
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001209 displayDevice->getCompositionDisplay()
1210 ->getDisplayColorProfile()
1211 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1212 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001213 }
1214
1215 ui::Dataspace mOutDataspace;
1216 ui::ColorMode mOutColorMode;
1217 ui::RenderIntent mOutRenderIntent;
1218
1219private:
1220 ui::Dataspace mInputDataspace;
1221 ui::RenderIntent mInputRenderIntent;
1222 bool mHasWideColorGamut = false;
1223 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1224 FakeDisplayDeviceInjector mInjector;
1225};
1226
1227TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1228 addHwcColorModesMapping(ui::ColorMode::SRGB,
1229 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1230 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1231 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1232 setHasWideColorGamut(true);
1233
1234 getBestColorMode();
1235
Peiyong Lin14724e62018-12-05 07:27:30 -08001236 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001237 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1238 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1239}
1240
1241TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1242 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1243 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1244 addHwcColorModesMapping(ui::ColorMode::SRGB,
1245 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1246 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1247 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1248 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1249 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1250 setHasWideColorGamut(true);
1251
1252 getBestColorMode();
1253
1254 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1255 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1256 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1257}
1258
1259TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1260 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1261 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1262 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1263 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1264 setHasWideColorGamut(true);
1265
1266 getBestColorMode();
1267
1268 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1269 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1270 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1271}
1272
1273/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001274 * SurfaceFlinger::getDisplayNativePrimaries
1275 */
1276
1277class GetDisplayNativePrimaries : public DisplayTransactionTest {
1278public:
1279 GetDisplayNativePrimaries();
1280 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1281 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1282
1283private:
1284 static constexpr float mStartingTestValue = 1.0f;
1285};
1286
1287GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1288 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1289 injectFakeNativeWindowSurfaceFactory();
1290}
1291
1292void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1293 ui::DisplayPrimaries& primaries) {
1294 float startingVal = mStartingTestValue;
1295 primaries.red.X = startingVal++;
1296 primaries.red.Y = startingVal++;
1297 primaries.red.Z = startingVal++;
1298 primaries.green.X = startingVal++;
1299 primaries.green.Y = startingVal++;
1300 primaries.green.Z = startingVal++;
1301 primaries.blue.X = startingVal++;
1302 primaries.blue.Y = startingVal++;
1303 primaries.blue.Z = startingVal++;
1304 primaries.white.X = startingVal++;
1305 primaries.white.Y = startingVal++;
1306 primaries.white.Z = startingVal++;
1307}
1308
1309void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1310 const ui::DisplayPrimaries& primaries) {
1311 float startingVal = mStartingTestValue;
1312 EXPECT_EQ(primaries.red.X, startingVal++);
1313 EXPECT_EQ(primaries.red.Y, startingVal++);
1314 EXPECT_EQ(primaries.red.Z, startingVal++);
1315 EXPECT_EQ(primaries.green.X, startingVal++);
1316 EXPECT_EQ(primaries.green.Y, startingVal++);
1317 EXPECT_EQ(primaries.green.Z, startingVal++);
1318 EXPECT_EQ(primaries.blue.X, startingVal++);
1319 EXPECT_EQ(primaries.blue.Y, startingVal++);
1320 EXPECT_EQ(primaries.blue.Z, startingVal++);
1321 EXPECT_EQ(primaries.white.X, startingVal++);
1322 EXPECT_EQ(primaries.white.Y, startingVal++);
1323 EXPECT_EQ(primaries.white.Z, startingVal++);
1324}
1325
1326TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1327 ui::DisplayPrimaries primaries;
1328 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1329}
1330
Daniel Solomon42d04562019-01-20 21:03:19 -08001331TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1332 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1333 injector.inject();
1334 auto internalDisplayToken = injector.token();
1335
1336 ui::DisplayPrimaries expectedPrimaries;
1337 populateDummyDisplayNativePrimaries(expectedPrimaries);
1338 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1339
1340 ui::DisplayPrimaries primaries;
1341 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1342
1343 checkDummyDisplayNativePrimaries(primaries);
1344}
1345
1346TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1347 sp<BBinder> notInternalDisplayToken = new BBinder();
1348
1349 ui::DisplayPrimaries primaries;
1350 populateDummyDisplayNativePrimaries(primaries);
1351 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1352
1353 // Check primaries argument wasn't modified in case of failure
1354 checkDummyDisplayNativePrimaries(primaries);
1355}
1356
1357/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001358 * SurfaceFlinger::setupNewDisplayDeviceInternal
1359 */
1360
1361class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1362public:
1363 template <typename T>
1364 void setupNewDisplayDeviceInternalTest();
1365};
1366
1367template <typename Case>
1368void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1369 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001370 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1371 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001372 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001373
1374 // --------------------------------------------------------------------
1375 // Preconditions
1376
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001377 // Wide color displays support is configured appropriately
1378 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001379
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001380 // The display is setup with the HWC.
1381 Case::Display::injectHwcDisplay(this);
1382
1383 // SurfaceFlinger will use a test-controlled factory for native window
1384 // surfaces.
1385 injectFakeNativeWindowSurfaceFactory();
1386
1387 // --------------------------------------------------------------------
1388 // Call Expectations
1389
1390 // Various native window calls will be made.
1391 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001392 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001393 Case::WideColorSupport::setupComposerCallExpectations(this);
1394 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001395 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001396
1397 // --------------------------------------------------------------------
1398 // Invocation
1399
1400 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001401 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1402 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001403 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1404
Dominik Laskowski075d3172018-05-24 15:50:06 -07001405 auto device =
1406 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1407 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001408
1409 // --------------------------------------------------------------------
1410 // Postconditions
1411
1412 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001413 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1414 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001415 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001416 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001417 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1418 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1419 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001420 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001421 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1422 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1423 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001424 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1425 // remapped, and the test only ever sets up one config. If there were an error
1426 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
1427 EXPECT_EQ(0, device->getActiveConfig());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001428 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1429 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001430}
1431
1432TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1433 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1434}
1435
1436TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1437 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1438}
1439
1440TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1441 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1442}
1443
1444TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001445 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001446
Dominik Laskowski075d3172018-05-24 15:50:06 -07001447 // Insert display data so that the HWC thinks it created the virtual display.
1448 const auto displayId = Case::Display::DISPLAY_ID::get();
1449 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001450 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001451
1452 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001453}
1454
1455TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1456 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1457}
1458
Valerie Haue9e843a2018-12-18 13:39:23 -08001459TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1460 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1461}
1462
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001463TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1464 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1465}
1466
1467TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1468 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1469}
1470
1471TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1472 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1473}
1474
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001475TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1476 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1477}
1478
1479TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1480 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1481}
1482
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001483/* ------------------------------------------------------------------------
1484 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1485 */
1486
1487class HandleTransactionLockedTest : public DisplayTransactionTest {
1488public:
1489 template <typename Case>
1490 void setupCommonPreconditions();
1491
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001492 template <typename Case, bool connected>
1493 static void expectHotplugReceived(mock::EventThread*);
1494
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001495 template <typename Case>
1496 void setupCommonCallExpectationsForConnectProcessing();
1497
1498 template <typename Case>
1499 void setupCommonCallExpectationsForDisconnectProcessing();
1500
1501 template <typename Case>
1502 void processesHotplugConnectCommon();
1503
1504 template <typename Case>
1505 void ignoresHotplugConnectCommon();
1506
1507 template <typename Case>
1508 void processesHotplugDisconnectCommon();
1509
1510 template <typename Case>
1511 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1512
1513 template <typename Case>
1514 void verifyPhysicalDisplayIsConnected();
1515
1516 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1517};
1518
1519template <typename Case>
1520void HandleTransactionLockedTest::setupCommonPreconditions() {
1521 // Wide color displays support is configured appropriately
1522 Case::WideColorSupport::injectConfigChange(this);
1523
1524 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1525 injectFakeBufferQueueFactory();
1526
1527 // SurfaceFlinger will use a test-controlled factory for native window
1528 // surfaces.
1529 injectFakeNativeWindowSurfaceFactory();
1530}
1531
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001532template <typename Case, bool connected>
1533void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1534 const auto convert = [](auto physicalDisplayId) {
1535 return std::make_optional(DisplayId{physicalDisplayId});
1536 };
1537
1538 EXPECT_CALL(*eventThread,
1539 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1540 .Times(1);
1541}
1542
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001543template <typename Case>
1544void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1545 Case::Display::setupHwcHotplugCallExpectations(this);
1546
1547 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1548 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1549 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1550 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1551
1552 Case::WideColorSupport::setupComposerCallExpectations(this);
1553 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001554 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001555
1556 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001557 expectHotplugReceived<Case, true>(mEventThread);
1558 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001559}
1560
1561template <typename Case>
1562void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1563 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001564
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001565 expectHotplugReceived<Case, false>(mEventThread);
1566 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001567}
1568
1569template <typename Case>
1570void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1571 // The display device should have been set up in the list of displays.
1572 ASSERT_TRUE(hasDisplayDevice(displayToken));
1573 const auto& device = getDisplayDevice(displayToken);
1574 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001575 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001576
1577 // The display should have been set up in the current display state
1578 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1579 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001580 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1581 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1582 : Case::Display::DISPLAY_ID::get(),
1583 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001584
1585 // The display should have been set up in the drawing display state
1586 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1587 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001588 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1589 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1590 : Case::Display::DISPLAY_ID::get(),
1591 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001592}
1593
1594template <typename Case>
1595void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1596 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001597 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001598
Dominik Laskowski075d3172018-05-24 15:50:06 -07001599 // SF should have a display token.
1600 const auto displayId = Case::Display::DISPLAY_ID::get();
1601 ASSERT_TRUE(displayId);
1602 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1603 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001604
1605 verifyDisplayIsConnected<Case>(displayToken);
1606}
1607
1608void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1609 EXPECT_FALSE(hasDisplayDevice(displayToken));
1610 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1611 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1612}
1613
1614template <typename Case>
1615void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1616 // --------------------------------------------------------------------
1617 // Preconditions
1618
1619 setupCommonPreconditions<Case>();
1620
1621 // A hotplug connect event is enqueued for a display
1622 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001623
1624 // --------------------------------------------------------------------
1625 // Call Expectations
1626
1627 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001628
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001629 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001630
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001631 // --------------------------------------------------------------------
1632 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001633
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001634 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001635
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001636 // --------------------------------------------------------------------
1637 // Postconditions
1638
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001639 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001640
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001641 // --------------------------------------------------------------------
1642 // Cleanup conditions
1643
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001644 EXPECT_CALL(*mComposer,
1645 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001646 .WillOnce(Return(Error::NONE));
1647 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001648}
1649
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001650template <typename Case>
1651void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1652 // --------------------------------------------------------------------
1653 // Preconditions
1654
1655 setupCommonPreconditions<Case>();
1656
1657 // A hotplug connect event is enqueued for a display
1658 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1659
1660 // --------------------------------------------------------------------
1661 // Invocation
1662
1663 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1664
1665 // --------------------------------------------------------------------
1666 // Postconditions
1667
1668 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001669 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001670}
1671
1672template <typename Case>
1673void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1674 // --------------------------------------------------------------------
1675 // Preconditions
1676
1677 setupCommonPreconditions<Case>();
1678
1679 // A hotplug disconnect event is enqueued for a display
1680 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1681
1682 // The display is already completely set up.
1683 Case::Display::injectHwcDisplay(this);
1684 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1685 existing.inject();
1686
1687 // --------------------------------------------------------------------
1688 // Call Expectations
1689
1690 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001691 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1692 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001693
1694 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1695
1696 // --------------------------------------------------------------------
1697 // Invocation
1698
1699 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1700
1701 // --------------------------------------------------------------------
1702 // Postconditions
1703
1704 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001705 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001706
Dominik Laskowski075d3172018-05-24 15:50:06 -07001707 // SF should not have a display token.
1708 const auto displayId = Case::Display::DISPLAY_ID::get();
1709 ASSERT_TRUE(displayId);
1710 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001711
1712 // The existing token should have been removed
1713 verifyDisplayIsNotConnected(existing.token());
1714}
1715
1716TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1717 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1718}
1719
1720TEST_F(HandleTransactionLockedTest,
1721 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1722 // Inject an external display.
1723 ExternalDisplayVariant::injectHwcDisplay(this);
1724
1725 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1726}
1727
1728TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1729 // Inject a primary display.
1730 PrimaryDisplayVariant::injectHwcDisplay(this);
1731
1732 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1733}
1734
1735TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1736 // Inject both a primary and external display.
1737 PrimaryDisplayVariant::injectHwcDisplay(this);
1738 ExternalDisplayVariant::injectHwcDisplay(this);
1739
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001740 // TODO: This is an unnecessary call.
1741 EXPECT_CALL(*mComposer,
1742 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
1743 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
1744 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
1745 Return(Error::NONE)));
1746
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001747 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1748
1749 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1750}
1751
1752TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1753 // Inject a primary display.
1754 PrimaryDisplayVariant::injectHwcDisplay(this);
1755
1756 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1757
1758 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1759}
1760
1761TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1762 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1763}
1764
1765TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1766 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1767}
1768
1769TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1770 using Case = SimplePrimaryDisplayCase;
1771
1772 // --------------------------------------------------------------------
1773 // Preconditions
1774
1775 setupCommonPreconditions<Case>();
1776
1777 // A hotplug connect event is enqueued for a display
1778 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1779 // A hotplug disconnect event is also enqueued for the same display
1780 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1781
1782 // --------------------------------------------------------------------
1783 // Call Expectations
1784
1785 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1786
1787 setupCommonCallExpectationsForConnectProcessing<Case>();
1788 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1789
1790 EXPECT_CALL(*mComposer,
1791 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1792 .WillOnce(Return(Error::NONE));
1793 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1794
1795 // --------------------------------------------------------------------
1796 // Invocation
1797
1798 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1799
1800 // --------------------------------------------------------------------
1801 // Postconditions
1802
1803 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001804 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001805
Dominik Laskowski075d3172018-05-24 15:50:06 -07001806 // SF should not have a display token.
1807 const auto displayId = Case::Display::DISPLAY_ID::get();
1808 ASSERT_TRUE(displayId);
1809 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001810}
1811
1812TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1813 using Case = SimplePrimaryDisplayCase;
1814
1815 // --------------------------------------------------------------------
1816 // Preconditions
1817
1818 setupCommonPreconditions<Case>();
1819
1820 // The display is already completely set up.
1821 Case::Display::injectHwcDisplay(this);
1822 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1823 existing.inject();
1824
1825 // A hotplug disconnect event is enqueued for a display
1826 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1827 // A hotplug connect event is also enqueued for the same display
1828 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1829
1830 // --------------------------------------------------------------------
1831 // Call Expectations
1832
1833 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1834
1835 setupCommonCallExpectationsForConnectProcessing<Case>();
1836 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1837
1838 // --------------------------------------------------------------------
1839 // Invocation
1840
1841 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1842
1843 // --------------------------------------------------------------------
1844 // Postconditions
1845
1846 // The existing token should have been removed
1847 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001848 const auto displayId = Case::Display::DISPLAY_ID::get();
1849 ASSERT_TRUE(displayId);
1850 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1851 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001852
1853 // A new display should be connected in its place
1854
1855 verifyPhysicalDisplayIsConnected<Case>();
1856
1857 // --------------------------------------------------------------------
1858 // Cleanup conditions
1859
1860 EXPECT_CALL(*mComposer,
1861 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1862 .WillOnce(Return(Error::NONE));
1863 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1864}
1865
1866TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1867 using Case = HwcVirtualDisplayCase;
1868
1869 // --------------------------------------------------------------------
1870 // Preconditions
1871
1872 // The HWC supports at least one virtual display
1873 injectMockComposer(1);
1874
1875 setupCommonPreconditions<Case>();
1876
1877 // A virtual display was added to the current state, and it has a
1878 // surface(producer)
1879 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07001880
Dominik Laskowski075d3172018-05-24 15:50:06 -07001881 DisplayDeviceState state;
1882 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001883
1884 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001885 state.surface = surface;
1886 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001887
1888 // --------------------------------------------------------------------
1889 // Call Expectations
1890
1891 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1892 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1893
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001894 EXPECT_CALL(*mComposer, getDisplayCapabilities(Case::Display::HWC_DISPLAY_ID, _))
1895 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
1896 Return(Error::NONE)));
1897
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001898 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1899 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1900 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1901 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1902 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1903 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1904 Return(NO_ERROR)));
1905 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1906 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1907
1908 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1909
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001910 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001911 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1912
1913 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1914 Case::WideColorSupport::setupComposerCallExpectations(this);
1915 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001916 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001917
1918 // --------------------------------------------------------------------
1919 // Invocation
1920
1921 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1922
1923 // --------------------------------------------------------------------
1924 // Postconditions
1925
1926 // The display device should have been set up in the list of displays.
1927 verifyDisplayIsConnected<Case>(displayToken);
1928
1929 // --------------------------------------------------------------------
1930 // Cleanup conditions
1931
1932 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1933 .WillOnce(Return(Error::NONE));
1934 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08001935
1936 // Cleanup
1937 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
1938 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001939}
1940
1941TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1942 using Case = HwcVirtualDisplayCase;
1943
1944 // --------------------------------------------------------------------
1945 // Preconditions
1946
1947 // The HWC supports at least one virtual display
1948 injectMockComposer(1);
1949
1950 setupCommonPreconditions<Case>();
1951
1952 // A virtual display was added to the current state, but it does not have a
1953 // surface.
1954 sp<BBinder> displayToken = new BBinder();
1955
Dominik Laskowski075d3172018-05-24 15:50:06 -07001956 DisplayDeviceState state;
1957 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001958
Dominik Laskowski075d3172018-05-24 15:50:06 -07001959 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001960
1961 // --------------------------------------------------------------------
1962 // Call Expectations
1963
1964 // --------------------------------------------------------------------
1965 // Invocation
1966
1967 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1968
1969 // --------------------------------------------------------------------
1970 // Postconditions
1971
1972 // There will not be a display device set up.
1973 EXPECT_FALSE(hasDisplayDevice(displayToken));
1974
1975 // The drawing display state will be set from the current display state.
1976 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1977 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001978 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001979}
1980
1981TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1982 using Case = HwcVirtualDisplayCase;
1983
1984 // --------------------------------------------------------------------
1985 // Preconditions
1986
1987 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07001988 const auto displayId = Case::Display::DISPLAY_ID::get();
1989 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001990 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001991 Case::Display::injectHwcDisplay(this);
1992 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1993 existing.inject();
1994 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1995
1996 // --------------------------------------------------------------------
1997 // Call Expectations
1998
1999 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2000
2001 // --------------------------------------------------------------------
2002 // Invocation
2003
2004 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2005
2006 // --------------------------------------------------------------------
2007 // Postconditions
2008
2009 // The existing token should have been removed
2010 verifyDisplayIsNotConnected(existing.token());
2011}
2012
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002013TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2014 using Case = NonHwcVirtualDisplayCase;
2015
2016 constexpr uint32_t oldLayerStack = 0u;
2017 constexpr uint32_t newLayerStack = 123u;
2018
2019 // --------------------------------------------------------------------
2020 // Preconditions
2021
2022 // A display is set up
2023 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2024 display.inject();
2025
2026 // There is a change to the layerStack state
2027 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2028 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2029
2030 // --------------------------------------------------------------------
2031 // Invocation
2032
2033 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2034
2035 // --------------------------------------------------------------------
2036 // Postconditions
2037
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002038 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002039}
2040
2041TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2042 using Case = NonHwcVirtualDisplayCase;
2043
2044 constexpr int oldTransform = 0;
2045 constexpr int newTransform = 2;
2046
2047 // --------------------------------------------------------------------
2048 // Preconditions
2049
2050 // A display is set up
2051 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2052 display.inject();
2053
2054 // There is a change to the orientation state
2055 display.mutableDrawingDisplayState().orientation = oldTransform;
2056 display.mutableCurrentDisplayState().orientation = newTransform;
2057
2058 // --------------------------------------------------------------------
2059 // Invocation
2060
2061 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2062
2063 // --------------------------------------------------------------------
2064 // Postconditions
2065
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002066 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002067}
2068
2069TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2070 using Case = NonHwcVirtualDisplayCase;
2071
2072 const Rect oldViewport(0, 0, 0, 0);
2073 const Rect newViewport(0, 0, 123, 456);
2074
2075 // --------------------------------------------------------------------
2076 // Preconditions
2077
2078 // A display is set up
2079 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2080 display.inject();
2081
2082 // There is a change to the viewport state
2083 display.mutableDrawingDisplayState().viewport = oldViewport;
2084 display.mutableCurrentDisplayState().viewport = newViewport;
2085
2086 // --------------------------------------------------------------------
2087 // Invocation
2088
2089 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2090
2091 // --------------------------------------------------------------------
2092 // Postconditions
2093
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002094 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002095}
2096
2097TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2098 using Case = NonHwcVirtualDisplayCase;
2099
2100 const Rect oldFrame(0, 0, 0, 0);
2101 const Rect newFrame(0, 0, 123, 456);
2102
2103 // --------------------------------------------------------------------
2104 // Preconditions
2105
2106 // A display is set up
2107 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2108 display.inject();
2109
2110 // There is a change to the viewport state
2111 display.mutableDrawingDisplayState().frame = oldFrame;
2112 display.mutableCurrentDisplayState().frame = newFrame;
2113
2114 // --------------------------------------------------------------------
2115 // Invocation
2116
2117 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2118
2119 // --------------------------------------------------------------------
2120 // Postconditions
2121
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002122 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002123}
2124
2125TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2126 using Case = NonHwcVirtualDisplayCase;
2127
2128 constexpr int oldWidth = 0;
2129 constexpr int oldHeight = 10;
2130 constexpr int newWidth = 123;
2131
2132 // --------------------------------------------------------------------
2133 // Preconditions
2134
2135 // A display is set up
2136 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002137 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002138 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002139 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2140 display.setNativeWindow(nativeWindow);
2141 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002142 // Setup injection expections
2143 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2144 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2145 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2146 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002147 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2148 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2149 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002150 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002151 display.inject();
2152
2153 // There is a change to the viewport state
2154 display.mutableDrawingDisplayState().width = oldWidth;
2155 display.mutableDrawingDisplayState().height = oldHeight;
2156 display.mutableCurrentDisplayState().width = newWidth;
2157 display.mutableCurrentDisplayState().height = oldHeight;
2158
2159 // --------------------------------------------------------------------
2160 // Call Expectations
2161
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002162 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002163
2164 // --------------------------------------------------------------------
2165 // Invocation
2166
2167 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2168}
2169
2170TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2171 using Case = NonHwcVirtualDisplayCase;
2172
2173 constexpr int oldWidth = 0;
2174 constexpr int oldHeight = 10;
2175 constexpr int newHeight = 123;
2176
2177 // --------------------------------------------------------------------
2178 // Preconditions
2179
2180 // A display is set up
2181 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002182 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002183 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002184 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2185 display.setNativeWindow(nativeWindow);
2186 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002187 // Setup injection expections
2188 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2189 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2190 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2191 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002192 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2193 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2194 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002195 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002196 display.inject();
2197
2198 // There is a change to the viewport state
2199 display.mutableDrawingDisplayState().width = oldWidth;
2200 display.mutableDrawingDisplayState().height = oldHeight;
2201 display.mutableCurrentDisplayState().width = oldWidth;
2202 display.mutableCurrentDisplayState().height = newHeight;
2203
2204 // --------------------------------------------------------------------
2205 // Call Expectations
2206
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002207 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002208
2209 // --------------------------------------------------------------------
2210 // Invocation
2211
2212 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2213}
2214
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002215/* ------------------------------------------------------------------------
2216 * SurfaceFlinger::setDisplayStateLocked
2217 */
2218
2219TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2220 // --------------------------------------------------------------------
2221 // Preconditions
2222
2223 // We have an unknown display token not associated with a known display
2224 sp<BBinder> displayToken = new BBinder();
2225
2226 // The requested display state references the unknown display.
2227 DisplayState state;
2228 state.what = DisplayState::eLayerStackChanged;
2229 state.token = displayToken;
2230 state.layerStack = 456;
2231
2232 // --------------------------------------------------------------------
2233 // Invocation
2234
2235 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2236
2237 // --------------------------------------------------------------------
2238 // Postconditions
2239
2240 // The returned flags are empty
2241 EXPECT_EQ(0u, flags);
2242
2243 // The display token still doesn't match anything known.
2244 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2245}
2246
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002247TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2248 using Case = SimplePrimaryDisplayCase;
2249
2250 // --------------------------------------------------------------------
2251 // Preconditions
2252
2253 // A display is already set up
2254 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2255 display.inject();
2256
2257 // No changes are made to the display
2258 DisplayState state;
2259 state.what = 0;
2260 state.token = display.token();
2261
2262 // --------------------------------------------------------------------
2263 // Invocation
2264
2265 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2266
2267 // --------------------------------------------------------------------
2268 // Postconditions
2269
2270 // The returned flags are empty
2271 EXPECT_EQ(0u, flags);
2272}
2273
2274TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2275 using Case = SimplePrimaryDisplayCase;
2276
2277 // --------------------------------------------------------------------
2278 // Preconditions
2279
2280 // A display is already set up
2281 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2282 display.inject();
2283
2284 // There is a surface that can be set.
2285 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2286
2287 // The current display state has the surface set
2288 display.mutableCurrentDisplayState().surface = surface;
2289
2290 // The incoming request sets the same surface
2291 DisplayState state;
2292 state.what = DisplayState::eSurfaceChanged;
2293 state.token = display.token();
2294 state.surface = surface;
2295
2296 // --------------------------------------------------------------------
2297 // Invocation
2298
2299 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2300
2301 // --------------------------------------------------------------------
2302 // Postconditions
2303
2304 // The returned flags are empty
2305 EXPECT_EQ(0u, flags);
2306
2307 // The current display state is unchanged.
2308 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2309}
2310
2311TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2312 using Case = SimplePrimaryDisplayCase;
2313
2314 // --------------------------------------------------------------------
2315 // Preconditions
2316
2317 // A display is already set up
2318 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2319 display.inject();
2320
2321 // There is a surface that can be set.
2322 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2323
2324 // The current display state does not have a surface
2325 display.mutableCurrentDisplayState().surface = nullptr;
2326
2327 // The incoming request sets a surface
2328 DisplayState state;
2329 state.what = DisplayState::eSurfaceChanged;
2330 state.token = display.token();
2331 state.surface = surface;
2332
2333 // --------------------------------------------------------------------
2334 // Invocation
2335
2336 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2337
2338 // --------------------------------------------------------------------
2339 // Postconditions
2340
2341 // The returned flags indicate a transaction is needed
2342 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2343
2344 // The current display layer stack state is set to the new value
2345 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2346}
2347
2348TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2349 using Case = SimplePrimaryDisplayCase;
2350
2351 // --------------------------------------------------------------------
2352 // Preconditions
2353
2354 // A display is already set up
2355 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2356 display.inject();
2357
2358 // The display has a layer stack set
2359 display.mutableCurrentDisplayState().layerStack = 456u;
2360
2361 // The incoming request sets the same layer stack
2362 DisplayState state;
2363 state.what = DisplayState::eLayerStackChanged;
2364 state.token = display.token();
2365 state.layerStack = 456u;
2366
2367 // --------------------------------------------------------------------
2368 // Invocation
2369
2370 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2371
2372 // --------------------------------------------------------------------
2373 // Postconditions
2374
2375 // The returned flags are empty
2376 EXPECT_EQ(0u, flags);
2377
2378 // The current display state is unchanged
2379 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2380}
2381
2382TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2383 using Case = SimplePrimaryDisplayCase;
2384
2385 // --------------------------------------------------------------------
2386 // Preconditions
2387
2388 // A display is set up
2389 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2390 display.inject();
2391
2392 // The display has a layer stack set
2393 display.mutableCurrentDisplayState().layerStack = 654u;
2394
2395 // The incoming request sets a different layer stack
2396 DisplayState state;
2397 state.what = DisplayState::eLayerStackChanged;
2398 state.token = display.token();
2399 state.layerStack = 456u;
2400
2401 // --------------------------------------------------------------------
2402 // Invocation
2403
2404 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2405
2406 // --------------------------------------------------------------------
2407 // Postconditions
2408
2409 // The returned flags indicate a transaction is needed
2410 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2411
2412 // The desired display state has been set to the new value.
2413 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2414}
2415
2416TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2417 using Case = SimplePrimaryDisplayCase;
2418 constexpr int initialOrientation = 180;
2419 const Rect initialFrame = {1, 2, 3, 4};
2420 const Rect initialViewport = {5, 6, 7, 8};
2421
2422 // --------------------------------------------------------------------
2423 // Preconditions
2424
2425 // A display is set up
2426 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2427 display.inject();
2428
2429 // The current display state projection state is all set
2430 display.mutableCurrentDisplayState().orientation = initialOrientation;
2431 display.mutableCurrentDisplayState().frame = initialFrame;
2432 display.mutableCurrentDisplayState().viewport = initialViewport;
2433
2434 // The incoming request sets the same projection state
2435 DisplayState state;
2436 state.what = DisplayState::eDisplayProjectionChanged;
2437 state.token = display.token();
2438 state.orientation = initialOrientation;
2439 state.frame = initialFrame;
2440 state.viewport = initialViewport;
2441
2442 // --------------------------------------------------------------------
2443 // Invocation
2444
2445 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2446
2447 // --------------------------------------------------------------------
2448 // Postconditions
2449
2450 // The returned flags are empty
2451 EXPECT_EQ(0u, flags);
2452
2453 // The current display state is unchanged
2454 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2455
2456 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2457 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2458}
2459
2460TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2461 using Case = SimplePrimaryDisplayCase;
2462 constexpr int initialOrientation = 90;
2463 constexpr int desiredOrientation = 180;
2464
2465 // --------------------------------------------------------------------
2466 // Preconditions
2467
2468 // A display is set up
2469 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2470 display.inject();
2471
2472 // The current display state has an orientation set
2473 display.mutableCurrentDisplayState().orientation = initialOrientation;
2474
2475 // The incoming request sets a different orientation
2476 DisplayState state;
2477 state.what = DisplayState::eDisplayProjectionChanged;
2478 state.token = display.token();
2479 state.orientation = desiredOrientation;
2480
2481 // --------------------------------------------------------------------
2482 // Invocation
2483
2484 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2485
2486 // --------------------------------------------------------------------
2487 // Postconditions
2488
2489 // The returned flags indicate a transaction is needed
2490 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2491
2492 // The current display state has the new value.
2493 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2494}
2495
2496TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2497 using Case = SimplePrimaryDisplayCase;
2498 const Rect initialFrame = {0, 0, 0, 0};
2499 const Rect desiredFrame = {5, 6, 7, 8};
2500
2501 // --------------------------------------------------------------------
2502 // Preconditions
2503
2504 // A display is set up
2505 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2506 display.inject();
2507
2508 // The current display state does not have a frame
2509 display.mutableCurrentDisplayState().frame = initialFrame;
2510
2511 // The incoming request sets a frame
2512 DisplayState state;
2513 state.what = DisplayState::eDisplayProjectionChanged;
2514 state.token = display.token();
2515 state.frame = desiredFrame;
2516
2517 // --------------------------------------------------------------------
2518 // Invocation
2519
2520 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2521
2522 // --------------------------------------------------------------------
2523 // Postconditions
2524
2525 // The returned flags indicate a transaction is needed
2526 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2527
2528 // The current display state has the new value.
2529 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2530}
2531
2532TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2533 using Case = SimplePrimaryDisplayCase;
2534 const Rect initialViewport = {0, 0, 0, 0};
2535 const Rect desiredViewport = {5, 6, 7, 8};
2536
2537 // --------------------------------------------------------------------
2538 // Preconditions
2539
2540 // A display is set up
2541 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2542 display.inject();
2543
2544 // The current display state does not have a viewport
2545 display.mutableCurrentDisplayState().viewport = initialViewport;
2546
2547 // The incoming request sets a viewport
2548 DisplayState state;
2549 state.what = DisplayState::eDisplayProjectionChanged;
2550 state.token = display.token();
2551 state.viewport = desiredViewport;
2552
2553 // --------------------------------------------------------------------
2554 // Invocation
2555
2556 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2557
2558 // --------------------------------------------------------------------
2559 // Postconditions
2560
2561 // The returned flags indicate a transaction is needed
2562 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2563
2564 // The current display state has the new value.
2565 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2566}
2567
2568TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2569 using Case = SimplePrimaryDisplayCase;
2570 constexpr uint32_t initialWidth = 1024;
2571 constexpr uint32_t initialHeight = 768;
2572
2573 // --------------------------------------------------------------------
2574 // Preconditions
2575
2576 // A display is set up
2577 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2578 display.inject();
2579
2580 // The current display state has a size set
2581 display.mutableCurrentDisplayState().width = initialWidth;
2582 display.mutableCurrentDisplayState().height = initialHeight;
2583
2584 // The incoming request sets the same display size
2585 DisplayState state;
2586 state.what = DisplayState::eDisplaySizeChanged;
2587 state.token = display.token();
2588 state.width = initialWidth;
2589 state.height = initialHeight;
2590
2591 // --------------------------------------------------------------------
2592 // Invocation
2593
2594 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2595
2596 // --------------------------------------------------------------------
2597 // Postconditions
2598
2599 // The returned flags are empty
2600 EXPECT_EQ(0u, flags);
2601
2602 // The current display state is unchanged
2603 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2604 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2605}
2606
2607TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2608 using Case = SimplePrimaryDisplayCase;
2609 constexpr uint32_t initialWidth = 0;
2610 constexpr uint32_t desiredWidth = 1024;
2611
2612 // --------------------------------------------------------------------
2613 // Preconditions
2614
2615 // A display is set up
2616 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2617 display.inject();
2618
2619 // The display does not yet have a width
2620 display.mutableCurrentDisplayState().width = initialWidth;
2621
2622 // The incoming request sets a display width
2623 DisplayState state;
2624 state.what = DisplayState::eDisplaySizeChanged;
2625 state.token = display.token();
2626 state.width = desiredWidth;
2627
2628 // --------------------------------------------------------------------
2629 // Invocation
2630
2631 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2632
2633 // --------------------------------------------------------------------
2634 // Postconditions
2635
2636 // The returned flags indicate a transaction is needed
2637 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2638
2639 // The current display state has the new value.
2640 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2641}
2642
2643TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2644 using Case = SimplePrimaryDisplayCase;
2645 constexpr uint32_t initialHeight = 0;
2646 constexpr uint32_t desiredHeight = 768;
2647
2648 // --------------------------------------------------------------------
2649 // Preconditions
2650
2651 // A display is set up
2652 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2653 display.inject();
2654
2655 // The display does not yet have a height
2656 display.mutableCurrentDisplayState().height = initialHeight;
2657
2658 // The incoming request sets a display height
2659 DisplayState state;
2660 state.what = DisplayState::eDisplaySizeChanged;
2661 state.token = display.token();
2662 state.height = desiredHeight;
2663
2664 // --------------------------------------------------------------------
2665 // Invocation
2666
2667 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2668
2669 // --------------------------------------------------------------------
2670 // Postconditions
2671
2672 // The returned flags indicate a transaction is needed
2673 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2674
2675 // The current display state has the new value.
2676 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2677}
2678
Lloyd Pique86016da2018-03-01 16:09:38 -08002679/* ------------------------------------------------------------------------
2680 * SurfaceFlinger::onInitializeDisplays
2681 */
2682
2683TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2684 using Case = SimplePrimaryDisplayCase;
2685
2686 // --------------------------------------------------------------------
2687 // Preconditions
2688
2689 // A primary display is set up
2690 Case::Display::injectHwcDisplay(this);
2691 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2692 primaryDisplay.inject();
2693
2694 // --------------------------------------------------------------------
2695 // Call Expectations
2696
2697 // We expect the surface interceptor to possibly be used, but we treat it as
2698 // disabled since it is called as a side effect rather than directly by this
2699 // function.
2700 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2701
2702 // We expect a call to get the active display config.
2703 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2704
2705 // We expect invalidate() to be invoked once to trigger display transaction
2706 // processing.
2707 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2708
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002709 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2710
Lloyd Pique86016da2018-03-01 16:09:38 -08002711 // --------------------------------------------------------------------
2712 // Invocation
2713
2714 mFlinger.onInitializeDisplays();
2715
2716 // --------------------------------------------------------------------
2717 // Postconditions
2718
2719 // The primary display should have a current state
2720 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2721 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2722 // The layer stack state should be set to zero
2723 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2724 // The orientation state should be set to zero
2725 EXPECT_EQ(0, primaryDisplayState.orientation);
2726
2727 // The frame state should be set to INVALID
2728 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2729
2730 // The viewport state should be set to INVALID
2731 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2732
2733 // The width and height should both be zero
2734 EXPECT_EQ(0u, primaryDisplayState.width);
2735 EXPECT_EQ(0u, primaryDisplayState.height);
2736
2737 // The display should be set to HWC_POWER_MODE_NORMAL
2738 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2739 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2740 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2741
2742 // The display refresh period should be set in the frame tracker.
2743 FrameStats stats;
2744 mFlinger.getAnimFrameTracker().getStats(&stats);
2745 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2746
2747 // The display transaction needed flag should be set.
2748 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2749
2750 // The compositor timing should be set to default values
2751 const auto& compositorTiming = mFlinger.getCompositorTiming();
2752 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2753 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2754 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2755}
2756
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002757/* ------------------------------------------------------------------------
2758 * SurfaceFlinger::setPowerModeInternal
2759 */
2760
2761// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07002762template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002763struct DozeIsSupportedVariant {
2764 static constexpr bool DOZE_SUPPORTED = true;
2765 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2766 IComposerClient::PowerMode::DOZE;
2767 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2768 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07002769
2770 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2771 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2772 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
2773 {Hwc2::DisplayCapability::DOZE})),
2774 Return(Error::NONE)));
2775 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002776};
2777
Peiyong Lined531a32018-10-26 18:27:56 -07002778template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002779// Used when we simulate a display that does not support doze.
2780struct DozeNotSupportedVariant {
2781 static constexpr bool DOZE_SUPPORTED = false;
2782 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2783 IComposerClient::PowerMode::ON;
2784 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2785 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07002786
2787 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2788 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2789 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
2790 Return(Error::NONE)));
2791 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002792};
2793
2794struct EventThreadBaseSupportedVariant {
2795 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
2796 // The event control thread should not be notified.
2797 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
2798
2799 // The event thread should not be notified.
2800 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
2801 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
2802 }
2803};
2804
2805struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
2806 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2807 // These calls are only expected for the primary display.
2808
2809 // Instead expect no calls.
2810 setupEventAndEventControlThreadNoCallExpectations(test);
2811 }
2812
2813 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2814 // These calls are only expected for the primary display.
2815
2816 // Instead expect no calls.
2817 setupEventAndEventControlThreadNoCallExpectations(test);
2818 }
2819};
2820
2821struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
2822 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2823 // The event control thread should be notified to enable vsyncs
2824 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
2825
2826 // The event thread should be notified that the screen was acquired.
2827 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
2828 }
2829
2830 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2831 // There should be a call to setVsyncEnabled(false)
2832 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
2833
2834 // The event thread should not be notified that the screen was released.
2835 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
2836 }
2837};
2838
Lloyd Pique41be5d22018-06-21 13:11:48 -07002839struct DispSyncIsSupportedVariant {
2840 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique41be5d22018-06-21 13:11:48 -07002841 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
2842 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
2843 }
2844
2845 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
2846 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
2847 }
2848};
2849
2850struct DispSyncNotSupportedVariant {
2851 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2852
2853 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2854};
2855
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002856// --------------------------------------------------------------------
2857// Note:
2858//
2859// There are a large number of transitions we could test, however we only test a
2860// selected subset which provides complete test coverage of the implementation.
2861// --------------------------------------------------------------------
2862
2863template <int initialPowerMode, int targetPowerMode>
2864struct TransitionVariantCommon {
2865 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
2866 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
2867
2868 static void verifyPostconditions(DisplayTransactionTest*) {}
2869};
2870
2871struct TransitionOffToOnVariant
2872 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
2873 template <typename Case>
2874 static void setupCallExpectations(DisplayTransactionTest* test) {
2875 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2876 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002877 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002878 Case::setupRepaintEverythingCallExpectations(test);
2879 }
2880
2881 static void verifyPostconditions(DisplayTransactionTest* test) {
2882 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2883 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2884 }
2885};
2886
2887struct TransitionOffToDozeSuspendVariant
2888 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
2889 template <typename Case>
2890 static void setupCallExpectations(DisplayTransactionTest* test) {
2891 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2892 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2893 Case::setupRepaintEverythingCallExpectations(test);
2894 }
2895
2896 static void verifyPostconditions(DisplayTransactionTest* test) {
2897 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2898 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2899 }
2900};
2901
2902struct TransitionOnToOffVariant
2903 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
2904 template <typename Case>
2905 static void setupCallExpectations(DisplayTransactionTest* test) {
2906 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002907 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002908 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2909 }
2910
2911 static void verifyPostconditions(DisplayTransactionTest* test) {
2912 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2913 }
2914};
2915
2916struct TransitionDozeSuspendToOffVariant
2917 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
2918 template <typename Case>
2919 static void setupCallExpectations(DisplayTransactionTest* test) {
2920 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2921 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2922 }
2923
2924 static void verifyPostconditions(DisplayTransactionTest* test) {
2925 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2926 }
2927};
2928
2929struct TransitionOnToDozeVariant
2930 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
2931 template <typename Case>
2932 static void setupCallExpectations(DisplayTransactionTest* test) {
2933 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2934 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2935 }
2936};
2937
2938struct TransitionDozeSuspendToDozeVariant
2939 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
2940 template <typename Case>
2941 static void setupCallExpectations(DisplayTransactionTest* test) {
2942 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002943 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002944 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2945 }
2946};
2947
2948struct TransitionDozeToOnVariant
2949 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
2950 template <typename Case>
2951 static void setupCallExpectations(DisplayTransactionTest* test) {
2952 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2953 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2954 }
2955};
2956
2957struct TransitionDozeSuspendToOnVariant
2958 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
2959 template <typename Case>
2960 static void setupCallExpectations(DisplayTransactionTest* test) {
2961 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002962 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002963 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2964 }
2965};
2966
2967struct TransitionOnToDozeSuspendVariant
2968 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
2969 template <typename Case>
2970 static void setupCallExpectations(DisplayTransactionTest* test) {
2971 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002972 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002973 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2974 }
2975};
2976
2977struct TransitionOnToUnknownVariant
2978 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
2979 template <typename Case>
2980 static void setupCallExpectations(DisplayTransactionTest* test) {
2981 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2982 Case::setupNoComposerPowerModeCallExpectations(test);
2983 }
2984};
2985
2986// --------------------------------------------------------------------
2987// Note:
2988//
2989// Rather than testing the cartesian product of of
2990// DozeIsSupported/DozeNotSupported with all other options, we use one for one
2991// display type, and the other for another display type.
2992// --------------------------------------------------------------------
2993
2994template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07002995 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002996struct DisplayPowerCase {
2997 using Display = DisplayVariant;
2998 using Doze = DozeVariant;
2999 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003000 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003001 using Transition = TransitionVariant;
3002
3003 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003004 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003005 auto display = Display::makeFakeExistingDisplayInjector(test);
3006 display.inject();
3007 display.mutableDisplayDevice()->setPowerMode(mode);
3008 return display;
3009 }
3010
3011 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Ana Krulecafb45842019-02-13 13:33:03 -08003012 test->mScheduler->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003013 }
3014
3015 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3016 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3017 }
3018
3019 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3020 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3021 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3022 }
3023
3024 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3025 IComposerClient::PowerMode mode) {
3026 // Any calls to get the active config will return a default value.
3027 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3028 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3029 Return(Error::NONE)));
3030
3031 // Any calls to get whether the display supports dozing will return the value set by the
3032 // policy variant.
3033 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3034 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3035
3036 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3037 }
3038
3039 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3040 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3041 }
3042};
3043
3044// A sample configuration for the primary display.
3045// In addition to having event thread support, we emulate doze support.
3046template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003047using PrimaryDisplayPowerCase =
3048 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3049 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3050 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003051
3052// A sample configuration for the external display.
3053// In addition to not having event thread support, we emulate not having doze
3054// support.
3055template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003056using ExternalDisplayPowerCase =
3057 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3058 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3059 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003060
3061class SetPowerModeInternalTest : public DisplayTransactionTest {
3062public:
3063 template <typename Case>
3064 void transitionDisplayCommon();
3065};
3066
3067template <int PowerMode>
3068struct PowerModeInitialVSyncEnabled : public std::false_type {};
3069
3070template <>
3071struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3072
3073template <>
3074struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3075
3076template <typename Case>
3077void SetPowerModeInternalTest::transitionDisplayCommon() {
3078 // --------------------------------------------------------------------
3079 // Preconditions
3080
Peiyong Lined531a32018-10-26 18:27:56 -07003081 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003082 auto display =
3083 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3084 Case::setInitialPrimaryHWVsyncEnabled(this,
3085 PowerModeInitialVSyncEnabled<
3086 Case::Transition::INITIAL_POWER_MODE>::value);
3087
3088 // --------------------------------------------------------------------
3089 // Call Expectations
3090
3091 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3092 Case::Transition::template setupCallExpectations<Case>(this);
3093
3094 // --------------------------------------------------------------------
3095 // Invocation
3096
3097 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3098 Case::Transition::TARGET_POWER_MODE);
3099
3100 // --------------------------------------------------------------------
3101 // Postconditions
3102
3103 Case::Transition::verifyPostconditions(this);
3104}
3105
3106TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3107 using Case = SimplePrimaryDisplayCase;
3108
3109 // --------------------------------------------------------------------
3110 // Preconditions
3111
3112 // A primary display device is set up
3113 Case::Display::injectHwcDisplay(this);
3114 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3115 display.inject();
3116
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003117 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003118 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3119
3120 // --------------------------------------------------------------------
3121 // Invocation
3122
3123 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3124
3125 // --------------------------------------------------------------------
3126 // Postconditions
3127
3128 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3129}
3130
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003131TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003132 using Case = HwcVirtualDisplayCase;
3133
3134 // --------------------------------------------------------------------
3135 // Preconditions
3136
Dominik Laskowski075d3172018-05-24 15:50:06 -07003137 // Insert display data so that the HWC thinks it created the virtual display.
3138 const auto displayId = Case::Display::DISPLAY_ID::get();
3139 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003140 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003141
3142 // A virtual display device is set up
3143 Case::Display::injectHwcDisplay(this);
3144 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3145 display.inject();
3146
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003147 // The display is set to HWC_POWER_MODE_NORMAL
3148 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003149
3150 // --------------------------------------------------------------------
3151 // Invocation
3152
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003153 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003154
3155 // --------------------------------------------------------------------
3156 // Postconditions
3157
3158 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3159}
3160
3161TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3162 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3163}
3164
3165TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3166 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3167}
3168
3169TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3170 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3171}
3172
3173TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3174 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3175}
3176
3177TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3178 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3179}
3180
3181TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3182 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3183}
3184
3185TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3186 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3187}
3188
3189TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3190 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3191}
3192
3193TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3194 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3195}
3196
3197TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3198 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3199}
3200
3201TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3202 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3203}
3204
3205TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3206 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3207}
3208
3209TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3210 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3211}
3212
3213TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3214 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3215}
3216
3217TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3218 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3219}
3220
3221TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3222 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3223}
3224
3225TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3226 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3227}
3228
3229TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3230 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3231}
3232
3233TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3234 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3235}
3236
3237TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3238 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3239}
3240
Lloyd Piquef58625d2017-12-19 13:22:33 -08003241} // namespace
3242} // namespace android