blob: d83f1bdf4fba3141d010277580780a30ecd8b5b7 [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));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800361 return injector;
362 }
363
364 // Called by tests to set up any native window creation call expectations.
365 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
366 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
367 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800368
Alec Mouriba013fa2018-10-16 12:43:11 -0700369 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
370 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
371 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
372 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800373 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
374 .WillRepeatedly(Return(0));
375 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
376 .WillRepeatedly(Return(0));
377 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
378 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800379 }
380
381 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
382 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
383 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
384 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
385 .WillRepeatedly(Return(NO_ERROR));
386 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
387 .WillRepeatedly(Return(NO_ERROR));
388 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
389 .WillRepeatedly(Return(NO_ERROR));
390 }
391
392 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
393 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
394 }
395};
396
Dominik Laskowski075d3172018-05-24 15:50:06 -0700397template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
398 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800399struct HwcDisplayVariant {
400 // The display id supplied by the HWC
401 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
402
403 // The HWC display type
404 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
405
406 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700407 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800408
409 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
410 HWC2::Connection connection) {
411 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
412 HotplugEvent{HWC_DISPLAY_ID, connection});
413 }
414
415 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800416 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700417 const auto displayId = DisplayVariant::DISPLAY_ID::get();
418 ASSERT_TRUE(displayId);
419 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
420 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800421 .setHwcDisplayId(HWC_DISPLAY_ID)
422 .setWidth(DisplayVariant::WIDTH)
423 .setHeight(DisplayVariant::HEIGHT)
424 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
425 .inject(&test->mFlinger, test->mComposer);
426 }
427
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800428 // Called by tests to inject a HWC display setup
429 static void injectHwcDisplay(DisplayTransactionTest* test) {
430 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
431 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
432 Return(Error::NONE)));
433 injectHwcDisplayWithNoDefaultCapabilities(test);
434 }
435
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800436 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
437 EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _))
438 .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>(
439 HWC_DISPLAY_TYPE)),
440 Return(Error::NONE)));
441 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
442 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
443 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
444 Return(Error::NONE)));
445 EXPECT_CALL(*test->mComposer,
446 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
447 IComposerClient::Attribute::WIDTH, _))
448 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
449 EXPECT_CALL(*test->mComposer,
450 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
451 IComposerClient::Attribute::HEIGHT, _))
452 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
453 EXPECT_CALL(*test->mComposer,
454 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
455 IComposerClient::Attribute::VSYNC_PERIOD, _))
456 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
457 EXPECT_CALL(*test->mComposer,
458 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
459 IComposerClient::Attribute::DPI_X, _))
460 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
461 EXPECT_CALL(*test->mComposer,
462 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
463 IComposerClient::Attribute::DPI_Y, _))
464 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800465 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
466 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
467 Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700468
469 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
470 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
471 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
472 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
473 Return(Error::NONE)));
474 } else {
475 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
476 .WillOnce(Return(Error::UNSUPPORTED));
477 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800478 }
479
480 // Called by tests to set up HWC call expectations
481 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
482 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700483 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800484 }
485};
486
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800487// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
488constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
489 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
490
Dominik Laskowski075d3172018-05-24 15:50:06 -0700491template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800492 Critical critical>
493struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700494 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
495 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
496 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
497 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
498 critical, Async::FALSE, Secure::TRUE,
499 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
500 PhysicalDisplay> {};
501
502template <bool hasIdentificationData>
503struct PrimaryDisplay {
504 static constexpr Primary PRIMARY = Primary::TRUE;
505 static constexpr uint8_t PORT = 255;
506 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
507 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
508};
509
510template <bool hasIdentificationData>
511struct ExternalDisplay {
512 static constexpr Primary PRIMARY = Primary::FALSE;
513 static constexpr uint8_t PORT = 254;
514 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
515 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
516};
517
518struct TertiaryDisplay {
519 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800520 static constexpr uint8_t PORT = 253;
521 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700522};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800523
524// A primary display is a physical display that is critical
525using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700526 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800527
528// An external display is physical display that is not critical.
529using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700530 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800531
532using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700533 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800534
535// A virtual display not supported by the HWC.
536constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
537
538template <int width, int height, Secure secure>
539struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700540 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
541 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
542 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
543 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
544
545 static void injectHwcDisplay(DisplayTransactionTest*) {}
546
547 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
548 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
549 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800550
551 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
552 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
553 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
554 }
555};
556
557// A virtual display supported by the HWC.
558constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
559
560template <int width, int height, Secure secure>
561struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700562 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
563 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
564 HwcDisplayVariant<
565 1010, HWC2::DisplayType::Virtual,
566 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
567 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
568 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
569 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800570 using Self = HwcVirtualDisplayVariant<width, height, secure>;
571
572 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
573 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
574 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
575 }
576
577 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
578 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
579 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
580 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
581 }
582};
583
584// For this variant, SurfaceFlinger should not configure itself with wide
585// display support, so the display should not be configured for wide-color
586// support.
587struct WideColorSupportNotConfiguredVariant {
588 static constexpr bool WIDE_COLOR_SUPPORTED = false;
589
590 static void injectConfigChange(DisplayTransactionTest* test) {
591 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700592 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800593 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
594 }
595
596 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
597 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
598 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
599 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
600 }
601};
602
603// For this variant, SurfaceFlinger should configure itself with wide display
604// support, and the display should respond with an non-empty list of supported
605// color modes. Wide-color support should be configured.
606template <typename Display>
607struct WideColorP3ColorimetricSupportedVariant {
608 static constexpr bool WIDE_COLOR_SUPPORTED = true;
609
610 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700611 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800612 test->mFlinger.mutableHasWideColorDisplay() = true;
613 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
614 }
615
616 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800617 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
618
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800619 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
620 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
621 Return(Error::NONE)));
622 EXPECT_CALL(*test->mComposer,
623 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
624 .WillOnce(DoAll(SetArgPointee<2>(
625 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
626 Return(Error::NONE)));
627 EXPECT_CALL(*test->mComposer,
628 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
629 RenderIntent::COLORIMETRIC))
630 .WillOnce(Return(Error::NONE));
631 }
632};
633
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800634// For this variant, SurfaceFlinger should configure itself with wide display
635// support, but the display should respond with an empty list of supported color
636// modes. Wide-color support for the display should not be configured.
637template <typename Display>
638struct WideColorNotSupportedVariant {
639 static constexpr bool WIDE_COLOR_SUPPORTED = false;
640
641 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700642 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800643 test->mFlinger.mutableHasWideColorDisplay() = true;
644 }
645
646 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
647 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
648 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700649 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800650 }
651};
652
653// For this variant, the display is not a HWC display, so no HDR support should
654// be configured.
655struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800656 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800657 static constexpr bool HDR10_SUPPORTED = false;
658 static constexpr bool HDR_HLG_SUPPORTED = false;
659 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
660 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
661 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
662 }
663};
664
Valerie Haue9e843a2018-12-18 13:39:23 -0800665template <typename Display>
666struct Hdr10PlusSupportedVariant {
667 static constexpr bool HDR10_PLUS_SUPPORTED = true;
668 static constexpr bool HDR10_SUPPORTED = true;
669 static constexpr bool HDR_HLG_SUPPORTED = false;
670 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
671 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
672 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
673 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
674 Hdr::HDR10_PLUS,
675 Hdr::HDR10,
676 })),
677 Return(Error::NONE)));
678 }
679};
680
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800681// For this variant, the composer should respond with a non-empty list of HDR
682// modes containing HDR10, so HDR10 support should be configured.
683template <typename Display>
684struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800685 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800686 static constexpr bool HDR10_SUPPORTED = true;
687 static constexpr bool HDR_HLG_SUPPORTED = false;
688 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
689 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
690 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
691 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
692 Return(Error::NONE)));
693 }
694};
695
696// For this variant, the composer should respond with a non-empty list of HDR
697// modes containing HLG, so HLG support should be configured.
698template <typename Display>
699struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800700 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800701 static constexpr bool HDR10_SUPPORTED = false;
702 static constexpr bool HDR_HLG_SUPPORTED = true;
703 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
704 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
705 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
706 .WillOnce(
707 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
708 }
709};
710
711// For this variant, the composer should respond with a non-empty list of HDR
712// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
713template <typename Display>
714struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800715 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800716 static constexpr bool HDR10_SUPPORTED = false;
717 static constexpr bool HDR_HLG_SUPPORTED = false;
718 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
719 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
720 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
721 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
722 Return(Error::NONE)));
723 }
724};
725
726// For this variant, the composer should respond with am empty list of HDR
727// modes, so no HDR support should be configured.
728template <typename Display>
729struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800730 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800731 static constexpr bool HDR10_SUPPORTED = false;
732 static constexpr bool HDR_HLG_SUPPORTED = false;
733 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
734 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
735 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
736 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
737 }
738};
739
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700740struct NonHwcPerFrameMetadataSupportVariant {
741 static constexpr int PER_FRAME_METADATA_KEYS = 0;
742 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800743 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700744 }
745};
746
747template <typename Display>
748struct NoPerFrameMetadataSupportVariant {
749 static constexpr int PER_FRAME_METADATA_KEYS = 0;
750 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800751 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
752 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700753 }
754};
755
756template <typename Display>
757struct Smpte2086PerFrameMetadataSupportVariant {
758 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
759 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800760 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
761 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800762 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
763 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
764 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
765 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
766 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
767 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
768 PerFrameMetadataKey::WHITE_POINT_X,
769 PerFrameMetadataKey::WHITE_POINT_Y,
770 PerFrameMetadataKey::MAX_LUMINANCE,
771 PerFrameMetadataKey::MIN_LUMINANCE,
772 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700773 }
774};
775
776template <typename Display>
777struct Cta861_3_PerFrameMetadataSupportVariant {
778 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
779 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800780 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
781 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800782 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
783 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
784 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700785 }
786};
787
Valerie Haue9e843a2018-12-18 13:39:23 -0800788template <typename Display>
789struct Hdr10_Plus_PerFrameMetadataSupportVariant {
790 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
791 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
792 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
793 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
794 PerFrameMetadataKey::HDR10_PLUS_SEI,
795 })));
796 }
797};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800798/* ------------------------------------------------------------------------
799 * Typical display configurations to test
800 */
801
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700802template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
803 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800804struct Case {
805 using Display = DisplayPolicy;
806 using WideColorSupport = WideColorSupportPolicy;
807 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700808 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800809};
810
811using SimplePrimaryDisplayCase =
812 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700813 HdrNotSupportedVariant<PrimaryDisplayVariant>,
814 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800815using SimpleExternalDisplayCase =
816 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700817 HdrNotSupportedVariant<ExternalDisplayVariant>,
818 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800819using SimpleTertiaryDisplayCase =
820 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700821 HdrNotSupportedVariant<TertiaryDisplayVariant>,
822 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800823using NonHwcVirtualDisplayCase =
824 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700825 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
826 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800827using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
828using HwcVirtualDisplayCase =
829 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700830 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800831 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800832using WideColorP3ColorimetricDisplayCase =
833 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700834 HdrNotSupportedVariant<PrimaryDisplayVariant>,
835 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800836using Hdr10PlusDisplayCase =
837 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
838 Hdr10SupportedVariant<PrimaryDisplayVariant>,
839 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800840using Hdr10DisplayCase =
841 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700842 Hdr10SupportedVariant<PrimaryDisplayVariant>,
843 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800844using HdrHlgDisplayCase =
845 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700846 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
847 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800848using HdrDolbyVisionDisplayCase =
849 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700850 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
851 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
852using HdrSmpte2086DisplayCase =
853 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
854 HdrNotSupportedVariant<PrimaryDisplayVariant>,
855 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
856using HdrCta861_3_DisplayCase =
857 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
858 HdrNotSupportedVariant<PrimaryDisplayVariant>,
859 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700860
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800861/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800862 *
863 * SurfaceFlinger::onHotplugReceived
864 */
865
866TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
867 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700868 constexpr hwc2_display_t hwcDisplayId1 = 456;
869 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800870
871 // --------------------------------------------------------------------
872 // Preconditions
873
874 // Set the current sequence id for accepted events
875 mFlinger.mutableComposerSequenceId() = currentSequenceId;
876
877 // Set the main thread id so that the current thread does not appear to be
878 // the main thread.
879 mFlinger.mutableMainThreadId() = std::thread::id();
880
881 // --------------------------------------------------------------------
882 // Call Expectations
883
884 // We expect invalidate() to be invoked once to trigger display transaction
885 // processing.
886 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
887
888 // --------------------------------------------------------------------
889 // Invocation
890
891 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700892 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
893 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800894
895 // --------------------------------------------------------------------
896 // Postconditions
897
898 // The display transaction needed flag should be set.
899 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
900
901 // All events should be in the pending event queue.
902 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
903 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700904 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800905 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700906 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800907 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
908}
909
910TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
911 constexpr int currentSequenceId = 123;
912 constexpr int otherSequenceId = 321;
913 constexpr hwc2_display_t displayId = 456;
914
915 // --------------------------------------------------------------------
916 // Preconditions
917
918 // Set the current sequence id for accepted events
919 mFlinger.mutableComposerSequenceId() = currentSequenceId;
920
921 // Set the main thread id so that the current thread does not appear to be
922 // the main thread.
923 mFlinger.mutableMainThreadId() = std::thread::id();
924
925 // --------------------------------------------------------------------
926 // Call Expectations
927
928 // We do not expect any calls to invalidate().
929 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
930
931 // --------------------------------------------------------------------
932 // Invocation
933
934 // Call with an unexpected sequence id
935 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
936
937 // --------------------------------------------------------------------
938 // Postconditions
939
940 // The display transaction needed flag should not be set
941 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
942
943 // There should be no pending events
944 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
945}
946
947TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
948 constexpr int currentSequenceId = 123;
949 constexpr hwc2_display_t displayId1 = 456;
950
951 // --------------------------------------------------------------------
952 // Note:
953 // --------------------------------------------------------------------
954 // This test case is a bit tricky. We want to verify that
955 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
956 // don't really want to provide coverage for everything the later function
957 // does as there are specific tests for it.
958 // --------------------------------------------------------------------
959
960 // --------------------------------------------------------------------
961 // Preconditions
962
963 // Set the current sequence id for accepted events
964 mFlinger.mutableComposerSequenceId() = currentSequenceId;
965
966 // Set the main thread id so that the current thread does appear to be the
967 // main thread.
968 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
969
970 // --------------------------------------------------------------------
971 // Call Expectations
972
973 // We expect invalidate() to be invoked once to trigger display transaction
974 // processing.
975 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
976
977 // --------------------------------------------------------------------
978 // Invocation
979
980 // Simulate a disconnect on a display id that is not connected. This should
981 // be enqueued by onHotplugReceived(), and dequeued by
982 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
983 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
984
985 // --------------------------------------------------------------------
986 // Postconditions
987
988 // The display transaction needed flag should be set.
989 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
990
991 // There should be no event queued on return, as it should have been
992 // processed.
993 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
994}
995
996/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -0800997 * SurfaceFlinger::createDisplay
998 */
999
1000TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1001 const String8 name("virtual.test");
1002
1003 // --------------------------------------------------------------------
1004 // Call Expectations
1005
1006 // The call should notify the interceptor that a display was created.
1007 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1008
1009 // --------------------------------------------------------------------
1010 // Invocation
1011
1012 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1013
1014 // --------------------------------------------------------------------
1015 // Postconditions
1016
1017 // The display should have been added to the current state
1018 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1019 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001020 EXPECT_TRUE(display.isVirtual());
1021 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001022 EXPECT_EQ(name.string(), display.displayName);
1023
1024 // --------------------------------------------------------------------
1025 // Cleanup conditions
1026
1027 // Destroying the display invalidates the display state.
1028 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1029}
1030
1031TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1032 const String8 name("virtual.test");
1033
1034 // --------------------------------------------------------------------
1035 // Call Expectations
1036
1037 // The call should notify the interceptor that a display was created.
1038 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1039
1040 // --------------------------------------------------------------------
1041 // Invocation
1042
1043 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1044
1045 // --------------------------------------------------------------------
1046 // Postconditions
1047
1048 // The display should have been added to the current state
1049 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1050 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001051 EXPECT_TRUE(display.isVirtual());
1052 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001053 EXPECT_EQ(name.string(), display.displayName);
1054
1055 // --------------------------------------------------------------------
1056 // Cleanup conditions
1057
1058 // Destroying the display invalidates the display state.
1059 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1060}
1061
1062/* ------------------------------------------------------------------------
1063 * SurfaceFlinger::destroyDisplay
1064 */
1065
1066TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1067 using Case = NonHwcVirtualDisplayCase;
1068
1069 // --------------------------------------------------------------------
1070 // Preconditions
1071
1072 // A virtual display exists
1073 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1074 existing.inject();
1075
1076 // --------------------------------------------------------------------
1077 // Call Expectations
1078
1079 // The call should notify the interceptor that a display was created.
1080 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1081
1082 // Destroying the display invalidates the display state.
1083 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1084
1085 // --------------------------------------------------------------------
1086 // Invocation
1087
1088 mFlinger.destroyDisplay(existing.token());
1089
1090 // --------------------------------------------------------------------
1091 // Postconditions
1092
1093 // The display should have been removed from the current state
1094 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1095
1096 // Ths display should still exist in the drawing state
1097 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1098
1099 // The display transaction needed flasg should be set
1100 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1101}
1102
1103TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1104 // --------------------------------------------------------------------
1105 // Preconditions
1106
1107 sp<BBinder> displayToken = new BBinder();
1108
1109 // --------------------------------------------------------------------
1110 // Invocation
1111
1112 mFlinger.destroyDisplay(displayToken);
1113}
1114
1115/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001116 * SurfaceFlinger::resetDisplayState
1117 */
1118
1119TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1120 using Case = NonHwcVirtualDisplayCase;
1121
1122 // --------------------------------------------------------------------
1123 // Preconditions
1124
1125 // vsync is enabled and available
Ana Krulecafb45842019-02-13 13:33:03 -08001126 mScheduler->mutablePrimaryHWVsyncEnabled() = true;
1127 mScheduler->mutableHWVsyncAvailable() = true;
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001128
1129 // A display exists
1130 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1131 existing.inject();
1132
1133 // --------------------------------------------------------------------
1134 // Call Expectations
1135
1136 // The call disable vsyncs
1137 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1138
Lloyd Pique41be5d22018-06-21 13:11:48 -07001139 // The call ends any display resyncs
1140 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1141
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001142 // --------------------------------------------------------------------
1143 // Invocation
1144
1145 mFlinger.resetDisplayState();
1146
1147 // --------------------------------------------------------------------
1148 // Postconditions
1149
1150 // vsyncs should be off and not available.
Ana Krulecafb45842019-02-13 13:33:03 -08001151 EXPECT_FALSE(mScheduler->mutablePrimaryHWVsyncEnabled());
1152 EXPECT_FALSE(mScheduler->mutableHWVsyncAvailable());
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001153
1154 // The display should have been removed from the display map.
1155 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1156
1157 // The display should still exist in the current state
1158 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1159
1160 // The display should have been removed from the drawing state
1161 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1162}
1163
1164/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001165 * DisplayDevice::GetBestColorMode
1166 */
1167class GetBestColorModeTest : public DisplayTransactionTest {
1168public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001169 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001170
Valerie Hau9758ae02018-10-09 16:05:09 -07001171 GetBestColorModeTest()
1172 : DisplayTransactionTest(),
Dominik Laskowski075d3172018-05-24 15:50:06 -07001173 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */,
1174 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001175
1176 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1177
1178 void addHwcColorModesMapping(ui::ColorMode colorMode,
1179 std::vector<ui::RenderIntent> renderIntents) {
1180 mHwcColorModes[colorMode] = renderIntents;
1181 }
1182
1183 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1184
1185 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1186
1187 void getBestColorMode() {
1188 mInjector.setHwcColorModes(mHwcColorModes);
1189 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001190 mInjector.setNativeWindow(mNativeWindow);
1191
1192 // Creating a DisplayDevice requires getting default dimensions from the
1193 // native window.
1194 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1195 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1196 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1197 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001198 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1199 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1200 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001201 auto displayDevice = mInjector.inject();
1202
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001203 displayDevice->getCompositionDisplay()
1204 ->getDisplayColorProfile()
1205 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1206 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001207 }
1208
1209 ui::Dataspace mOutDataspace;
1210 ui::ColorMode mOutColorMode;
1211 ui::RenderIntent mOutRenderIntent;
1212
1213private:
1214 ui::Dataspace mInputDataspace;
1215 ui::RenderIntent mInputRenderIntent;
1216 bool mHasWideColorGamut = false;
1217 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1218 FakeDisplayDeviceInjector mInjector;
1219};
1220
1221TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1222 addHwcColorModesMapping(ui::ColorMode::SRGB,
1223 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1224 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1225 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1226 setHasWideColorGamut(true);
1227
1228 getBestColorMode();
1229
Peiyong Lin14724e62018-12-05 07:27:30 -08001230 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001231 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1232 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1233}
1234
1235TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1236 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1237 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1238 addHwcColorModesMapping(ui::ColorMode::SRGB,
1239 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1240 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1241 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1242 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1243 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1244 setHasWideColorGamut(true);
1245
1246 getBestColorMode();
1247
1248 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1249 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1250 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1251}
1252
1253TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1254 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1255 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1256 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1257 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1258 setHasWideColorGamut(true);
1259
1260 getBestColorMode();
1261
1262 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1263 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1264 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1265}
1266
1267/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001268 * SurfaceFlinger::getDisplayNativePrimaries
1269 */
1270
1271class GetDisplayNativePrimaries : public DisplayTransactionTest {
1272public:
1273 GetDisplayNativePrimaries();
1274 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1275 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1276
1277private:
1278 static constexpr float mStartingTestValue = 1.0f;
1279};
1280
1281GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1282 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1283 injectFakeNativeWindowSurfaceFactory();
1284}
1285
1286void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1287 ui::DisplayPrimaries& primaries) {
1288 float startingVal = mStartingTestValue;
1289 primaries.red.X = startingVal++;
1290 primaries.red.Y = startingVal++;
1291 primaries.red.Z = startingVal++;
1292 primaries.green.X = startingVal++;
1293 primaries.green.Y = startingVal++;
1294 primaries.green.Z = startingVal++;
1295 primaries.blue.X = startingVal++;
1296 primaries.blue.Y = startingVal++;
1297 primaries.blue.Z = startingVal++;
1298 primaries.white.X = startingVal++;
1299 primaries.white.Y = startingVal++;
1300 primaries.white.Z = startingVal++;
1301}
1302
1303void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1304 const ui::DisplayPrimaries& primaries) {
1305 float startingVal = mStartingTestValue;
1306 EXPECT_EQ(primaries.red.X, startingVal++);
1307 EXPECT_EQ(primaries.red.Y, startingVal++);
1308 EXPECT_EQ(primaries.red.Z, startingVal++);
1309 EXPECT_EQ(primaries.green.X, startingVal++);
1310 EXPECT_EQ(primaries.green.Y, startingVal++);
1311 EXPECT_EQ(primaries.green.Z, startingVal++);
1312 EXPECT_EQ(primaries.blue.X, startingVal++);
1313 EXPECT_EQ(primaries.blue.Y, startingVal++);
1314 EXPECT_EQ(primaries.blue.Z, startingVal++);
1315 EXPECT_EQ(primaries.white.X, startingVal++);
1316 EXPECT_EQ(primaries.white.Y, startingVal++);
1317 EXPECT_EQ(primaries.white.Z, startingVal++);
1318}
1319
1320TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1321 ui::DisplayPrimaries primaries;
1322 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1323}
1324
Daniel Solomon42d04562019-01-20 21:03:19 -08001325TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1326 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1327 injector.inject();
1328 auto internalDisplayToken = injector.token();
1329
1330 ui::DisplayPrimaries expectedPrimaries;
1331 populateDummyDisplayNativePrimaries(expectedPrimaries);
1332 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1333
1334 ui::DisplayPrimaries primaries;
1335 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1336
1337 checkDummyDisplayNativePrimaries(primaries);
1338}
1339
1340TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1341 sp<BBinder> notInternalDisplayToken = new BBinder();
1342
1343 ui::DisplayPrimaries primaries;
1344 populateDummyDisplayNativePrimaries(primaries);
1345 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1346
1347 // Check primaries argument wasn't modified in case of failure
1348 checkDummyDisplayNativePrimaries(primaries);
1349}
1350
1351/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001352 * SurfaceFlinger::setupNewDisplayDeviceInternal
1353 */
1354
1355class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1356public:
1357 template <typename T>
1358 void setupNewDisplayDeviceInternalTest();
1359};
1360
1361template <typename Case>
1362void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1363 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001364 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1365 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001366 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001367
1368 // --------------------------------------------------------------------
1369 // Preconditions
1370
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001371 // Wide color displays support is configured appropriately
1372 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001373
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001374 // The display is setup with the HWC.
1375 Case::Display::injectHwcDisplay(this);
1376
1377 // SurfaceFlinger will use a test-controlled factory for native window
1378 // surfaces.
1379 injectFakeNativeWindowSurfaceFactory();
1380
1381 // --------------------------------------------------------------------
1382 // Call Expectations
1383
1384 // Various native window calls will be made.
1385 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001386 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001387 Case::WideColorSupport::setupComposerCallExpectations(this);
1388 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001389 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001390
1391 // --------------------------------------------------------------------
1392 // Invocation
1393
1394 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001395 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1396 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001397 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1398
Dominik Laskowski075d3172018-05-24 15:50:06 -07001399 auto device =
1400 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1401 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001402
1403 // --------------------------------------------------------------------
1404 // Postconditions
1405
1406 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001407 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1408 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001409 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001410 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001411 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1412 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1413 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001414 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001415 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1416 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1417 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001418 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1419 // remapped, and the test only ever sets up one config. If there were an error
1420 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
1421 EXPECT_EQ(0, device->getActiveConfig());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001422 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1423 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001424}
1425
1426TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1427 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1428}
1429
1430TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1431 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1432}
1433
1434TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1435 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1436}
1437
1438TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001439 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001440
Dominik Laskowski075d3172018-05-24 15:50:06 -07001441 // Insert display data so that the HWC thinks it created the virtual display.
1442 const auto displayId = Case::Display::DISPLAY_ID::get();
1443 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001444 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001445
1446 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001447}
1448
1449TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1450 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1451}
1452
Valerie Haue9e843a2018-12-18 13:39:23 -08001453TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1454 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1455}
1456
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001457TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1458 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1459}
1460
1461TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1462 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1463}
1464
1465TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1466 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1467}
1468
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001469TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1470 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1471}
1472
1473TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1474 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1475}
1476
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001477/* ------------------------------------------------------------------------
1478 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1479 */
1480
1481class HandleTransactionLockedTest : public DisplayTransactionTest {
1482public:
1483 template <typename Case>
1484 void setupCommonPreconditions();
1485
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001486 template <typename Case, bool connected>
1487 static void expectHotplugReceived(mock::EventThread*);
1488
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001489 template <typename Case>
1490 void setupCommonCallExpectationsForConnectProcessing();
1491
1492 template <typename Case>
1493 void setupCommonCallExpectationsForDisconnectProcessing();
1494
1495 template <typename Case>
1496 void processesHotplugConnectCommon();
1497
1498 template <typename Case>
1499 void ignoresHotplugConnectCommon();
1500
1501 template <typename Case>
1502 void processesHotplugDisconnectCommon();
1503
1504 template <typename Case>
1505 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1506
1507 template <typename Case>
1508 void verifyPhysicalDisplayIsConnected();
1509
1510 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1511};
1512
1513template <typename Case>
1514void HandleTransactionLockedTest::setupCommonPreconditions() {
1515 // Wide color displays support is configured appropriately
1516 Case::WideColorSupport::injectConfigChange(this);
1517
1518 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1519 injectFakeBufferQueueFactory();
1520
1521 // SurfaceFlinger will use a test-controlled factory for native window
1522 // surfaces.
1523 injectFakeNativeWindowSurfaceFactory();
1524}
1525
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001526template <typename Case, bool connected>
1527void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1528 const auto convert = [](auto physicalDisplayId) {
1529 return std::make_optional(DisplayId{physicalDisplayId});
1530 };
1531
1532 EXPECT_CALL(*eventThread,
1533 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1534 .Times(1);
1535}
1536
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001537template <typename Case>
1538void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1539 Case::Display::setupHwcHotplugCallExpectations(this);
1540
1541 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1542 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1543 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1544 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1545
1546 Case::WideColorSupport::setupComposerCallExpectations(this);
1547 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001548 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001549
1550 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001551 expectHotplugReceived<Case, true>(mEventThread);
1552 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001553}
1554
1555template <typename Case>
1556void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1557 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001558
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001559 expectHotplugReceived<Case, false>(mEventThread);
1560 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001561}
1562
1563template <typename Case>
1564void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1565 // The display device should have been set up in the list of displays.
1566 ASSERT_TRUE(hasDisplayDevice(displayToken));
1567 const auto& device = getDisplayDevice(displayToken);
1568 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001569 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001570
1571 // The display should have been set up in the current display state
1572 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1573 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001574 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1575 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1576 : Case::Display::DISPLAY_ID::get(),
1577 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001578
1579 // The display should have been set up in the drawing display state
1580 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1581 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001582 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1583 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1584 : Case::Display::DISPLAY_ID::get(),
1585 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001586}
1587
1588template <typename Case>
1589void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1590 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001591 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001592
Dominik Laskowski075d3172018-05-24 15:50:06 -07001593 // SF should have a display token.
1594 const auto displayId = Case::Display::DISPLAY_ID::get();
1595 ASSERT_TRUE(displayId);
1596 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1597 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001598
1599 verifyDisplayIsConnected<Case>(displayToken);
1600}
1601
1602void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1603 EXPECT_FALSE(hasDisplayDevice(displayToken));
1604 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1605 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1606}
1607
1608template <typename Case>
1609void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1610 // --------------------------------------------------------------------
1611 // Preconditions
1612
1613 setupCommonPreconditions<Case>();
1614
1615 // A hotplug connect event is enqueued for a display
1616 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001617
1618 // --------------------------------------------------------------------
1619 // Call Expectations
1620
1621 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001622
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001623 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001624
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001625 // --------------------------------------------------------------------
1626 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001627
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001628 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001629
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001630 // --------------------------------------------------------------------
1631 // Postconditions
1632
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001633 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001634
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001635 // --------------------------------------------------------------------
1636 // Cleanup conditions
1637
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001638 EXPECT_CALL(*mComposer,
1639 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001640 .WillOnce(Return(Error::NONE));
1641 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001642}
1643
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001644template <typename Case>
1645void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1646 // --------------------------------------------------------------------
1647 // Preconditions
1648
1649 setupCommonPreconditions<Case>();
1650
1651 // A hotplug connect event is enqueued for a display
1652 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1653
1654 // --------------------------------------------------------------------
1655 // Invocation
1656
1657 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1658
1659 // --------------------------------------------------------------------
1660 // Postconditions
1661
1662 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001663 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001664}
1665
1666template <typename Case>
1667void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1668 // --------------------------------------------------------------------
1669 // Preconditions
1670
1671 setupCommonPreconditions<Case>();
1672
1673 // A hotplug disconnect event is enqueued for a display
1674 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1675
1676 // The display is already completely set up.
1677 Case::Display::injectHwcDisplay(this);
1678 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1679 existing.inject();
1680
1681 // --------------------------------------------------------------------
1682 // Call Expectations
1683
1684 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001685 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1686 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001687
1688 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1689
1690 // --------------------------------------------------------------------
1691 // Invocation
1692
1693 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1694
1695 // --------------------------------------------------------------------
1696 // Postconditions
1697
1698 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001699 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001700
Dominik Laskowski075d3172018-05-24 15:50:06 -07001701 // SF should not have a display token.
1702 const auto displayId = Case::Display::DISPLAY_ID::get();
1703 ASSERT_TRUE(displayId);
1704 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001705
1706 // The existing token should have been removed
1707 verifyDisplayIsNotConnected(existing.token());
1708}
1709
1710TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1711 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1712}
1713
1714TEST_F(HandleTransactionLockedTest,
1715 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1716 // Inject an external display.
1717 ExternalDisplayVariant::injectHwcDisplay(this);
1718
1719 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1720}
1721
1722TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1723 // Inject a primary display.
1724 PrimaryDisplayVariant::injectHwcDisplay(this);
1725
1726 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1727}
1728
1729TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1730 // Inject both a primary and external display.
1731 PrimaryDisplayVariant::injectHwcDisplay(this);
1732 ExternalDisplayVariant::injectHwcDisplay(this);
1733
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001734 // TODO: This is an unnecessary call.
1735 EXPECT_CALL(*mComposer,
1736 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
1737 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
1738 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
1739 Return(Error::NONE)));
1740
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001741 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1742
1743 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1744}
1745
1746TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1747 // Inject a primary display.
1748 PrimaryDisplayVariant::injectHwcDisplay(this);
1749
1750 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1751
1752 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1753}
1754
1755TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1756 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1757}
1758
1759TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1760 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1761}
1762
1763TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1764 using Case = SimplePrimaryDisplayCase;
1765
1766 // --------------------------------------------------------------------
1767 // Preconditions
1768
1769 setupCommonPreconditions<Case>();
1770
1771 // A hotplug connect event is enqueued for a display
1772 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1773 // A hotplug disconnect event is also enqueued for the same display
1774 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1775
1776 // --------------------------------------------------------------------
1777 // Call Expectations
1778
1779 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1780
1781 setupCommonCallExpectationsForConnectProcessing<Case>();
1782 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1783
1784 EXPECT_CALL(*mComposer,
1785 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1786 .WillOnce(Return(Error::NONE));
1787 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1788
1789 // --------------------------------------------------------------------
1790 // Invocation
1791
1792 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1793
1794 // --------------------------------------------------------------------
1795 // Postconditions
1796
1797 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001798 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001799
Dominik Laskowski075d3172018-05-24 15:50:06 -07001800 // SF should not have a display token.
1801 const auto displayId = Case::Display::DISPLAY_ID::get();
1802 ASSERT_TRUE(displayId);
1803 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001804}
1805
1806TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1807 using Case = SimplePrimaryDisplayCase;
1808
1809 // --------------------------------------------------------------------
1810 // Preconditions
1811
1812 setupCommonPreconditions<Case>();
1813
1814 // The display is already completely set up.
1815 Case::Display::injectHwcDisplay(this);
1816 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1817 existing.inject();
1818
1819 // A hotplug disconnect event is enqueued for a display
1820 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1821 // A hotplug connect event is also enqueued for the same display
1822 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1823
1824 // --------------------------------------------------------------------
1825 // Call Expectations
1826
1827 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1828
1829 setupCommonCallExpectationsForConnectProcessing<Case>();
1830 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1831
1832 // --------------------------------------------------------------------
1833 // Invocation
1834
1835 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1836
1837 // --------------------------------------------------------------------
1838 // Postconditions
1839
1840 // The existing token should have been removed
1841 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001842 const auto displayId = Case::Display::DISPLAY_ID::get();
1843 ASSERT_TRUE(displayId);
1844 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1845 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001846
1847 // A new display should be connected in its place
1848
1849 verifyPhysicalDisplayIsConnected<Case>();
1850
1851 // --------------------------------------------------------------------
1852 // Cleanup conditions
1853
1854 EXPECT_CALL(*mComposer,
1855 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1856 .WillOnce(Return(Error::NONE));
1857 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1858}
1859
1860TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1861 using Case = HwcVirtualDisplayCase;
1862
1863 // --------------------------------------------------------------------
1864 // Preconditions
1865
1866 // The HWC supports at least one virtual display
1867 injectMockComposer(1);
1868
1869 setupCommonPreconditions<Case>();
1870
1871 // A virtual display was added to the current state, and it has a
1872 // surface(producer)
1873 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07001874
Dominik Laskowski075d3172018-05-24 15:50:06 -07001875 DisplayDeviceState state;
1876 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001877
1878 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001879 state.surface = surface;
1880 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001881
1882 // --------------------------------------------------------------------
1883 // Call Expectations
1884
1885 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1886 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1887
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001888 EXPECT_CALL(*mComposer, getDisplayCapabilities(Case::Display::HWC_DISPLAY_ID, _))
1889 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
1890 Return(Error::NONE)));
1891
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001892 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1893 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1894 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1895 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1896 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1897 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1898 Return(NO_ERROR)));
1899 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1900 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1901
1902 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1903
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001904 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001905 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1906
1907 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1908 Case::WideColorSupport::setupComposerCallExpectations(this);
1909 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001910 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001911
1912 // --------------------------------------------------------------------
1913 // Invocation
1914
1915 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1916
1917 // --------------------------------------------------------------------
1918 // Postconditions
1919
1920 // The display device should have been set up in the list of displays.
1921 verifyDisplayIsConnected<Case>(displayToken);
1922
1923 // --------------------------------------------------------------------
1924 // Cleanup conditions
1925
1926 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1927 .WillOnce(Return(Error::NONE));
1928 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08001929
1930 // Cleanup
1931 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
1932 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001933}
1934
1935TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1936 using Case = HwcVirtualDisplayCase;
1937
1938 // --------------------------------------------------------------------
1939 // Preconditions
1940
1941 // The HWC supports at least one virtual display
1942 injectMockComposer(1);
1943
1944 setupCommonPreconditions<Case>();
1945
1946 // A virtual display was added to the current state, but it does not have a
1947 // surface.
1948 sp<BBinder> displayToken = new BBinder();
1949
Dominik Laskowski075d3172018-05-24 15:50:06 -07001950 DisplayDeviceState state;
1951 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001952
Dominik Laskowski075d3172018-05-24 15:50:06 -07001953 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001954
1955 // --------------------------------------------------------------------
1956 // Call Expectations
1957
1958 // --------------------------------------------------------------------
1959 // Invocation
1960
1961 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1962
1963 // --------------------------------------------------------------------
1964 // Postconditions
1965
1966 // There will not be a display device set up.
1967 EXPECT_FALSE(hasDisplayDevice(displayToken));
1968
1969 // The drawing display state will be set from the current display state.
1970 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1971 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001972 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001973}
1974
1975TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1976 using Case = HwcVirtualDisplayCase;
1977
1978 // --------------------------------------------------------------------
1979 // Preconditions
1980
1981 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07001982 const auto displayId = Case::Display::DISPLAY_ID::get();
1983 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001984 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001985 Case::Display::injectHwcDisplay(this);
1986 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1987 existing.inject();
1988 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1989
1990 // --------------------------------------------------------------------
1991 // Call Expectations
1992
1993 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1994
1995 // --------------------------------------------------------------------
1996 // Invocation
1997
1998 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1999
2000 // --------------------------------------------------------------------
2001 // Postconditions
2002
2003 // The existing token should have been removed
2004 verifyDisplayIsNotConnected(existing.token());
2005}
2006
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002007TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2008 using Case = NonHwcVirtualDisplayCase;
2009
2010 constexpr uint32_t oldLayerStack = 0u;
2011 constexpr uint32_t newLayerStack = 123u;
2012
2013 // --------------------------------------------------------------------
2014 // Preconditions
2015
2016 // A display is set up
2017 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2018 display.inject();
2019
2020 // There is a change to the layerStack state
2021 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2022 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2023
2024 // --------------------------------------------------------------------
2025 // Invocation
2026
2027 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2028
2029 // --------------------------------------------------------------------
2030 // Postconditions
2031
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002032 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002033}
2034
2035TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2036 using Case = NonHwcVirtualDisplayCase;
2037
2038 constexpr int oldTransform = 0;
2039 constexpr int newTransform = 2;
2040
2041 // --------------------------------------------------------------------
2042 // Preconditions
2043
2044 // A display is set up
2045 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2046 display.inject();
2047
2048 // There is a change to the orientation state
2049 display.mutableDrawingDisplayState().orientation = oldTransform;
2050 display.mutableCurrentDisplayState().orientation = newTransform;
2051
2052 // --------------------------------------------------------------------
2053 // Invocation
2054
2055 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2056
2057 // --------------------------------------------------------------------
2058 // Postconditions
2059
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002060 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002061}
2062
2063TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2064 using Case = NonHwcVirtualDisplayCase;
2065
2066 const Rect oldViewport(0, 0, 0, 0);
2067 const Rect newViewport(0, 0, 123, 456);
2068
2069 // --------------------------------------------------------------------
2070 // Preconditions
2071
2072 // A display is set up
2073 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2074 display.inject();
2075
2076 // There is a change to the viewport state
2077 display.mutableDrawingDisplayState().viewport = oldViewport;
2078 display.mutableCurrentDisplayState().viewport = newViewport;
2079
2080 // --------------------------------------------------------------------
2081 // Invocation
2082
2083 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2084
2085 // --------------------------------------------------------------------
2086 // Postconditions
2087
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002088 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002089}
2090
2091TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2092 using Case = NonHwcVirtualDisplayCase;
2093
2094 const Rect oldFrame(0, 0, 0, 0);
2095 const Rect newFrame(0, 0, 123, 456);
2096
2097 // --------------------------------------------------------------------
2098 // Preconditions
2099
2100 // A display is set up
2101 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2102 display.inject();
2103
2104 // There is a change to the viewport state
2105 display.mutableDrawingDisplayState().frame = oldFrame;
2106 display.mutableCurrentDisplayState().frame = newFrame;
2107
2108 // --------------------------------------------------------------------
2109 // Invocation
2110
2111 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2112
2113 // --------------------------------------------------------------------
2114 // Postconditions
2115
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002116 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002117}
2118
2119TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2120 using Case = NonHwcVirtualDisplayCase;
2121
2122 constexpr int oldWidth = 0;
2123 constexpr int oldHeight = 10;
2124 constexpr int newWidth = 123;
2125
2126 // --------------------------------------------------------------------
2127 // Preconditions
2128
2129 // A display is set up
2130 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002131 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002132 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002133 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2134 display.setNativeWindow(nativeWindow);
2135 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002136 // Setup injection expections
2137 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2138 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2139 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2140 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002141 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2142 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2143 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002144 display.inject();
2145
2146 // There is a change to the viewport state
2147 display.mutableDrawingDisplayState().width = oldWidth;
2148 display.mutableDrawingDisplayState().height = oldHeight;
2149 display.mutableCurrentDisplayState().width = newWidth;
2150 display.mutableCurrentDisplayState().height = oldHeight;
2151
2152 // --------------------------------------------------------------------
2153 // Call Expectations
2154
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002155 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002156
2157 // --------------------------------------------------------------------
2158 // Invocation
2159
2160 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2161}
2162
2163TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2164 using Case = NonHwcVirtualDisplayCase;
2165
2166 constexpr int oldWidth = 0;
2167 constexpr int oldHeight = 10;
2168 constexpr int newHeight = 123;
2169
2170 // --------------------------------------------------------------------
2171 // Preconditions
2172
2173 // A display is set up
2174 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002175 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002176 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002177 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2178 display.setNativeWindow(nativeWindow);
2179 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002180 // Setup injection expections
2181 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2182 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2183 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2184 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002185 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2186 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2187 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002188 display.inject();
2189
2190 // There is a change to the viewport state
2191 display.mutableDrawingDisplayState().width = oldWidth;
2192 display.mutableDrawingDisplayState().height = oldHeight;
2193 display.mutableCurrentDisplayState().width = oldWidth;
2194 display.mutableCurrentDisplayState().height = newHeight;
2195
2196 // --------------------------------------------------------------------
2197 // Call Expectations
2198
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002199 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002200
2201 // --------------------------------------------------------------------
2202 // Invocation
2203
2204 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2205}
2206
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002207/* ------------------------------------------------------------------------
2208 * SurfaceFlinger::setDisplayStateLocked
2209 */
2210
2211TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2212 // --------------------------------------------------------------------
2213 // Preconditions
2214
2215 // We have an unknown display token not associated with a known display
2216 sp<BBinder> displayToken = new BBinder();
2217
2218 // The requested display state references the unknown display.
2219 DisplayState state;
2220 state.what = DisplayState::eLayerStackChanged;
2221 state.token = displayToken;
2222 state.layerStack = 456;
2223
2224 // --------------------------------------------------------------------
2225 // Invocation
2226
2227 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2228
2229 // --------------------------------------------------------------------
2230 // Postconditions
2231
2232 // The returned flags are empty
2233 EXPECT_EQ(0u, flags);
2234
2235 // The display token still doesn't match anything known.
2236 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2237}
2238
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002239TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2240 using Case = SimplePrimaryDisplayCase;
2241
2242 // --------------------------------------------------------------------
2243 // Preconditions
2244
2245 // A display is already set up
2246 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2247 display.inject();
2248
2249 // No changes are made to the display
2250 DisplayState state;
2251 state.what = 0;
2252 state.token = display.token();
2253
2254 // --------------------------------------------------------------------
2255 // Invocation
2256
2257 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2258
2259 // --------------------------------------------------------------------
2260 // Postconditions
2261
2262 // The returned flags are empty
2263 EXPECT_EQ(0u, flags);
2264}
2265
2266TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2267 using Case = SimplePrimaryDisplayCase;
2268
2269 // --------------------------------------------------------------------
2270 // Preconditions
2271
2272 // A display is already set up
2273 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2274 display.inject();
2275
2276 // There is a surface that can be set.
2277 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2278
2279 // The current display state has the surface set
2280 display.mutableCurrentDisplayState().surface = surface;
2281
2282 // The incoming request sets the same surface
2283 DisplayState state;
2284 state.what = DisplayState::eSurfaceChanged;
2285 state.token = display.token();
2286 state.surface = surface;
2287
2288 // --------------------------------------------------------------------
2289 // Invocation
2290
2291 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2292
2293 // --------------------------------------------------------------------
2294 // Postconditions
2295
2296 // The returned flags are empty
2297 EXPECT_EQ(0u, flags);
2298
2299 // The current display state is unchanged.
2300 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2301}
2302
2303TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2304 using Case = SimplePrimaryDisplayCase;
2305
2306 // --------------------------------------------------------------------
2307 // Preconditions
2308
2309 // A display is already set up
2310 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2311 display.inject();
2312
2313 // There is a surface that can be set.
2314 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2315
2316 // The current display state does not have a surface
2317 display.mutableCurrentDisplayState().surface = nullptr;
2318
2319 // The incoming request sets a surface
2320 DisplayState state;
2321 state.what = DisplayState::eSurfaceChanged;
2322 state.token = display.token();
2323 state.surface = surface;
2324
2325 // --------------------------------------------------------------------
2326 // Invocation
2327
2328 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2329
2330 // --------------------------------------------------------------------
2331 // Postconditions
2332
2333 // The returned flags indicate a transaction is needed
2334 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2335
2336 // The current display layer stack state is set to the new value
2337 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2338}
2339
2340TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2341 using Case = SimplePrimaryDisplayCase;
2342
2343 // --------------------------------------------------------------------
2344 // Preconditions
2345
2346 // A display is already set up
2347 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2348 display.inject();
2349
2350 // The display has a layer stack set
2351 display.mutableCurrentDisplayState().layerStack = 456u;
2352
2353 // The incoming request sets the same layer stack
2354 DisplayState state;
2355 state.what = DisplayState::eLayerStackChanged;
2356 state.token = display.token();
2357 state.layerStack = 456u;
2358
2359 // --------------------------------------------------------------------
2360 // Invocation
2361
2362 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2363
2364 // --------------------------------------------------------------------
2365 // Postconditions
2366
2367 // The returned flags are empty
2368 EXPECT_EQ(0u, flags);
2369
2370 // The current display state is unchanged
2371 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2372}
2373
2374TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2375 using Case = SimplePrimaryDisplayCase;
2376
2377 // --------------------------------------------------------------------
2378 // Preconditions
2379
2380 // A display is set up
2381 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2382 display.inject();
2383
2384 // The display has a layer stack set
2385 display.mutableCurrentDisplayState().layerStack = 654u;
2386
2387 // The incoming request sets a different layer stack
2388 DisplayState state;
2389 state.what = DisplayState::eLayerStackChanged;
2390 state.token = display.token();
2391 state.layerStack = 456u;
2392
2393 // --------------------------------------------------------------------
2394 // Invocation
2395
2396 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2397
2398 // --------------------------------------------------------------------
2399 // Postconditions
2400
2401 // The returned flags indicate a transaction is needed
2402 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2403
2404 // The desired display state has been set to the new value.
2405 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2406}
2407
2408TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2409 using Case = SimplePrimaryDisplayCase;
2410 constexpr int initialOrientation = 180;
2411 const Rect initialFrame = {1, 2, 3, 4};
2412 const Rect initialViewport = {5, 6, 7, 8};
2413
2414 // --------------------------------------------------------------------
2415 // Preconditions
2416
2417 // A display is set up
2418 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2419 display.inject();
2420
2421 // The current display state projection state is all set
2422 display.mutableCurrentDisplayState().orientation = initialOrientation;
2423 display.mutableCurrentDisplayState().frame = initialFrame;
2424 display.mutableCurrentDisplayState().viewport = initialViewport;
2425
2426 // The incoming request sets the same projection state
2427 DisplayState state;
2428 state.what = DisplayState::eDisplayProjectionChanged;
2429 state.token = display.token();
2430 state.orientation = initialOrientation;
2431 state.frame = initialFrame;
2432 state.viewport = initialViewport;
2433
2434 // --------------------------------------------------------------------
2435 // Invocation
2436
2437 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2438
2439 // --------------------------------------------------------------------
2440 // Postconditions
2441
2442 // The returned flags are empty
2443 EXPECT_EQ(0u, flags);
2444
2445 // The current display state is unchanged
2446 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2447
2448 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2449 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2450}
2451
2452TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2453 using Case = SimplePrimaryDisplayCase;
2454 constexpr int initialOrientation = 90;
2455 constexpr int desiredOrientation = 180;
2456
2457 // --------------------------------------------------------------------
2458 // Preconditions
2459
2460 // A display is set up
2461 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2462 display.inject();
2463
2464 // The current display state has an orientation set
2465 display.mutableCurrentDisplayState().orientation = initialOrientation;
2466
2467 // The incoming request sets a different orientation
2468 DisplayState state;
2469 state.what = DisplayState::eDisplayProjectionChanged;
2470 state.token = display.token();
2471 state.orientation = desiredOrientation;
2472
2473 // --------------------------------------------------------------------
2474 // Invocation
2475
2476 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2477
2478 // --------------------------------------------------------------------
2479 // Postconditions
2480
2481 // The returned flags indicate a transaction is needed
2482 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2483
2484 // The current display state has the new value.
2485 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2486}
2487
2488TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2489 using Case = SimplePrimaryDisplayCase;
2490 const Rect initialFrame = {0, 0, 0, 0};
2491 const Rect desiredFrame = {5, 6, 7, 8};
2492
2493 // --------------------------------------------------------------------
2494 // Preconditions
2495
2496 // A display is set up
2497 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2498 display.inject();
2499
2500 // The current display state does not have a frame
2501 display.mutableCurrentDisplayState().frame = initialFrame;
2502
2503 // The incoming request sets a frame
2504 DisplayState state;
2505 state.what = DisplayState::eDisplayProjectionChanged;
2506 state.token = display.token();
2507 state.frame = desiredFrame;
2508
2509 // --------------------------------------------------------------------
2510 // Invocation
2511
2512 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2513
2514 // --------------------------------------------------------------------
2515 // Postconditions
2516
2517 // The returned flags indicate a transaction is needed
2518 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2519
2520 // The current display state has the new value.
2521 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2522}
2523
2524TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2525 using Case = SimplePrimaryDisplayCase;
2526 const Rect initialViewport = {0, 0, 0, 0};
2527 const Rect desiredViewport = {5, 6, 7, 8};
2528
2529 // --------------------------------------------------------------------
2530 // Preconditions
2531
2532 // A display is set up
2533 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2534 display.inject();
2535
2536 // The current display state does not have a viewport
2537 display.mutableCurrentDisplayState().viewport = initialViewport;
2538
2539 // The incoming request sets a viewport
2540 DisplayState state;
2541 state.what = DisplayState::eDisplayProjectionChanged;
2542 state.token = display.token();
2543 state.viewport = desiredViewport;
2544
2545 // --------------------------------------------------------------------
2546 // Invocation
2547
2548 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2549
2550 // --------------------------------------------------------------------
2551 // Postconditions
2552
2553 // The returned flags indicate a transaction is needed
2554 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2555
2556 // The current display state has the new value.
2557 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2558}
2559
2560TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2561 using Case = SimplePrimaryDisplayCase;
2562 constexpr uint32_t initialWidth = 1024;
2563 constexpr uint32_t initialHeight = 768;
2564
2565 // --------------------------------------------------------------------
2566 // Preconditions
2567
2568 // A display is set up
2569 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2570 display.inject();
2571
2572 // The current display state has a size set
2573 display.mutableCurrentDisplayState().width = initialWidth;
2574 display.mutableCurrentDisplayState().height = initialHeight;
2575
2576 // The incoming request sets the same display size
2577 DisplayState state;
2578 state.what = DisplayState::eDisplaySizeChanged;
2579 state.token = display.token();
2580 state.width = initialWidth;
2581 state.height = initialHeight;
2582
2583 // --------------------------------------------------------------------
2584 // Invocation
2585
2586 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2587
2588 // --------------------------------------------------------------------
2589 // Postconditions
2590
2591 // The returned flags are empty
2592 EXPECT_EQ(0u, flags);
2593
2594 // The current display state is unchanged
2595 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2596 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2597}
2598
2599TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2600 using Case = SimplePrimaryDisplayCase;
2601 constexpr uint32_t initialWidth = 0;
2602 constexpr uint32_t desiredWidth = 1024;
2603
2604 // --------------------------------------------------------------------
2605 // Preconditions
2606
2607 // A display is set up
2608 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2609 display.inject();
2610
2611 // The display does not yet have a width
2612 display.mutableCurrentDisplayState().width = initialWidth;
2613
2614 // The incoming request sets a display width
2615 DisplayState state;
2616 state.what = DisplayState::eDisplaySizeChanged;
2617 state.token = display.token();
2618 state.width = desiredWidth;
2619
2620 // --------------------------------------------------------------------
2621 // Invocation
2622
2623 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2624
2625 // --------------------------------------------------------------------
2626 // Postconditions
2627
2628 // The returned flags indicate a transaction is needed
2629 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2630
2631 // The current display state has the new value.
2632 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2633}
2634
2635TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2636 using Case = SimplePrimaryDisplayCase;
2637 constexpr uint32_t initialHeight = 0;
2638 constexpr uint32_t desiredHeight = 768;
2639
2640 // --------------------------------------------------------------------
2641 // Preconditions
2642
2643 // A display is set up
2644 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2645 display.inject();
2646
2647 // The display does not yet have a height
2648 display.mutableCurrentDisplayState().height = initialHeight;
2649
2650 // The incoming request sets a display height
2651 DisplayState state;
2652 state.what = DisplayState::eDisplaySizeChanged;
2653 state.token = display.token();
2654 state.height = desiredHeight;
2655
2656 // --------------------------------------------------------------------
2657 // Invocation
2658
2659 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2660
2661 // --------------------------------------------------------------------
2662 // Postconditions
2663
2664 // The returned flags indicate a transaction is needed
2665 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2666
2667 // The current display state has the new value.
2668 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2669}
2670
Lloyd Pique86016da2018-03-01 16:09:38 -08002671/* ------------------------------------------------------------------------
2672 * SurfaceFlinger::onInitializeDisplays
2673 */
2674
2675TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2676 using Case = SimplePrimaryDisplayCase;
2677
2678 // --------------------------------------------------------------------
2679 // Preconditions
2680
2681 // A primary display is set up
2682 Case::Display::injectHwcDisplay(this);
2683 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2684 primaryDisplay.inject();
2685
2686 // --------------------------------------------------------------------
2687 // Call Expectations
2688
2689 // We expect the surface interceptor to possibly be used, but we treat it as
2690 // disabled since it is called as a side effect rather than directly by this
2691 // function.
2692 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2693
2694 // We expect a call to get the active display config.
2695 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2696
2697 // We expect invalidate() to be invoked once to trigger display transaction
2698 // processing.
2699 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2700
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002701 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2702
Lloyd Pique86016da2018-03-01 16:09:38 -08002703 // --------------------------------------------------------------------
2704 // Invocation
2705
2706 mFlinger.onInitializeDisplays();
2707
2708 // --------------------------------------------------------------------
2709 // Postconditions
2710
2711 // The primary display should have a current state
2712 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2713 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2714 // The layer stack state should be set to zero
2715 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2716 // The orientation state should be set to zero
2717 EXPECT_EQ(0, primaryDisplayState.orientation);
2718
2719 // The frame state should be set to INVALID
2720 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2721
2722 // The viewport state should be set to INVALID
2723 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2724
2725 // The width and height should both be zero
2726 EXPECT_EQ(0u, primaryDisplayState.width);
2727 EXPECT_EQ(0u, primaryDisplayState.height);
2728
2729 // The display should be set to HWC_POWER_MODE_NORMAL
2730 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2731 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2732 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2733
2734 // The display refresh period should be set in the frame tracker.
2735 FrameStats stats;
2736 mFlinger.getAnimFrameTracker().getStats(&stats);
2737 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2738
2739 // The display transaction needed flag should be set.
2740 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2741
2742 // The compositor timing should be set to default values
2743 const auto& compositorTiming = mFlinger.getCompositorTiming();
2744 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2745 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2746 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2747}
2748
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002749/* ------------------------------------------------------------------------
2750 * SurfaceFlinger::setPowerModeInternal
2751 */
2752
2753// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07002754template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002755struct DozeIsSupportedVariant {
2756 static constexpr bool DOZE_SUPPORTED = true;
2757 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2758 IComposerClient::PowerMode::DOZE;
2759 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2760 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07002761
2762 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2763 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2764 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
2765 {Hwc2::DisplayCapability::DOZE})),
2766 Return(Error::NONE)));
2767 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002768};
2769
Peiyong Lined531a32018-10-26 18:27:56 -07002770template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002771// Used when we simulate a display that does not support doze.
2772struct DozeNotSupportedVariant {
2773 static constexpr bool DOZE_SUPPORTED = false;
2774 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2775 IComposerClient::PowerMode::ON;
2776 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2777 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07002778
2779 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2780 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2781 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
2782 Return(Error::NONE)));
2783 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002784};
2785
2786struct EventThreadBaseSupportedVariant {
2787 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
2788 // The event control thread should not be notified.
2789 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
2790
2791 // The event thread should not be notified.
2792 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
2793 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
2794 }
2795};
2796
2797struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
2798 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2799 // These calls are only expected for the primary display.
2800
2801 // Instead expect no calls.
2802 setupEventAndEventControlThreadNoCallExpectations(test);
2803 }
2804
2805 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2806 // These calls are only expected for the primary display.
2807
2808 // Instead expect no calls.
2809 setupEventAndEventControlThreadNoCallExpectations(test);
2810 }
2811};
2812
2813struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
2814 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2815 // The event control thread should be notified to enable vsyncs
2816 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
2817
2818 // The event thread should be notified that the screen was acquired.
2819 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
2820 }
2821
2822 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2823 // There should be a call to setVsyncEnabled(false)
2824 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
2825
2826 // The event thread should not be notified that the screen was released.
2827 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
2828 }
2829};
2830
Lloyd Pique41be5d22018-06-21 13:11:48 -07002831struct DispSyncIsSupportedVariant {
2832 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
2833 EXPECT_CALL(*test->mPrimaryDispSync, reset()).Times(1);
2834 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
2835 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
2836 }
2837
2838 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
2839 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
2840 }
2841};
2842
2843struct DispSyncNotSupportedVariant {
2844 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2845
2846 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2847};
2848
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002849// --------------------------------------------------------------------
2850// Note:
2851//
2852// There are a large number of transitions we could test, however we only test a
2853// selected subset which provides complete test coverage of the implementation.
2854// --------------------------------------------------------------------
2855
2856template <int initialPowerMode, int targetPowerMode>
2857struct TransitionVariantCommon {
2858 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
2859 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
2860
2861 static void verifyPostconditions(DisplayTransactionTest*) {}
2862};
2863
2864struct TransitionOffToOnVariant
2865 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
2866 template <typename Case>
2867 static void setupCallExpectations(DisplayTransactionTest* test) {
2868 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2869 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002870 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002871 Case::setupRepaintEverythingCallExpectations(test);
2872 }
2873
2874 static void verifyPostconditions(DisplayTransactionTest* test) {
2875 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2876 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2877 }
2878};
2879
2880struct TransitionOffToDozeSuspendVariant
2881 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
2882 template <typename Case>
2883 static void setupCallExpectations(DisplayTransactionTest* test) {
2884 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2885 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2886 Case::setupRepaintEverythingCallExpectations(test);
2887 }
2888
2889 static void verifyPostconditions(DisplayTransactionTest* test) {
2890 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2891 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2892 }
2893};
2894
2895struct TransitionOnToOffVariant
2896 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
2897 template <typename Case>
2898 static void setupCallExpectations(DisplayTransactionTest* test) {
2899 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002900 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002901 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2902 }
2903
2904 static void verifyPostconditions(DisplayTransactionTest* test) {
2905 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2906 }
2907};
2908
2909struct TransitionDozeSuspendToOffVariant
2910 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
2911 template <typename Case>
2912 static void setupCallExpectations(DisplayTransactionTest* test) {
2913 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2914 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2915 }
2916
2917 static void verifyPostconditions(DisplayTransactionTest* test) {
2918 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2919 }
2920};
2921
2922struct TransitionOnToDozeVariant
2923 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
2924 template <typename Case>
2925 static void setupCallExpectations(DisplayTransactionTest* test) {
2926 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2927 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2928 }
2929};
2930
2931struct TransitionDozeSuspendToDozeVariant
2932 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
2933 template <typename Case>
2934 static void setupCallExpectations(DisplayTransactionTest* test) {
2935 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002936 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002937 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2938 }
2939};
2940
2941struct TransitionDozeToOnVariant
2942 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
2943 template <typename Case>
2944 static void setupCallExpectations(DisplayTransactionTest* test) {
2945 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2946 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2947 }
2948};
2949
2950struct TransitionDozeSuspendToOnVariant
2951 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
2952 template <typename Case>
2953 static void setupCallExpectations(DisplayTransactionTest* test) {
2954 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002955 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002956 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2957 }
2958};
2959
2960struct TransitionOnToDozeSuspendVariant
2961 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
2962 template <typename Case>
2963 static void setupCallExpectations(DisplayTransactionTest* test) {
2964 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002965 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002966 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2967 }
2968};
2969
2970struct TransitionOnToUnknownVariant
2971 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
2972 template <typename Case>
2973 static void setupCallExpectations(DisplayTransactionTest* test) {
2974 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2975 Case::setupNoComposerPowerModeCallExpectations(test);
2976 }
2977};
2978
2979// --------------------------------------------------------------------
2980// Note:
2981//
2982// Rather than testing the cartesian product of of
2983// DozeIsSupported/DozeNotSupported with all other options, we use one for one
2984// display type, and the other for another display type.
2985// --------------------------------------------------------------------
2986
2987template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07002988 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002989struct DisplayPowerCase {
2990 using Display = DisplayVariant;
2991 using Doze = DozeVariant;
2992 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07002993 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002994 using Transition = TransitionVariant;
2995
2996 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002997 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002998 auto display = Display::makeFakeExistingDisplayInjector(test);
2999 display.inject();
3000 display.mutableDisplayDevice()->setPowerMode(mode);
3001 return display;
3002 }
3003
3004 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Ana Krulecafb45842019-02-13 13:33:03 -08003005 test->mScheduler->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003006 }
3007
3008 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3009 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3010 }
3011
3012 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3013 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3014 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3015 }
3016
3017 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3018 IComposerClient::PowerMode mode) {
3019 // Any calls to get the active config will return a default value.
3020 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3021 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3022 Return(Error::NONE)));
3023
3024 // Any calls to get whether the display supports dozing will return the value set by the
3025 // policy variant.
3026 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3027 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3028
3029 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3030 }
3031
3032 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3033 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3034 }
3035};
3036
3037// A sample configuration for the primary display.
3038// In addition to having event thread support, we emulate doze support.
3039template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003040using PrimaryDisplayPowerCase =
3041 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3042 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3043 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003044
3045// A sample configuration for the external display.
3046// In addition to not having event thread support, we emulate not having doze
3047// support.
3048template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003049using ExternalDisplayPowerCase =
3050 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3051 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3052 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003053
3054class SetPowerModeInternalTest : public DisplayTransactionTest {
3055public:
3056 template <typename Case>
3057 void transitionDisplayCommon();
3058};
3059
3060template <int PowerMode>
3061struct PowerModeInitialVSyncEnabled : public std::false_type {};
3062
3063template <>
3064struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3065
3066template <>
3067struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3068
3069template <typename Case>
3070void SetPowerModeInternalTest::transitionDisplayCommon() {
3071 // --------------------------------------------------------------------
3072 // Preconditions
3073
Peiyong Lined531a32018-10-26 18:27:56 -07003074 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003075 auto display =
3076 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3077 Case::setInitialPrimaryHWVsyncEnabled(this,
3078 PowerModeInitialVSyncEnabled<
3079 Case::Transition::INITIAL_POWER_MODE>::value);
3080
3081 // --------------------------------------------------------------------
3082 // Call Expectations
3083
3084 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3085 Case::Transition::template setupCallExpectations<Case>(this);
3086
3087 // --------------------------------------------------------------------
3088 // Invocation
3089
3090 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3091 Case::Transition::TARGET_POWER_MODE);
3092
3093 // --------------------------------------------------------------------
3094 // Postconditions
3095
3096 Case::Transition::verifyPostconditions(this);
3097}
3098
3099TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3100 using Case = SimplePrimaryDisplayCase;
3101
3102 // --------------------------------------------------------------------
3103 // Preconditions
3104
3105 // A primary display device is set up
3106 Case::Display::injectHwcDisplay(this);
3107 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3108 display.inject();
3109
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003110 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003111 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3112
3113 // --------------------------------------------------------------------
3114 // Invocation
3115
3116 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3117
3118 // --------------------------------------------------------------------
3119 // Postconditions
3120
3121 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3122}
3123
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003124TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003125 using Case = HwcVirtualDisplayCase;
3126
3127 // --------------------------------------------------------------------
3128 // Preconditions
3129
Dominik Laskowski075d3172018-05-24 15:50:06 -07003130 // Insert display data so that the HWC thinks it created the virtual display.
3131 const auto displayId = Case::Display::DISPLAY_ID::get();
3132 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003133 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003134
3135 // A virtual display device is set up
3136 Case::Display::injectHwcDisplay(this);
3137 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3138 display.inject();
3139
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003140 // The display is set to HWC_POWER_MODE_NORMAL
3141 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003142
3143 // --------------------------------------------------------------------
3144 // Invocation
3145
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003146 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003147
3148 // --------------------------------------------------------------------
3149 // Postconditions
3150
3151 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3152}
3153
3154TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3155 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3156}
3157
3158TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3159 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3160}
3161
3162TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3163 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3164}
3165
3166TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3167 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3168}
3169
3170TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3171 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3172}
3173
3174TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3175 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3176}
3177
3178TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3179 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3180}
3181
3182TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3183 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3184}
3185
3186TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3187 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3188}
3189
3190TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3191 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3192}
3193
3194TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3195 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3196}
3197
3198TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3199 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3200}
3201
3202TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3203 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3204}
3205
3206TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3207 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3208}
3209
3210TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3211 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3212}
3213
3214TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3215 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3216}
3217
3218TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3219 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3220}
3221
3222TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3223 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3224}
3225
3226TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3227 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3228}
3229
3230TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3231 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3232}
3233
Lloyd Piquef58625d2017-12-19 13:22:33 -08003234} // namespace
3235} // namespace android