blob: 6659d4ac8e012b0697d0e7c327fbb87b88d40b8b [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"
Lloyd Piquef58625d2017-12-19 13:22:33 -080032#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080033#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique41be5d22018-06-21 13:11:48 -070034#include "mock/MockDispSync.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080035#include "mock/MockEventControlThread.h"
36#include "mock/MockEventThread.h"
37#include "mock/MockMessageQueue.h"
38#include "mock/MockNativeWindowSurface.h"
39#include "mock/MockSurfaceInterceptor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080040#include "mock/gui/MockGraphicBufferConsumer.h"
41#include "mock/gui/MockGraphicBufferProducer.h"
42#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080043
44namespace android {
45namespace {
46
Lloyd Piquee39cad22017-12-20 17:01:29 -080047using testing::_;
Lloyd Piquee39cad22017-12-20 17:01:29 -080048using testing::DoAll;
49using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080050using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080051using testing::Return;
52using testing::SetArgPointee;
53
Lloyd Piqued883d5a2018-04-27 19:32:30 -070054using android::Hwc2::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080055using android::Hwc2::Error;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070056using android::Hwc2::Hdr;
Lloyd Piquee39cad22017-12-20 17:01:29 -080057using android::Hwc2::IComposer;
58using android::Hwc2::IComposerClient;
Lloyd Piqued883d5a2018-04-27 19:32:30 -070059using android::Hwc2::PerFrameMetadataKey;
60using android::Hwc2::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080061
Lloyd Piquec11e0d32018-01-22 18:44:59 -080062using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
63using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080064using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080065using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080066
Lloyd Piquec11e0d32018-01-22 18:44:59 -080067constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'666;
Lloyd Piquee39cad22017-12-20 17:01:29 -080068constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080069constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080070
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080071constexpr int HWC_POWER_MODE_LEET = 1337; // An out of range power mode value
72
Lloyd Piquec11e0d32018-01-22 18:44:59 -080073/* ------------------------------------------------------------------------
74 * Boolean avoidance
75 *
76 * To make calls and template instantiations more readable, we define some
77 * local enums along with an implicit bool conversion.
78 */
79
80#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
81
Lloyd Piquec11e0d32018-01-22 18:44:59 -080082BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -070083BOOL_SUBSTITUTE(Critical);
84BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080085BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -070086BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -080087
88/* ------------------------------------------------------------------------
89 *
90 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -080091
Lloyd Piquef58625d2017-12-19 13:22:33 -080092class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -080093public:
Lloyd Piquef58625d2017-12-19 13:22:33 -080094 DisplayTransactionTest();
95 ~DisplayTransactionTest() override;
96
Lloyd Pique1fa4d462018-01-22 18:03:16 -080097 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -080098 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -080099
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800100 void injectMockComposer(int virtualDisplayCount);
101 void injectFakeBufferQueueFactory();
102 void injectFakeNativeWindowSurfaceFactory();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800103
104 // --------------------------------------------------------------------
105 // Postcondition helpers
106
Dominik Laskowski075d3172018-05-24 15:50:06 -0700107 bool hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800108 bool hasTransactionFlagSet(int flag);
109 bool hasDisplayDevice(sp<IBinder> displayToken);
110 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
111 bool hasCurrentDisplayState(sp<IBinder> displayToken);
112 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
113 bool hasDrawingDisplayState(sp<IBinder> displayToken);
114 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
115
116 // --------------------------------------------------------------------
117 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800118
Lloyd Piquef58625d2017-12-19 13:22:33 -0800119 TestableSurfaceFlinger mFlinger;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800120 mock::EventThread* mEventThread = new mock::EventThread();
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800121 mock::EventThread* mSFEventThread = new mock::EventThread();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800122 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
Alec Mouriba013fa2018-10-16 12:43:11 -0700123 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800124 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800125
126 // These mocks are created by the test, but are destroyed by SurfaceFlinger
127 // by virtue of being stored into a std::unique_ptr. However we still need
128 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700129 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800130 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800131 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
132 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Lloyd Pique41be5d22018-06-21 13:11:48 -0700133 mock::DispSync* mPrimaryDispSync = new mock::DispSync();
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800134
135 // These mocks are created only when expected to be created via a factory.
136 sp<mock::GraphicBufferConsumer> mConsumer;
137 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700138 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800139};
140
141DisplayTransactionTest::DisplayTransactionTest() {
142 const ::testing::TestInfo* const test_info =
143 ::testing::UnitTest::GetInstance()->current_test_info();
144 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800145
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800146 // Default to no wide color display support configured
147 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700148 mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800149 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
150
151 // Default to using HWC virtual displays
152 mFlinger.mutableUseHwcVirtualDisplays() = true;
153
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800154 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
155 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
156 });
157
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800158 mFlinger.setCreateNativeWindowSurface([](auto) {
159 ADD_FAILURE() << "Unexpected request to create a native window surface.";
160 return nullptr;
161 });
162
163 mFlinger.mutableEventControlThread().reset(mEventControlThread);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800164 mFlinger.mutableEventThread().reset(mEventThread);
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800165 mFlinger.mutableSFEventThread().reset(mSFEventThread);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800166 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700167 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800168 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Pique41be5d22018-06-21 13:11:48 -0700169 mFlinger.mutablePrimaryDispSync().reset(mPrimaryDispSync);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800170
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800171 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800172}
173
174DisplayTransactionTest::~DisplayTransactionTest() {
175 const ::testing::TestInfo* const test_info =
176 ::testing::UnitTest::GetInstance()->current_test_info();
177 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
178}
179
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800180void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
181 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800182 EXPECT_CALL(*mComposer, getCapabilities())
183 .WillOnce(Return(std::vector<IComposer::Capability>()));
184 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
185 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800186
Lloyd Piquee39cad22017-12-20 17:01:29 -0800187 Mock::VerifyAndClear(mComposer);
188}
189
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800190void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800191 // This setup is only expected once per test.
192 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
193
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800194 mConsumer = new mock::GraphicBufferConsumer();
195 mProducer = new mock::GraphicBufferProducer();
196
197 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
198 *outProducer = mProducer;
199 *outConsumer = mConsumer;
200 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800201}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800202
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800203void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800204 // This setup is only expected once per test.
205 ASSERT_TRUE(mNativeWindowSurface == nullptr);
206
Lloyd Pique22098362018-09-13 11:46:49 -0700207 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800208
Lloyd Pique22098362018-09-13 11:46:49 -0700209 mFlinger.setCreateNativeWindowSurface([this](auto) {
210 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
211 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800212}
213
Dominik Laskowski075d3172018-05-24 15:50:06 -0700214bool DisplayTransactionTest::hasPhysicalHwcDisplay(hwc2_display_t hwcDisplayId) {
215 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800216}
217
218bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
219 return mFlinger.mutableTransactionFlags() & flag;
220}
221
222bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700223 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800224}
225
226sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700227 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800228}
229
230bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
231 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
232}
233
234const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
235 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
236}
237
238bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
239 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
240}
241
242const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
243 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
244}
245
246/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800247 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800248 */
249
Dominik Laskowski075d3172018-05-24 15:50:06 -0700250template <typename PhysicalDisplay>
251struct PhysicalDisplayId {};
252
Dominik Laskowski34157762018-10-31 13:07:19 -0700253template <DisplayId::Type displayId>
254using VirtualDisplayId = std::integral_constant<DisplayId::Type, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700255
256struct NoDisplayId {};
257
258template <typename>
259struct IsPhysicalDisplayId : std::bool_constant<false> {};
260
261template <typename PhysicalDisplay>
262struct IsPhysicalDisplayId<PhysicalDisplayId<PhysicalDisplay>> : std::bool_constant<true> {};
263
264template <typename>
265struct DisplayIdGetter;
266
267template <typename PhysicalDisplay>
268struct DisplayIdGetter<PhysicalDisplayId<PhysicalDisplay>> {
269 static std::optional<DisplayId> get() {
270 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
271 return getFallbackDisplayId(static_cast<bool>(PhysicalDisplay::PRIMARY)
272 ? HWC_DISPLAY_PRIMARY
273 : HWC_DISPLAY_EXTERNAL);
274 }
275
276 const auto info =
277 parseDisplayIdentificationData(PhysicalDisplay::PORT,
278 PhysicalDisplay::GET_IDENTIFICATION_DATA());
279 return info ? std::make_optional(info->id) : std::nullopt;
280 }
281};
282
Dominik Laskowski34157762018-10-31 13:07:19 -0700283template <DisplayId::Type displayId>
Dominik Laskowski075d3172018-05-24 15:50:06 -0700284struct DisplayIdGetter<VirtualDisplayId<displayId>> {
Dominik Laskowski34157762018-10-31 13:07:19 -0700285 static std::optional<DisplayId> get() { return DisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700286};
287
288template <>
289struct DisplayIdGetter<NoDisplayId> {
290 static std::optional<DisplayId> get() { return {}; }
291};
292
293// DisplayIdType can be:
294// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC.
295// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC.
296// 3) NoDisplayId for virtual display without HWC backing.
297template <typename DisplayIdType, int width, int height, Critical critical, Async async,
298 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800299struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700300 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
301
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800302 // The display width and height
303 static constexpr int WIDTH = width;
304 static constexpr int HEIGHT = height;
305
306 static constexpr int GRALLOC_USAGE = grallocUsage;
307
Dominik Laskowski075d3172018-05-24 15:50:06 -0700308 // Whether the display is virtual or physical
309 static constexpr Virtual VIRTUAL =
310 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800311
312 // When creating native window surfaces for the framebuffer, whether those should be critical
313 static constexpr Critical CRITICAL = critical;
314
315 // When creating native window surfaces for the framebuffer, whether those should be async
316 static constexpr Async ASYNC = async;
317
318 // Whether the display should be treated as secure
319 static constexpr Secure SECURE = secure;
320
Dominik Laskowski075d3172018-05-24 15:50:06 -0700321 // Whether the display is primary
322 static constexpr Primary PRIMARY = primary;
323
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800324 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700325 auto injector =
326 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(),
327 static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY));
328
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800329 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700330 injector.setNativeWindow(test->mNativeWindow);
331
332 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800333 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700334 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
335 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
336 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
337 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800338 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
339 .WillRepeatedly(Return(0));
340 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
341 .WillRepeatedly(Return(0));
342 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
343 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800344 return injector;
345 }
346
347 // Called by tests to set up any native window creation call expectations.
348 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
349 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
350 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800351
Alec Mouriba013fa2018-10-16 12:43:11 -0700352 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
353 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
354 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
355 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800356 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
357 .WillRepeatedly(Return(0));
358 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
359 .WillRepeatedly(Return(0));
360 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
361 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800362 }
363
364 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
365 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
366 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
367 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
368 .WillRepeatedly(Return(NO_ERROR));
369 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
370 .WillRepeatedly(Return(NO_ERROR));
371 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
372 .WillRepeatedly(Return(NO_ERROR));
373 }
374
375 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
376 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
377 }
378};
379
Dominik Laskowski075d3172018-05-24 15:50:06 -0700380template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
381 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800382struct HwcDisplayVariant {
383 // The display id supplied by the HWC
384 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
385
386 // The HWC display type
387 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
388
389 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700390 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800391
392 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
393 HWC2::Connection connection) {
394 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
395 HotplugEvent{HWC_DISPLAY_ID, connection});
396 }
397
398 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800399 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700400 const auto displayId = DisplayVariant::DISPLAY_ID::get();
401 ASSERT_TRUE(displayId);
402 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
403 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800404 .setHwcDisplayId(HWC_DISPLAY_ID)
405 .setWidth(DisplayVariant::WIDTH)
406 .setHeight(DisplayVariant::HEIGHT)
407 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
408 .inject(&test->mFlinger, test->mComposer);
409 }
410
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800411 // Called by tests to inject a HWC display setup
412 static void injectHwcDisplay(DisplayTransactionTest* test) {
413 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
414 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
415 Return(Error::NONE)));
416 injectHwcDisplayWithNoDefaultCapabilities(test);
417 }
418
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800419 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
420 EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _))
421 .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>(
422 HWC_DISPLAY_TYPE)),
423 Return(Error::NONE)));
424 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
425 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
426 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
427 Return(Error::NONE)));
428 EXPECT_CALL(*test->mComposer,
429 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
430 IComposerClient::Attribute::WIDTH, _))
431 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
432 EXPECT_CALL(*test->mComposer,
433 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
434 IComposerClient::Attribute::HEIGHT, _))
435 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
436 EXPECT_CALL(*test->mComposer,
437 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
438 IComposerClient::Attribute::VSYNC_PERIOD, _))
439 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
440 EXPECT_CALL(*test->mComposer,
441 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
442 IComposerClient::Attribute::DPI_X, _))
443 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
444 EXPECT_CALL(*test->mComposer,
445 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
446 IComposerClient::Attribute::DPI_Y, _))
447 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800448 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
449 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
450 Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700451
452 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
453 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
454 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
455 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
456 Return(Error::NONE)));
457 } else {
458 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
459 .WillOnce(Return(Error::UNSUPPORTED));
460 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800461 }
462
463 // Called by tests to set up HWC call expectations
464 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
465 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700466 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800467 }
468};
469
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800470// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
471constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
472 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
473
Dominik Laskowski075d3172018-05-24 15:50:06 -0700474template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800475 Critical critical>
476struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700477 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
478 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
479 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
480 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
481 critical, Async::FALSE, Secure::TRUE,
482 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
483 PhysicalDisplay> {};
484
485template <bool hasIdentificationData>
486struct PrimaryDisplay {
487 static constexpr Primary PRIMARY = Primary::TRUE;
488 static constexpr uint8_t PORT = 255;
489 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
490 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
491};
492
493template <bool hasIdentificationData>
494struct ExternalDisplay {
495 static constexpr Primary PRIMARY = Primary::FALSE;
496 static constexpr uint8_t PORT = 254;
497 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
498 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
499};
500
501struct TertiaryDisplay {
502 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800503 static constexpr uint8_t PORT = 253;
504 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700505};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800506
507// A primary display is a physical display that is critical
508using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700509 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800510
511// An external display is physical display that is not critical.
512using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700513 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800514
515using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700516 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800517
518// A virtual display not supported by the HWC.
519constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
520
521template <int width, int height, Secure secure>
522struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700523 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
524 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
525 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
526 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
527
528 static void injectHwcDisplay(DisplayTransactionTest*) {}
529
530 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
531 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
532 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800533
534 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
535 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
536 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
537 }
538};
539
540// A virtual display supported by the HWC.
541constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
542
543template <int width, int height, Secure secure>
544struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700545 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
546 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
547 HwcDisplayVariant<
548 1010, HWC2::DisplayType::Virtual,
549 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
550 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
551 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
552 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800553 using Self = HwcVirtualDisplayVariant<width, height, secure>;
554
555 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
556 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
557 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
558 }
559
560 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
561 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
562 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
563 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
564 }
565};
566
567// For this variant, SurfaceFlinger should not configure itself with wide
568// display support, so the display should not be configured for wide-color
569// support.
570struct WideColorSupportNotConfiguredVariant {
571 static constexpr bool WIDE_COLOR_SUPPORTED = false;
572
573 static void injectConfigChange(DisplayTransactionTest* test) {
574 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700575 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800576 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
577 }
578
579 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
580 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
581 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
582 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
583 }
584};
585
586// For this variant, SurfaceFlinger should configure itself with wide display
587// support, and the display should respond with an non-empty list of supported
588// color modes. Wide-color support should be configured.
589template <typename Display>
590struct WideColorP3ColorimetricSupportedVariant {
591 static constexpr bool WIDE_COLOR_SUPPORTED = true;
592
593 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700594 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800595 test->mFlinger.mutableHasWideColorDisplay() = true;
596 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
597 }
598
599 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800600 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
601
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800602 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
603 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
604 Return(Error::NONE)));
605 EXPECT_CALL(*test->mComposer,
606 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
607 .WillOnce(DoAll(SetArgPointee<2>(
608 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
609 Return(Error::NONE)));
610 EXPECT_CALL(*test->mComposer,
611 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
612 RenderIntent::COLORIMETRIC))
613 .WillOnce(Return(Error::NONE));
614 }
615};
616
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800617// For this variant, SurfaceFlinger should configure itself with wide display
618// support, but the display should respond with an empty list of supported color
619// modes. Wide-color support for the display should not be configured.
620template <typename Display>
621struct WideColorNotSupportedVariant {
622 static constexpr bool WIDE_COLOR_SUPPORTED = false;
623
624 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700625 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800626 test->mFlinger.mutableHasWideColorDisplay() = true;
627 }
628
629 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
630 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
631 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700632 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800633 }
634};
635
636// For this variant, the display is not a HWC display, so no HDR support should
637// be configured.
638struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800639 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800640 static constexpr bool HDR10_SUPPORTED = false;
641 static constexpr bool HDR_HLG_SUPPORTED = false;
642 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
643 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
644 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
645 }
646};
647
Valerie Haue9e843a2018-12-18 13:39:23 -0800648template <typename Display>
649struct Hdr10PlusSupportedVariant {
650 static constexpr bool HDR10_PLUS_SUPPORTED = true;
651 static constexpr bool HDR10_SUPPORTED = true;
652 static constexpr bool HDR_HLG_SUPPORTED = false;
653 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
654 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
655 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
656 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
657 Hdr::HDR10_PLUS,
658 Hdr::HDR10,
659 })),
660 Return(Error::NONE)));
661 }
662};
663
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800664// For this variant, the composer should respond with a non-empty list of HDR
665// modes containing HDR10, so HDR10 support should be configured.
666template <typename Display>
667struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800668 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800669 static constexpr bool HDR10_SUPPORTED = true;
670 static constexpr bool HDR_HLG_SUPPORTED = false;
671 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
672 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
673 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
674 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
675 Return(Error::NONE)));
676 }
677};
678
679// For this variant, the composer should respond with a non-empty list of HDR
680// modes containing HLG, so HLG support should be configured.
681template <typename Display>
682struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800683 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800684 static constexpr bool HDR10_SUPPORTED = false;
685 static constexpr bool HDR_HLG_SUPPORTED = true;
686 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
687 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
688 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
689 .WillOnce(
690 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
691 }
692};
693
694// For this variant, the composer should respond with a non-empty list of HDR
695// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
696template <typename Display>
697struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800698 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800699 static constexpr bool HDR10_SUPPORTED = false;
700 static constexpr bool HDR_HLG_SUPPORTED = false;
701 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
702 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
703 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
704 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
705 Return(Error::NONE)));
706 }
707};
708
709// For this variant, the composer should respond with am empty list of HDR
710// modes, so no HDR support should be configured.
711template <typename Display>
712struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800713 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800714 static constexpr bool HDR10_SUPPORTED = false;
715 static constexpr bool HDR_HLG_SUPPORTED = false;
716 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
717 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
718 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
719 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
720 }
721};
722
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700723struct NonHwcPerFrameMetadataSupportVariant {
724 static constexpr int PER_FRAME_METADATA_KEYS = 0;
725 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800726 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700727 }
728};
729
730template <typename Display>
731struct NoPerFrameMetadataSupportVariant {
732 static constexpr int PER_FRAME_METADATA_KEYS = 0;
733 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800734 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
735 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700736 }
737};
738
739template <typename Display>
740struct Smpte2086PerFrameMetadataSupportVariant {
741 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
742 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800743 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
744 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800745 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
746 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
747 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
748 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
749 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
750 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
751 PerFrameMetadataKey::WHITE_POINT_X,
752 PerFrameMetadataKey::WHITE_POINT_Y,
753 PerFrameMetadataKey::MAX_LUMINANCE,
754 PerFrameMetadataKey::MIN_LUMINANCE,
755 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700756 }
757};
758
759template <typename Display>
760struct Cta861_3_PerFrameMetadataSupportVariant {
761 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
762 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800763 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
764 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800765 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
766 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
767 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700768 }
769};
770
Valerie Haue9e843a2018-12-18 13:39:23 -0800771template <typename Display>
772struct Hdr10_Plus_PerFrameMetadataSupportVariant {
773 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
774 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
775 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
776 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
777 PerFrameMetadataKey::HDR10_PLUS_SEI,
778 })));
779 }
780};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800781/* ------------------------------------------------------------------------
782 * Typical display configurations to test
783 */
784
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700785template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
786 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800787struct Case {
788 using Display = DisplayPolicy;
789 using WideColorSupport = WideColorSupportPolicy;
790 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700791 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800792};
793
794using SimplePrimaryDisplayCase =
795 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700796 HdrNotSupportedVariant<PrimaryDisplayVariant>,
797 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800798using SimpleExternalDisplayCase =
799 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700800 HdrNotSupportedVariant<ExternalDisplayVariant>,
801 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800802using SimpleTertiaryDisplayCase =
803 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700804 HdrNotSupportedVariant<TertiaryDisplayVariant>,
805 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800806using NonHwcVirtualDisplayCase =
807 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700808 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
809 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800810using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
811using HwcVirtualDisplayCase =
812 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700813 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800814 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800815using WideColorP3ColorimetricDisplayCase =
816 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700817 HdrNotSupportedVariant<PrimaryDisplayVariant>,
818 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800819using Hdr10PlusDisplayCase =
820 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
821 Hdr10SupportedVariant<PrimaryDisplayVariant>,
822 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800823using Hdr10DisplayCase =
824 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700825 Hdr10SupportedVariant<PrimaryDisplayVariant>,
826 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800827using HdrHlgDisplayCase =
828 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700829 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
830 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800831using HdrDolbyVisionDisplayCase =
832 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700833 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
834 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
835using HdrSmpte2086DisplayCase =
836 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
837 HdrNotSupportedVariant<PrimaryDisplayVariant>,
838 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
839using HdrCta861_3_DisplayCase =
840 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
841 HdrNotSupportedVariant<PrimaryDisplayVariant>,
842 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700843
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800844/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800845 *
846 * SurfaceFlinger::onHotplugReceived
847 */
848
849TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
850 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700851 constexpr hwc2_display_t hwcDisplayId1 = 456;
852 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800853
854 // --------------------------------------------------------------------
855 // Preconditions
856
857 // Set the current sequence id for accepted events
858 mFlinger.mutableComposerSequenceId() = currentSequenceId;
859
860 // Set the main thread id so that the current thread does not appear to be
861 // the main thread.
862 mFlinger.mutableMainThreadId() = std::thread::id();
863
864 // --------------------------------------------------------------------
865 // Call Expectations
866
867 // We expect invalidate() to be invoked once to trigger display transaction
868 // processing.
869 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
870
871 // --------------------------------------------------------------------
872 // Invocation
873
874 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700875 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
876 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800877
878 // --------------------------------------------------------------------
879 // Postconditions
880
881 // The display transaction needed flag should be set.
882 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
883
884 // All events should be in the pending event queue.
885 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
886 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700887 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800888 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700889 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800890 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
891}
892
893TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
894 constexpr int currentSequenceId = 123;
895 constexpr int otherSequenceId = 321;
896 constexpr hwc2_display_t displayId = 456;
897
898 // --------------------------------------------------------------------
899 // Preconditions
900
901 // Set the current sequence id for accepted events
902 mFlinger.mutableComposerSequenceId() = currentSequenceId;
903
904 // Set the main thread id so that the current thread does not appear to be
905 // the main thread.
906 mFlinger.mutableMainThreadId() = std::thread::id();
907
908 // --------------------------------------------------------------------
909 // Call Expectations
910
911 // We do not expect any calls to invalidate().
912 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
913
914 // --------------------------------------------------------------------
915 // Invocation
916
917 // Call with an unexpected sequence id
918 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
919
920 // --------------------------------------------------------------------
921 // Postconditions
922
923 // The display transaction needed flag should not be set
924 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
925
926 // There should be no pending events
927 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
928}
929
930TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
931 constexpr int currentSequenceId = 123;
932 constexpr hwc2_display_t displayId1 = 456;
933
934 // --------------------------------------------------------------------
935 // Note:
936 // --------------------------------------------------------------------
937 // This test case is a bit tricky. We want to verify that
938 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
939 // don't really want to provide coverage for everything the later function
940 // does as there are specific tests for it.
941 // --------------------------------------------------------------------
942
943 // --------------------------------------------------------------------
944 // Preconditions
945
946 // Set the current sequence id for accepted events
947 mFlinger.mutableComposerSequenceId() = currentSequenceId;
948
949 // Set the main thread id so that the current thread does appear to be the
950 // main thread.
951 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
952
953 // --------------------------------------------------------------------
954 // Call Expectations
955
956 // We expect invalidate() to be invoked once to trigger display transaction
957 // processing.
958 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
959
960 // --------------------------------------------------------------------
961 // Invocation
962
963 // Simulate a disconnect on a display id that is not connected. This should
964 // be enqueued by onHotplugReceived(), and dequeued by
965 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
966 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
967
968 // --------------------------------------------------------------------
969 // Postconditions
970
971 // The display transaction needed flag should be set.
972 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
973
974 // There should be no event queued on return, as it should have been
975 // processed.
976 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
977}
978
979/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -0800980 * SurfaceFlinger::createDisplay
981 */
982
983TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
984 const String8 name("virtual.test");
985
986 // --------------------------------------------------------------------
987 // Call Expectations
988
989 // The call should notify the interceptor that a display was created.
990 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
991
992 // --------------------------------------------------------------------
993 // Invocation
994
995 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
996
997 // --------------------------------------------------------------------
998 // Postconditions
999
1000 // The display should have been added to the current state
1001 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1002 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001003 EXPECT_TRUE(display.isVirtual());
1004 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001005 EXPECT_EQ(name.string(), display.displayName);
1006
1007 // --------------------------------------------------------------------
1008 // Cleanup conditions
1009
1010 // Destroying the display invalidates the display state.
1011 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1012}
1013
1014TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1015 const String8 name("virtual.test");
1016
1017 // --------------------------------------------------------------------
1018 // Call Expectations
1019
1020 // The call should notify the interceptor that a display was created.
1021 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1022
1023 // --------------------------------------------------------------------
1024 // Invocation
1025
1026 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1027
1028 // --------------------------------------------------------------------
1029 // Postconditions
1030
1031 // The display should have been added to the current state
1032 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1033 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001034 EXPECT_TRUE(display.isVirtual());
1035 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001036 EXPECT_EQ(name.string(), display.displayName);
1037
1038 // --------------------------------------------------------------------
1039 // Cleanup conditions
1040
1041 // Destroying the display invalidates the display state.
1042 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1043}
1044
1045/* ------------------------------------------------------------------------
1046 * SurfaceFlinger::destroyDisplay
1047 */
1048
1049TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1050 using Case = NonHwcVirtualDisplayCase;
1051
1052 // --------------------------------------------------------------------
1053 // Preconditions
1054
1055 // A virtual display exists
1056 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1057 existing.inject();
1058
1059 // --------------------------------------------------------------------
1060 // Call Expectations
1061
1062 // The call should notify the interceptor that a display was created.
1063 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1064
1065 // Destroying the display invalidates the display state.
1066 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1067
1068 // --------------------------------------------------------------------
1069 // Invocation
1070
1071 mFlinger.destroyDisplay(existing.token());
1072
1073 // --------------------------------------------------------------------
1074 // Postconditions
1075
1076 // The display should have been removed from the current state
1077 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1078
1079 // Ths display should still exist in the drawing state
1080 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1081
1082 // The display transaction needed flasg should be set
1083 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1084}
1085
1086TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1087 // --------------------------------------------------------------------
1088 // Preconditions
1089
1090 sp<BBinder> displayToken = new BBinder();
1091
1092 // --------------------------------------------------------------------
1093 // Invocation
1094
1095 mFlinger.destroyDisplay(displayToken);
1096}
1097
1098/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001099 * SurfaceFlinger::resetDisplayState
1100 */
1101
1102TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1103 using Case = NonHwcVirtualDisplayCase;
1104
1105 // --------------------------------------------------------------------
1106 // Preconditions
1107
1108 // vsync is enabled and available
1109 mFlinger.mutablePrimaryHWVsyncEnabled() = true;
1110 mFlinger.mutableHWVsyncAvailable() = true;
1111
1112 // A display exists
1113 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1114 existing.inject();
1115
1116 // --------------------------------------------------------------------
1117 // Call Expectations
1118
1119 // The call disable vsyncs
1120 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1121
Lloyd Pique41be5d22018-06-21 13:11:48 -07001122 // The call ends any display resyncs
1123 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1124
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001125 // --------------------------------------------------------------------
1126 // Invocation
1127
1128 mFlinger.resetDisplayState();
1129
1130 // --------------------------------------------------------------------
1131 // Postconditions
1132
1133 // vsyncs should be off and not available.
1134 EXPECT_FALSE(mFlinger.mutablePrimaryHWVsyncEnabled());
1135 EXPECT_FALSE(mFlinger.mutableHWVsyncAvailable());
1136
1137 // The display should have been removed from the display map.
1138 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1139
1140 // The display should still exist in the current state
1141 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1142
1143 // The display should have been removed from the drawing state
1144 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1145}
1146
1147/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001148 * DisplayDevice::GetBestColorMode
1149 */
1150class GetBestColorModeTest : public DisplayTransactionTest {
1151public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001152 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001153
Valerie Hau9758ae02018-10-09 16:05:09 -07001154 GetBestColorModeTest()
1155 : DisplayTransactionTest(),
Dominik Laskowski075d3172018-05-24 15:50:06 -07001156 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */,
1157 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001158
1159 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1160
1161 void addHwcColorModesMapping(ui::ColorMode colorMode,
1162 std::vector<ui::RenderIntent> renderIntents) {
1163 mHwcColorModes[colorMode] = renderIntents;
1164 }
1165
1166 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1167
1168 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1169
1170 void getBestColorMode() {
1171 mInjector.setHwcColorModes(mHwcColorModes);
1172 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001173 mInjector.setNativeWindow(mNativeWindow);
1174
1175 // Creating a DisplayDevice requires getting default dimensions from the
1176 // native window.
1177 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1178 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1179 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1180 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001181 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1182 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1183 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001184 auto displayDevice = mInjector.inject();
1185
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001186 displayDevice->getCompositionDisplay()
1187 ->getDisplayColorProfile()
1188 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1189 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001190 }
1191
1192 ui::Dataspace mOutDataspace;
1193 ui::ColorMode mOutColorMode;
1194 ui::RenderIntent mOutRenderIntent;
1195
1196private:
1197 ui::Dataspace mInputDataspace;
1198 ui::RenderIntent mInputRenderIntent;
1199 bool mHasWideColorGamut = false;
1200 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1201 FakeDisplayDeviceInjector mInjector;
1202};
1203
1204TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1205 addHwcColorModesMapping(ui::ColorMode::SRGB,
1206 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1207 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1208 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1209 setHasWideColorGamut(true);
1210
1211 getBestColorMode();
1212
Peiyong Lin14724e62018-12-05 07:27:30 -08001213 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001214 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1215 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1216}
1217
1218TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1219 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1220 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1221 addHwcColorModesMapping(ui::ColorMode::SRGB,
1222 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1223 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1224 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1225 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1226 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1227 setHasWideColorGamut(true);
1228
1229 getBestColorMode();
1230
1231 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1232 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1233 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1234}
1235
1236TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1237 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1238 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1239 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1240 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1241 setHasWideColorGamut(true);
1242
1243 getBestColorMode();
1244
1245 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1246 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1247 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1248}
1249
1250/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001251 * SurfaceFlinger::getDisplayNativePrimaries
1252 */
1253
1254class GetDisplayNativePrimaries : public DisplayTransactionTest {
1255public:
1256 GetDisplayNativePrimaries();
1257 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1258 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1259
1260private:
1261 static constexpr float mStartingTestValue = 1.0f;
1262};
1263
1264GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1265 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1266 injectFakeNativeWindowSurfaceFactory();
1267}
1268
1269void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1270 ui::DisplayPrimaries& primaries) {
1271 float startingVal = mStartingTestValue;
1272 primaries.red.X = startingVal++;
1273 primaries.red.Y = startingVal++;
1274 primaries.red.Z = startingVal++;
1275 primaries.green.X = startingVal++;
1276 primaries.green.Y = startingVal++;
1277 primaries.green.Z = startingVal++;
1278 primaries.blue.X = startingVal++;
1279 primaries.blue.Y = startingVal++;
1280 primaries.blue.Z = startingVal++;
1281 primaries.white.X = startingVal++;
1282 primaries.white.Y = startingVal++;
1283 primaries.white.Z = startingVal++;
1284}
1285
1286void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1287 const ui::DisplayPrimaries& primaries) {
1288 float startingVal = mStartingTestValue;
1289 EXPECT_EQ(primaries.red.X, startingVal++);
1290 EXPECT_EQ(primaries.red.Y, startingVal++);
1291 EXPECT_EQ(primaries.red.Z, startingVal++);
1292 EXPECT_EQ(primaries.green.X, startingVal++);
1293 EXPECT_EQ(primaries.green.Y, startingVal++);
1294 EXPECT_EQ(primaries.green.Z, startingVal++);
1295 EXPECT_EQ(primaries.blue.X, startingVal++);
1296 EXPECT_EQ(primaries.blue.Y, startingVal++);
1297 EXPECT_EQ(primaries.blue.Z, startingVal++);
1298 EXPECT_EQ(primaries.white.X, startingVal++);
1299 EXPECT_EQ(primaries.white.Y, startingVal++);
1300 EXPECT_EQ(primaries.white.Z, startingVal++);
1301}
1302
1303TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1304 ui::DisplayPrimaries primaries;
1305 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1306}
1307
1308TEST_F(GetDisplayNativePrimaries, internalDisplayWithDefaultPrimariesData) {
1309 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1310 injector.inject();
1311 auto internalDisplayToken = injector.token();
1312 // A nullptr would trigger a different execution path than what's being tested here
1313 EXPECT_NE(nullptr, internalDisplayToken.get());
1314
1315 mFlinger.initDefaultDisplayNativePrimaries();
1316
1317 ui::DisplayPrimaries primaries;
1318 // Expecting sRGB primaries
1319 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1320 EXPECT_EQ(primaries.red.X, 0.4123f);
1321 EXPECT_EQ(primaries.red.Y, 0.2126f);
1322 EXPECT_EQ(primaries.red.Z, 0.0193f);
1323 EXPECT_EQ(primaries.green.X, 0.3576f);
1324 EXPECT_EQ(primaries.green.Y, 0.7152f);
1325 EXPECT_EQ(primaries.green.Z, 0.1192f);
1326 EXPECT_EQ(primaries.blue.X, 0.1805f);
1327 EXPECT_EQ(primaries.blue.Y, 0.0722f);
1328 EXPECT_EQ(primaries.blue.Z, 0.9506f);
1329 EXPECT_EQ(primaries.white.X, 0.9505f);
1330 EXPECT_EQ(primaries.white.Y, 1.0000f);
1331 EXPECT_EQ(primaries.white.Z, 1.0891f);
1332}
1333
1334TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1335 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1336 injector.inject();
1337 auto internalDisplayToken = injector.token();
1338
1339 ui::DisplayPrimaries expectedPrimaries;
1340 populateDummyDisplayNativePrimaries(expectedPrimaries);
1341 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1342
1343 ui::DisplayPrimaries primaries;
1344 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1345
1346 checkDummyDisplayNativePrimaries(primaries);
1347}
1348
1349TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1350 sp<BBinder> notInternalDisplayToken = new BBinder();
1351
1352 ui::DisplayPrimaries primaries;
1353 populateDummyDisplayNativePrimaries(primaries);
1354 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1355
1356 // Check primaries argument wasn't modified in case of failure
1357 checkDummyDisplayNativePrimaries(primaries);
1358}
1359
1360/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001361 * SurfaceFlinger::setupNewDisplayDeviceInternal
1362 */
1363
1364class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1365public:
1366 template <typename T>
1367 void setupNewDisplayDeviceInternalTest();
1368};
1369
1370template <typename Case>
1371void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1372 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001373 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1374 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001375 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001376
1377 // --------------------------------------------------------------------
1378 // Preconditions
1379
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001380 // Wide color displays support is configured appropriately
1381 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001382
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001383 // The display is setup with the HWC.
1384 Case::Display::injectHwcDisplay(this);
1385
1386 // SurfaceFlinger will use a test-controlled factory for native window
1387 // surfaces.
1388 injectFakeNativeWindowSurfaceFactory();
1389
1390 // --------------------------------------------------------------------
1391 // Call Expectations
1392
1393 // Various native window calls will be made.
1394 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001395 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001396 Case::WideColorSupport::setupComposerCallExpectations(this);
1397 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001398 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001399
1400 // --------------------------------------------------------------------
1401 // Invocation
1402
1403 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001404 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1405 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001406 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1407
Dominik Laskowski075d3172018-05-24 15:50:06 -07001408 auto device =
1409 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1410 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001411
1412 // --------------------------------------------------------------------
1413 // Postconditions
1414
1415 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001416 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1417 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001418 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001419 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001420 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1421 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1422 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001423 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001424 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1425 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1426 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001427 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1428 // remapped, and the test only ever sets up one config. If there were an error
1429 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
1430 EXPECT_EQ(0, device->getActiveConfig());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001431 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1432 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001433}
1434
1435TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1436 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1437}
1438
1439TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1440 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1441}
1442
1443TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1444 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1445}
1446
1447TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001448 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001449
Dominik Laskowski075d3172018-05-24 15:50:06 -07001450 // Insert display data so that the HWC thinks it created the virtual display.
1451 const auto displayId = Case::Display::DISPLAY_ID::get();
1452 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001453 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001454
1455 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001456}
1457
1458TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1459 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1460}
1461
Valerie Haue9e843a2018-12-18 13:39:23 -08001462TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1463 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1464}
1465
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001466TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1467 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1468}
1469
1470TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1471 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1472}
1473
1474TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1475 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1476}
1477
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001478TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1479 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1480}
1481
1482TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1483 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1484}
1485
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001486/* ------------------------------------------------------------------------
1487 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1488 */
1489
1490class HandleTransactionLockedTest : public DisplayTransactionTest {
1491public:
1492 template <typename Case>
1493 void setupCommonPreconditions();
1494
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001495 template <typename Case, bool connected>
1496 static void expectHotplugReceived(mock::EventThread*);
1497
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001498 template <typename Case>
1499 void setupCommonCallExpectationsForConnectProcessing();
1500
1501 template <typename Case>
1502 void setupCommonCallExpectationsForDisconnectProcessing();
1503
1504 template <typename Case>
1505 void processesHotplugConnectCommon();
1506
1507 template <typename Case>
1508 void ignoresHotplugConnectCommon();
1509
1510 template <typename Case>
1511 void processesHotplugDisconnectCommon();
1512
1513 template <typename Case>
1514 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1515
1516 template <typename Case>
1517 void verifyPhysicalDisplayIsConnected();
1518
1519 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1520};
1521
1522template <typename Case>
1523void HandleTransactionLockedTest::setupCommonPreconditions() {
1524 // Wide color displays support is configured appropriately
1525 Case::WideColorSupport::injectConfigChange(this);
1526
1527 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1528 injectFakeBufferQueueFactory();
1529
1530 // SurfaceFlinger will use a test-controlled factory for native window
1531 // surfaces.
1532 injectFakeNativeWindowSurfaceFactory();
1533}
1534
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001535template <typename Case, bool connected>
1536void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1537 const auto convert = [](auto physicalDisplayId) {
1538 return std::make_optional(DisplayId{physicalDisplayId});
1539 };
1540
1541 EXPECT_CALL(*eventThread,
1542 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1543 .Times(1);
1544}
1545
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001546template <typename Case>
1547void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1548 Case::Display::setupHwcHotplugCallExpectations(this);
1549
1550 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1551 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1552 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1553 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1554
1555 Case::WideColorSupport::setupComposerCallExpectations(this);
1556 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001557 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001558
1559 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001560
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001561 expectHotplugReceived<Case, true>(mEventThread);
1562 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001563}
1564
1565template <typename Case>
1566void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1567 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001568
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001569 expectHotplugReceived<Case, false>(mEventThread);
1570 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001571}
1572
1573template <typename Case>
1574void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1575 // The display device should have been set up in the list of displays.
1576 ASSERT_TRUE(hasDisplayDevice(displayToken));
1577 const auto& device = getDisplayDevice(displayToken);
1578 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001579 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001580
1581 // The display should have been set up in the current display state
1582 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1583 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001584 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1585 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1586 : Case::Display::DISPLAY_ID::get(),
1587 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001588
1589 // The display should have been set up in the drawing display state
1590 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1591 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001592 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1593 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1594 : Case::Display::DISPLAY_ID::get(),
1595 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001596}
1597
1598template <typename Case>
1599void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1600 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001601 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001602
Dominik Laskowski075d3172018-05-24 15:50:06 -07001603 // SF should have a display token.
1604 const auto displayId = Case::Display::DISPLAY_ID::get();
1605 ASSERT_TRUE(displayId);
1606 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1607 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001608
1609 verifyDisplayIsConnected<Case>(displayToken);
1610}
1611
1612void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1613 EXPECT_FALSE(hasDisplayDevice(displayToken));
1614 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1615 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1616}
1617
1618template <typename Case>
1619void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1620 // --------------------------------------------------------------------
1621 // Preconditions
1622
1623 setupCommonPreconditions<Case>();
1624
1625 // A hotplug connect event is enqueued for a display
1626 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001627
1628 // --------------------------------------------------------------------
1629 // Call Expectations
1630
1631 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001632
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001633 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001634
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001635 // --------------------------------------------------------------------
1636 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001637
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001638 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001639
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001640 // --------------------------------------------------------------------
1641 // Postconditions
1642
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001643 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001644
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001645 // --------------------------------------------------------------------
1646 // Cleanup conditions
1647
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001648 EXPECT_CALL(*mComposer,
1649 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001650 .WillOnce(Return(Error::NONE));
1651 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001652}
1653
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001654template <typename Case>
1655void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1656 // --------------------------------------------------------------------
1657 // Preconditions
1658
1659 setupCommonPreconditions<Case>();
1660
1661 // A hotplug connect event is enqueued for a display
1662 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1663
1664 // --------------------------------------------------------------------
1665 // Invocation
1666
1667 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1668
1669 // --------------------------------------------------------------------
1670 // Postconditions
1671
1672 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001673 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001674}
1675
1676template <typename Case>
1677void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1678 // --------------------------------------------------------------------
1679 // Preconditions
1680
1681 setupCommonPreconditions<Case>();
1682
1683 // A hotplug disconnect event is enqueued for a display
1684 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1685
1686 // The display is already completely set up.
1687 Case::Display::injectHwcDisplay(this);
1688 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1689 existing.inject();
1690
1691 // --------------------------------------------------------------------
1692 // Call Expectations
1693
1694 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001695 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1696 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001697
1698 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1699
1700 // --------------------------------------------------------------------
1701 // Invocation
1702
1703 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1704
1705 // --------------------------------------------------------------------
1706 // Postconditions
1707
1708 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001709 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001710
Dominik Laskowski075d3172018-05-24 15:50:06 -07001711 // SF should not have a display token.
1712 const auto displayId = Case::Display::DISPLAY_ID::get();
1713 ASSERT_TRUE(displayId);
1714 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001715
1716 // The existing token should have been removed
1717 verifyDisplayIsNotConnected(existing.token());
1718}
1719
1720TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1721 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1722}
1723
1724TEST_F(HandleTransactionLockedTest,
1725 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1726 // Inject an external display.
1727 ExternalDisplayVariant::injectHwcDisplay(this);
1728
1729 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1730}
1731
1732TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1733 // Inject a primary display.
1734 PrimaryDisplayVariant::injectHwcDisplay(this);
1735
1736 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1737}
1738
1739TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1740 // Inject both a primary and external display.
1741 PrimaryDisplayVariant::injectHwcDisplay(this);
1742 ExternalDisplayVariant::injectHwcDisplay(this);
1743
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001744 // TODO: This is an unnecessary call.
1745 EXPECT_CALL(*mComposer,
1746 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
1747 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
1748 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
1749 Return(Error::NONE)));
1750
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001751 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1752
1753 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1754}
1755
1756TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1757 // Inject a primary display.
1758 PrimaryDisplayVariant::injectHwcDisplay(this);
1759
1760 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1761
1762 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1763}
1764
1765TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1766 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1767}
1768
1769TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1770 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1771}
1772
1773TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1774 using Case = SimplePrimaryDisplayCase;
1775
1776 // --------------------------------------------------------------------
1777 // Preconditions
1778
1779 setupCommonPreconditions<Case>();
1780
1781 // A hotplug connect event is enqueued for a display
1782 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1783 // A hotplug disconnect event is also enqueued for the same display
1784 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1785
1786 // --------------------------------------------------------------------
1787 // Call Expectations
1788
1789 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1790
1791 setupCommonCallExpectationsForConnectProcessing<Case>();
1792 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1793
1794 EXPECT_CALL(*mComposer,
1795 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1796 .WillOnce(Return(Error::NONE));
1797 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1798
1799 // --------------------------------------------------------------------
1800 // Invocation
1801
1802 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1803
1804 // --------------------------------------------------------------------
1805 // Postconditions
1806
1807 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001808 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001809
Dominik Laskowski075d3172018-05-24 15:50:06 -07001810 // SF should not have a display token.
1811 const auto displayId = Case::Display::DISPLAY_ID::get();
1812 ASSERT_TRUE(displayId);
1813 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001814}
1815
1816TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1817 using Case = SimplePrimaryDisplayCase;
1818
1819 // --------------------------------------------------------------------
1820 // Preconditions
1821
1822 setupCommonPreconditions<Case>();
1823
1824 // The display is already completely set up.
1825 Case::Display::injectHwcDisplay(this);
1826 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1827 existing.inject();
1828
1829 // A hotplug disconnect event is enqueued for a display
1830 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1831 // A hotplug connect event is also enqueued for the same display
1832 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1833
1834 // --------------------------------------------------------------------
1835 // Call Expectations
1836
1837 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1838
1839 setupCommonCallExpectationsForConnectProcessing<Case>();
1840 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1841
1842 // --------------------------------------------------------------------
1843 // Invocation
1844
1845 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1846
1847 // --------------------------------------------------------------------
1848 // Postconditions
1849
1850 // The existing token should have been removed
1851 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001852 const auto displayId = Case::Display::DISPLAY_ID::get();
1853 ASSERT_TRUE(displayId);
1854 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1855 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001856
1857 // A new display should be connected in its place
1858
1859 verifyPhysicalDisplayIsConnected<Case>();
1860
1861 // --------------------------------------------------------------------
1862 // Cleanup conditions
1863
1864 EXPECT_CALL(*mComposer,
1865 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1866 .WillOnce(Return(Error::NONE));
1867 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1868}
1869
1870TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1871 using Case = HwcVirtualDisplayCase;
1872
1873 // --------------------------------------------------------------------
1874 // Preconditions
1875
1876 // The HWC supports at least one virtual display
1877 injectMockComposer(1);
1878
1879 setupCommonPreconditions<Case>();
1880
1881 // A virtual display was added to the current state, and it has a
1882 // surface(producer)
1883 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07001884
Dominik Laskowski075d3172018-05-24 15:50:06 -07001885 DisplayDeviceState state;
1886 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001887
1888 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001889 state.surface = surface;
1890 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001891
1892 // --------------------------------------------------------------------
1893 // Call Expectations
1894
1895 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1896 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1897
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001898 EXPECT_CALL(*mComposer, getDisplayCapabilities(Case::Display::HWC_DISPLAY_ID, _))
1899 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
1900 Return(Error::NONE)));
1901
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001902 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1903 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1904 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1905 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1906 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1907 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1908 Return(NO_ERROR)));
1909 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1910 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1911
1912 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1913
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001914 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001915 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1916
1917 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1918 Case::WideColorSupport::setupComposerCallExpectations(this);
1919 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001920 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001921
1922 // --------------------------------------------------------------------
1923 // Invocation
1924
1925 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1926
1927 // --------------------------------------------------------------------
1928 // Postconditions
1929
1930 // The display device should have been set up in the list of displays.
1931 verifyDisplayIsConnected<Case>(displayToken);
1932
1933 // --------------------------------------------------------------------
1934 // Cleanup conditions
1935
1936 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1937 .WillOnce(Return(Error::NONE));
1938 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1939}
1940
1941TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1942 using Case = HwcVirtualDisplayCase;
1943
1944 // --------------------------------------------------------------------
1945 // Preconditions
1946
1947 // The HWC supports at least one virtual display
1948 injectMockComposer(1);
1949
1950 setupCommonPreconditions<Case>();
1951
1952 // A virtual display was added to the current state, but it does not have a
1953 // surface.
1954 sp<BBinder> displayToken = new BBinder();
1955
Dominik Laskowski075d3172018-05-24 15:50:06 -07001956 DisplayDeviceState state;
1957 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001958
Dominik Laskowski075d3172018-05-24 15:50:06 -07001959 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001960
1961 // --------------------------------------------------------------------
1962 // Call Expectations
1963
1964 // --------------------------------------------------------------------
1965 // Invocation
1966
1967 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1968
1969 // --------------------------------------------------------------------
1970 // Postconditions
1971
1972 // There will not be a display device set up.
1973 EXPECT_FALSE(hasDisplayDevice(displayToken));
1974
1975 // The drawing display state will be set from the current display state.
1976 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1977 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001978 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001979}
1980
1981TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1982 using Case = HwcVirtualDisplayCase;
1983
1984 // --------------------------------------------------------------------
1985 // Preconditions
1986
1987 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07001988 const auto displayId = Case::Display::DISPLAY_ID::get();
1989 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001990 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001991 Case::Display::injectHwcDisplay(this);
1992 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1993 existing.inject();
1994 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1995
1996 // --------------------------------------------------------------------
1997 // Call Expectations
1998
1999 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
2000
2001 // --------------------------------------------------------------------
2002 // Invocation
2003
2004 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2005
2006 // --------------------------------------------------------------------
2007 // Postconditions
2008
2009 // The existing token should have been removed
2010 verifyDisplayIsNotConnected(existing.token());
2011}
2012
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002013TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2014 using Case = NonHwcVirtualDisplayCase;
2015
2016 constexpr uint32_t oldLayerStack = 0u;
2017 constexpr uint32_t newLayerStack = 123u;
2018
2019 // --------------------------------------------------------------------
2020 // Preconditions
2021
2022 // A display is set up
2023 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2024 display.inject();
2025
2026 // There is a change to the layerStack state
2027 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2028 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2029
2030 // --------------------------------------------------------------------
2031 // Invocation
2032
2033 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2034
2035 // --------------------------------------------------------------------
2036 // Postconditions
2037
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002038 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002039}
2040
2041TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2042 using Case = NonHwcVirtualDisplayCase;
2043
2044 constexpr int oldTransform = 0;
2045 constexpr int newTransform = 2;
2046
2047 // --------------------------------------------------------------------
2048 // Preconditions
2049
2050 // A display is set up
2051 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2052 display.inject();
2053
2054 // There is a change to the orientation state
2055 display.mutableDrawingDisplayState().orientation = oldTransform;
2056 display.mutableCurrentDisplayState().orientation = newTransform;
2057
2058 // --------------------------------------------------------------------
2059 // Invocation
2060
2061 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2062
2063 // --------------------------------------------------------------------
2064 // Postconditions
2065
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002066 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002067}
2068
2069TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2070 using Case = NonHwcVirtualDisplayCase;
2071
2072 const Rect oldViewport(0, 0, 0, 0);
2073 const Rect newViewport(0, 0, 123, 456);
2074
2075 // --------------------------------------------------------------------
2076 // Preconditions
2077
2078 // A display is set up
2079 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2080 display.inject();
2081
2082 // There is a change to the viewport state
2083 display.mutableDrawingDisplayState().viewport = oldViewport;
2084 display.mutableCurrentDisplayState().viewport = newViewport;
2085
2086 // --------------------------------------------------------------------
2087 // Invocation
2088
2089 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2090
2091 // --------------------------------------------------------------------
2092 // Postconditions
2093
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002094 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002095}
2096
2097TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2098 using Case = NonHwcVirtualDisplayCase;
2099
2100 const Rect oldFrame(0, 0, 0, 0);
2101 const Rect newFrame(0, 0, 123, 456);
2102
2103 // --------------------------------------------------------------------
2104 // Preconditions
2105
2106 // A display is set up
2107 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2108 display.inject();
2109
2110 // There is a change to the viewport state
2111 display.mutableDrawingDisplayState().frame = oldFrame;
2112 display.mutableCurrentDisplayState().frame = newFrame;
2113
2114 // --------------------------------------------------------------------
2115 // Invocation
2116
2117 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2118
2119 // --------------------------------------------------------------------
2120 // Postconditions
2121
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002122 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002123}
2124
2125TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2126 using Case = NonHwcVirtualDisplayCase;
2127
2128 constexpr int oldWidth = 0;
2129 constexpr int oldHeight = 10;
2130 constexpr int newWidth = 123;
2131
2132 // --------------------------------------------------------------------
2133 // Preconditions
2134
2135 // A display is set up
2136 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002137 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002138 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002139 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2140 display.setNativeWindow(nativeWindow);
2141 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002142 // Setup injection expections
2143 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2144 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2145 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2146 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002147 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2148 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2149 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002150 display.inject();
2151
2152 // There is a change to the viewport state
2153 display.mutableDrawingDisplayState().width = oldWidth;
2154 display.mutableDrawingDisplayState().height = oldHeight;
2155 display.mutableCurrentDisplayState().width = newWidth;
2156 display.mutableCurrentDisplayState().height = oldHeight;
2157
2158 // --------------------------------------------------------------------
2159 // Call Expectations
2160
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002161 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002162
2163 // --------------------------------------------------------------------
2164 // Invocation
2165
2166 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2167}
2168
2169TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2170 using Case = NonHwcVirtualDisplayCase;
2171
2172 constexpr int oldWidth = 0;
2173 constexpr int oldHeight = 10;
2174 constexpr int newHeight = 123;
2175
2176 // --------------------------------------------------------------------
2177 // Preconditions
2178
2179 // A display is set up
2180 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002181 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002182 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002183 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2184 display.setNativeWindow(nativeWindow);
2185 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002186 // Setup injection expections
2187 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2188 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2189 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2190 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002191 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2192 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2193 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002194 display.inject();
2195
2196 // There is a change to the viewport state
2197 display.mutableDrawingDisplayState().width = oldWidth;
2198 display.mutableDrawingDisplayState().height = oldHeight;
2199 display.mutableCurrentDisplayState().width = oldWidth;
2200 display.mutableCurrentDisplayState().height = newHeight;
2201
2202 // --------------------------------------------------------------------
2203 // Call Expectations
2204
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002205 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002206
2207 // --------------------------------------------------------------------
2208 // Invocation
2209
2210 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2211}
2212
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002213/* ------------------------------------------------------------------------
2214 * SurfaceFlinger::setDisplayStateLocked
2215 */
2216
2217TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2218 // --------------------------------------------------------------------
2219 // Preconditions
2220
2221 // We have an unknown display token not associated with a known display
2222 sp<BBinder> displayToken = new BBinder();
2223
2224 // The requested display state references the unknown display.
2225 DisplayState state;
2226 state.what = DisplayState::eLayerStackChanged;
2227 state.token = displayToken;
2228 state.layerStack = 456;
2229
2230 // --------------------------------------------------------------------
2231 // Invocation
2232
2233 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2234
2235 // --------------------------------------------------------------------
2236 // Postconditions
2237
2238 // The returned flags are empty
2239 EXPECT_EQ(0u, flags);
2240
2241 // The display token still doesn't match anything known.
2242 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2243}
2244
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002245TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2246 using Case = SimplePrimaryDisplayCase;
2247
2248 // --------------------------------------------------------------------
2249 // Preconditions
2250
2251 // A display is already set up
2252 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2253 display.inject();
2254
2255 // No changes are made to the display
2256 DisplayState state;
2257 state.what = 0;
2258 state.token = display.token();
2259
2260 // --------------------------------------------------------------------
2261 // Invocation
2262
2263 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2264
2265 // --------------------------------------------------------------------
2266 // Postconditions
2267
2268 // The returned flags are empty
2269 EXPECT_EQ(0u, flags);
2270}
2271
2272TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2273 using Case = SimplePrimaryDisplayCase;
2274
2275 // --------------------------------------------------------------------
2276 // Preconditions
2277
2278 // A display is already set up
2279 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2280 display.inject();
2281
2282 // There is a surface that can be set.
2283 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2284
2285 // The current display state has the surface set
2286 display.mutableCurrentDisplayState().surface = surface;
2287
2288 // The incoming request sets the same surface
2289 DisplayState state;
2290 state.what = DisplayState::eSurfaceChanged;
2291 state.token = display.token();
2292 state.surface = surface;
2293
2294 // --------------------------------------------------------------------
2295 // Invocation
2296
2297 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2298
2299 // --------------------------------------------------------------------
2300 // Postconditions
2301
2302 // The returned flags are empty
2303 EXPECT_EQ(0u, flags);
2304
2305 // The current display state is unchanged.
2306 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2307}
2308
2309TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2310 using Case = SimplePrimaryDisplayCase;
2311
2312 // --------------------------------------------------------------------
2313 // Preconditions
2314
2315 // A display is already set up
2316 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2317 display.inject();
2318
2319 // There is a surface that can be set.
2320 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2321
2322 // The current display state does not have a surface
2323 display.mutableCurrentDisplayState().surface = nullptr;
2324
2325 // The incoming request sets a surface
2326 DisplayState state;
2327 state.what = DisplayState::eSurfaceChanged;
2328 state.token = display.token();
2329 state.surface = surface;
2330
2331 // --------------------------------------------------------------------
2332 // Invocation
2333
2334 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2335
2336 // --------------------------------------------------------------------
2337 // Postconditions
2338
2339 // The returned flags indicate a transaction is needed
2340 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2341
2342 // The current display layer stack state is set to the new value
2343 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2344}
2345
2346TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2347 using Case = SimplePrimaryDisplayCase;
2348
2349 // --------------------------------------------------------------------
2350 // Preconditions
2351
2352 // A display is already set up
2353 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2354 display.inject();
2355
2356 // The display has a layer stack set
2357 display.mutableCurrentDisplayState().layerStack = 456u;
2358
2359 // The incoming request sets the same layer stack
2360 DisplayState state;
2361 state.what = DisplayState::eLayerStackChanged;
2362 state.token = display.token();
2363 state.layerStack = 456u;
2364
2365 // --------------------------------------------------------------------
2366 // Invocation
2367
2368 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2369
2370 // --------------------------------------------------------------------
2371 // Postconditions
2372
2373 // The returned flags are empty
2374 EXPECT_EQ(0u, flags);
2375
2376 // The current display state is unchanged
2377 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2378}
2379
2380TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2381 using Case = SimplePrimaryDisplayCase;
2382
2383 // --------------------------------------------------------------------
2384 // Preconditions
2385
2386 // A display is set up
2387 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2388 display.inject();
2389
2390 // The display has a layer stack set
2391 display.mutableCurrentDisplayState().layerStack = 654u;
2392
2393 // The incoming request sets a different layer stack
2394 DisplayState state;
2395 state.what = DisplayState::eLayerStackChanged;
2396 state.token = display.token();
2397 state.layerStack = 456u;
2398
2399 // --------------------------------------------------------------------
2400 // Invocation
2401
2402 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2403
2404 // --------------------------------------------------------------------
2405 // Postconditions
2406
2407 // The returned flags indicate a transaction is needed
2408 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2409
2410 // The desired display state has been set to the new value.
2411 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2412}
2413
2414TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2415 using Case = SimplePrimaryDisplayCase;
2416 constexpr int initialOrientation = 180;
2417 const Rect initialFrame = {1, 2, 3, 4};
2418 const Rect initialViewport = {5, 6, 7, 8};
2419
2420 // --------------------------------------------------------------------
2421 // Preconditions
2422
2423 // A display is set up
2424 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2425 display.inject();
2426
2427 // The current display state projection state is all set
2428 display.mutableCurrentDisplayState().orientation = initialOrientation;
2429 display.mutableCurrentDisplayState().frame = initialFrame;
2430 display.mutableCurrentDisplayState().viewport = initialViewport;
2431
2432 // The incoming request sets the same projection state
2433 DisplayState state;
2434 state.what = DisplayState::eDisplayProjectionChanged;
2435 state.token = display.token();
2436 state.orientation = initialOrientation;
2437 state.frame = initialFrame;
2438 state.viewport = initialViewport;
2439
2440 // --------------------------------------------------------------------
2441 // Invocation
2442
2443 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2444
2445 // --------------------------------------------------------------------
2446 // Postconditions
2447
2448 // The returned flags are empty
2449 EXPECT_EQ(0u, flags);
2450
2451 // The current display state is unchanged
2452 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2453
2454 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2455 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2456}
2457
2458TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2459 using Case = SimplePrimaryDisplayCase;
2460 constexpr int initialOrientation = 90;
2461 constexpr int desiredOrientation = 180;
2462
2463 // --------------------------------------------------------------------
2464 // Preconditions
2465
2466 // A display is set up
2467 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2468 display.inject();
2469
2470 // The current display state has an orientation set
2471 display.mutableCurrentDisplayState().orientation = initialOrientation;
2472
2473 // The incoming request sets a different orientation
2474 DisplayState state;
2475 state.what = DisplayState::eDisplayProjectionChanged;
2476 state.token = display.token();
2477 state.orientation = desiredOrientation;
2478
2479 // --------------------------------------------------------------------
2480 // Invocation
2481
2482 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2483
2484 // --------------------------------------------------------------------
2485 // Postconditions
2486
2487 // The returned flags indicate a transaction is needed
2488 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2489
2490 // The current display state has the new value.
2491 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2492}
2493
2494TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2495 using Case = SimplePrimaryDisplayCase;
2496 const Rect initialFrame = {0, 0, 0, 0};
2497 const Rect desiredFrame = {5, 6, 7, 8};
2498
2499 // --------------------------------------------------------------------
2500 // Preconditions
2501
2502 // A display is set up
2503 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2504 display.inject();
2505
2506 // The current display state does not have a frame
2507 display.mutableCurrentDisplayState().frame = initialFrame;
2508
2509 // The incoming request sets a frame
2510 DisplayState state;
2511 state.what = DisplayState::eDisplayProjectionChanged;
2512 state.token = display.token();
2513 state.frame = desiredFrame;
2514
2515 // --------------------------------------------------------------------
2516 // Invocation
2517
2518 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2519
2520 // --------------------------------------------------------------------
2521 // Postconditions
2522
2523 // The returned flags indicate a transaction is needed
2524 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2525
2526 // The current display state has the new value.
2527 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2528}
2529
2530TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2531 using Case = SimplePrimaryDisplayCase;
2532 const Rect initialViewport = {0, 0, 0, 0};
2533 const Rect desiredViewport = {5, 6, 7, 8};
2534
2535 // --------------------------------------------------------------------
2536 // Preconditions
2537
2538 // A display is set up
2539 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2540 display.inject();
2541
2542 // The current display state does not have a viewport
2543 display.mutableCurrentDisplayState().viewport = initialViewport;
2544
2545 // The incoming request sets a viewport
2546 DisplayState state;
2547 state.what = DisplayState::eDisplayProjectionChanged;
2548 state.token = display.token();
2549 state.viewport = desiredViewport;
2550
2551 // --------------------------------------------------------------------
2552 // Invocation
2553
2554 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2555
2556 // --------------------------------------------------------------------
2557 // Postconditions
2558
2559 // The returned flags indicate a transaction is needed
2560 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2561
2562 // The current display state has the new value.
2563 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2564}
2565
2566TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2567 using Case = SimplePrimaryDisplayCase;
2568 constexpr uint32_t initialWidth = 1024;
2569 constexpr uint32_t initialHeight = 768;
2570
2571 // --------------------------------------------------------------------
2572 // Preconditions
2573
2574 // A display is set up
2575 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2576 display.inject();
2577
2578 // The current display state has a size set
2579 display.mutableCurrentDisplayState().width = initialWidth;
2580 display.mutableCurrentDisplayState().height = initialHeight;
2581
2582 // The incoming request sets the same display size
2583 DisplayState state;
2584 state.what = DisplayState::eDisplaySizeChanged;
2585 state.token = display.token();
2586 state.width = initialWidth;
2587 state.height = initialHeight;
2588
2589 // --------------------------------------------------------------------
2590 // Invocation
2591
2592 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2593
2594 // --------------------------------------------------------------------
2595 // Postconditions
2596
2597 // The returned flags are empty
2598 EXPECT_EQ(0u, flags);
2599
2600 // The current display state is unchanged
2601 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2602 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2603}
2604
2605TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2606 using Case = SimplePrimaryDisplayCase;
2607 constexpr uint32_t initialWidth = 0;
2608 constexpr uint32_t desiredWidth = 1024;
2609
2610 // --------------------------------------------------------------------
2611 // Preconditions
2612
2613 // A display is set up
2614 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2615 display.inject();
2616
2617 // The display does not yet have a width
2618 display.mutableCurrentDisplayState().width = initialWidth;
2619
2620 // The incoming request sets a display width
2621 DisplayState state;
2622 state.what = DisplayState::eDisplaySizeChanged;
2623 state.token = display.token();
2624 state.width = desiredWidth;
2625
2626 // --------------------------------------------------------------------
2627 // Invocation
2628
2629 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2630
2631 // --------------------------------------------------------------------
2632 // Postconditions
2633
2634 // The returned flags indicate a transaction is needed
2635 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2636
2637 // The current display state has the new value.
2638 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2639}
2640
2641TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2642 using Case = SimplePrimaryDisplayCase;
2643 constexpr uint32_t initialHeight = 0;
2644 constexpr uint32_t desiredHeight = 768;
2645
2646 // --------------------------------------------------------------------
2647 // Preconditions
2648
2649 // A display is set up
2650 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2651 display.inject();
2652
2653 // The display does not yet have a height
2654 display.mutableCurrentDisplayState().height = initialHeight;
2655
2656 // The incoming request sets a display height
2657 DisplayState state;
2658 state.what = DisplayState::eDisplaySizeChanged;
2659 state.token = display.token();
2660 state.height = desiredHeight;
2661
2662 // --------------------------------------------------------------------
2663 // Invocation
2664
2665 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2666
2667 // --------------------------------------------------------------------
2668 // Postconditions
2669
2670 // The returned flags indicate a transaction is needed
2671 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2672
2673 // The current display state has the new value.
2674 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2675}
2676
Lloyd Pique86016da2018-03-01 16:09:38 -08002677/* ------------------------------------------------------------------------
2678 * SurfaceFlinger::onInitializeDisplays
2679 */
2680
2681TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2682 using Case = SimplePrimaryDisplayCase;
2683
2684 // --------------------------------------------------------------------
2685 // Preconditions
2686
2687 // A primary display is set up
2688 Case::Display::injectHwcDisplay(this);
2689 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2690 primaryDisplay.inject();
2691
2692 // --------------------------------------------------------------------
2693 // Call Expectations
2694
2695 // We expect the surface interceptor to possibly be used, but we treat it as
2696 // disabled since it is called as a side effect rather than directly by this
2697 // function.
2698 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2699
2700 // We expect a call to get the active display config.
2701 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2702
2703 // We expect invalidate() to be invoked once to trigger display transaction
2704 // processing.
2705 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2706
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002707 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2708
Lloyd Pique86016da2018-03-01 16:09:38 -08002709 // --------------------------------------------------------------------
2710 // Invocation
2711
2712 mFlinger.onInitializeDisplays();
2713
2714 // --------------------------------------------------------------------
2715 // Postconditions
2716
2717 // The primary display should have a current state
2718 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2719 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2720 // The layer stack state should be set to zero
2721 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2722 // The orientation state should be set to zero
2723 EXPECT_EQ(0, primaryDisplayState.orientation);
2724
2725 // The frame state should be set to INVALID
2726 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2727
2728 // The viewport state should be set to INVALID
2729 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2730
2731 // The width and height should both be zero
2732 EXPECT_EQ(0u, primaryDisplayState.width);
2733 EXPECT_EQ(0u, primaryDisplayState.height);
2734
2735 // The display should be set to HWC_POWER_MODE_NORMAL
2736 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2737 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2738 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2739
2740 // The display refresh period should be set in the frame tracker.
2741 FrameStats stats;
2742 mFlinger.getAnimFrameTracker().getStats(&stats);
2743 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2744
2745 // The display transaction needed flag should be set.
2746 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2747
2748 // The compositor timing should be set to default values
2749 const auto& compositorTiming = mFlinger.getCompositorTiming();
2750 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2751 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2752 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2753}
2754
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002755/* ------------------------------------------------------------------------
2756 * SurfaceFlinger::setPowerModeInternal
2757 */
2758
2759// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07002760template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002761struct DozeIsSupportedVariant {
2762 static constexpr bool DOZE_SUPPORTED = true;
2763 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2764 IComposerClient::PowerMode::DOZE;
2765 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2766 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07002767
2768 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2769 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2770 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
2771 {Hwc2::DisplayCapability::DOZE})),
2772 Return(Error::NONE)));
2773 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002774};
2775
Peiyong Lined531a32018-10-26 18:27:56 -07002776template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002777// Used when we simulate a display that does not support doze.
2778struct DozeNotSupportedVariant {
2779 static constexpr bool DOZE_SUPPORTED = false;
2780 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2781 IComposerClient::PowerMode::ON;
2782 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2783 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07002784
2785 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2786 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2787 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
2788 Return(Error::NONE)));
2789 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002790};
2791
2792struct EventThreadBaseSupportedVariant {
2793 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
2794 // The event control thread should not be notified.
2795 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
2796
2797 // The event thread should not be notified.
2798 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
2799 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
2800 }
2801};
2802
2803struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
2804 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2805 // These calls are only expected for the primary display.
2806
2807 // Instead expect no calls.
2808 setupEventAndEventControlThreadNoCallExpectations(test);
2809 }
2810
2811 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2812 // These calls are only expected for the primary display.
2813
2814 // Instead expect no calls.
2815 setupEventAndEventControlThreadNoCallExpectations(test);
2816 }
2817};
2818
2819struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
2820 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2821 // The event control thread should be notified to enable vsyncs
2822 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
2823
2824 // The event thread should be notified that the screen was acquired.
2825 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
2826 }
2827
2828 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2829 // There should be a call to setVsyncEnabled(false)
2830 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
2831
2832 // The event thread should not be notified that the screen was released.
2833 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
2834 }
2835};
2836
Lloyd Pique41be5d22018-06-21 13:11:48 -07002837struct DispSyncIsSupportedVariant {
2838 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
2839 EXPECT_CALL(*test->mPrimaryDispSync, reset()).Times(1);
2840 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
2841 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
2842 }
2843
2844 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
2845 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
2846 }
2847};
2848
2849struct DispSyncNotSupportedVariant {
2850 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2851
2852 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2853};
2854
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002855// --------------------------------------------------------------------
2856// Note:
2857//
2858// There are a large number of transitions we could test, however we only test a
2859// selected subset which provides complete test coverage of the implementation.
2860// --------------------------------------------------------------------
2861
2862template <int initialPowerMode, int targetPowerMode>
2863struct TransitionVariantCommon {
2864 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
2865 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
2866
2867 static void verifyPostconditions(DisplayTransactionTest*) {}
2868};
2869
2870struct TransitionOffToOnVariant
2871 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
2872 template <typename Case>
2873 static void setupCallExpectations(DisplayTransactionTest* test) {
2874 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2875 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002876 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002877 Case::setupRepaintEverythingCallExpectations(test);
2878 }
2879
2880 static void verifyPostconditions(DisplayTransactionTest* test) {
2881 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2882 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2883 }
2884};
2885
2886struct TransitionOffToDozeSuspendVariant
2887 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
2888 template <typename Case>
2889 static void setupCallExpectations(DisplayTransactionTest* test) {
2890 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2891 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2892 Case::setupRepaintEverythingCallExpectations(test);
2893 }
2894
2895 static void verifyPostconditions(DisplayTransactionTest* test) {
2896 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2897 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2898 }
2899};
2900
2901struct TransitionOnToOffVariant
2902 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
2903 template <typename Case>
2904 static void setupCallExpectations(DisplayTransactionTest* test) {
2905 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002906 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002907 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2908 }
2909
2910 static void verifyPostconditions(DisplayTransactionTest* test) {
2911 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2912 }
2913};
2914
2915struct TransitionDozeSuspendToOffVariant
2916 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
2917 template <typename Case>
2918 static void setupCallExpectations(DisplayTransactionTest* test) {
2919 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2920 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2921 }
2922
2923 static void verifyPostconditions(DisplayTransactionTest* test) {
2924 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2925 }
2926};
2927
2928struct TransitionOnToDozeVariant
2929 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
2930 template <typename Case>
2931 static void setupCallExpectations(DisplayTransactionTest* test) {
2932 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2933 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2934 }
2935};
2936
2937struct TransitionDozeSuspendToDozeVariant
2938 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
2939 template <typename Case>
2940 static void setupCallExpectations(DisplayTransactionTest* test) {
2941 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002942 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002943 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2944 }
2945};
2946
2947struct TransitionDozeToOnVariant
2948 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
2949 template <typename Case>
2950 static void setupCallExpectations(DisplayTransactionTest* test) {
2951 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2952 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2953 }
2954};
2955
2956struct TransitionDozeSuspendToOnVariant
2957 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
2958 template <typename Case>
2959 static void setupCallExpectations(DisplayTransactionTest* test) {
2960 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002961 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002962 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2963 }
2964};
2965
2966struct TransitionOnToDozeSuspendVariant
2967 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
2968 template <typename Case>
2969 static void setupCallExpectations(DisplayTransactionTest* test) {
2970 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002971 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002972 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2973 }
2974};
2975
2976struct TransitionOnToUnknownVariant
2977 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
2978 template <typename Case>
2979 static void setupCallExpectations(DisplayTransactionTest* test) {
2980 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2981 Case::setupNoComposerPowerModeCallExpectations(test);
2982 }
2983};
2984
2985// --------------------------------------------------------------------
2986// Note:
2987//
2988// Rather than testing the cartesian product of of
2989// DozeIsSupported/DozeNotSupported with all other options, we use one for one
2990// display type, and the other for another display type.
2991// --------------------------------------------------------------------
2992
2993template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07002994 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002995struct DisplayPowerCase {
2996 using Display = DisplayVariant;
2997 using Doze = DozeVariant;
2998 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07002999 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003000 using Transition = TransitionVariant;
3001
3002 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003003 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003004 auto display = Display::makeFakeExistingDisplayInjector(test);
3005 display.inject();
3006 display.mutableDisplayDevice()->setPowerMode(mode);
3007 return display;
3008 }
3009
3010 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
3011 test->mFlinger.mutablePrimaryHWVsyncEnabled() = enabled;
3012 }
3013
3014 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3015 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3016 }
3017
3018 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3019 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3020 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3021 }
3022
3023 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3024 IComposerClient::PowerMode mode) {
3025 // Any calls to get the active config will return a default value.
3026 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3027 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3028 Return(Error::NONE)));
3029
3030 // Any calls to get whether the display supports dozing will return the value set by the
3031 // policy variant.
3032 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3033 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3034
3035 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3036 }
3037
3038 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3039 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3040 }
3041};
3042
3043// A sample configuration for the primary display.
3044// In addition to having event thread support, we emulate doze support.
3045template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003046using PrimaryDisplayPowerCase =
3047 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3048 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3049 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003050
3051// A sample configuration for the external display.
3052// In addition to not having event thread support, we emulate not having doze
3053// support.
3054template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003055using ExternalDisplayPowerCase =
3056 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3057 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3058 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003059
3060class SetPowerModeInternalTest : public DisplayTransactionTest {
3061public:
3062 template <typename Case>
3063 void transitionDisplayCommon();
3064};
3065
3066template <int PowerMode>
3067struct PowerModeInitialVSyncEnabled : public std::false_type {};
3068
3069template <>
3070struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3071
3072template <>
3073struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3074
3075template <typename Case>
3076void SetPowerModeInternalTest::transitionDisplayCommon() {
3077 // --------------------------------------------------------------------
3078 // Preconditions
3079
Peiyong Lined531a32018-10-26 18:27:56 -07003080 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003081 auto display =
3082 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3083 Case::setInitialPrimaryHWVsyncEnabled(this,
3084 PowerModeInitialVSyncEnabled<
3085 Case::Transition::INITIAL_POWER_MODE>::value);
3086
3087 // --------------------------------------------------------------------
3088 // Call Expectations
3089
3090 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3091 Case::Transition::template setupCallExpectations<Case>(this);
3092
3093 // --------------------------------------------------------------------
3094 // Invocation
3095
3096 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3097 Case::Transition::TARGET_POWER_MODE);
3098
3099 // --------------------------------------------------------------------
3100 // Postconditions
3101
3102 Case::Transition::verifyPostconditions(this);
3103}
3104
3105TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3106 using Case = SimplePrimaryDisplayCase;
3107
3108 // --------------------------------------------------------------------
3109 // Preconditions
3110
3111 // A primary display device is set up
3112 Case::Display::injectHwcDisplay(this);
3113 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3114 display.inject();
3115
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003116 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003117 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3118
3119 // --------------------------------------------------------------------
3120 // Invocation
3121
3122 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3123
3124 // --------------------------------------------------------------------
3125 // Postconditions
3126
3127 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3128}
3129
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003130TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003131 using Case = HwcVirtualDisplayCase;
3132
3133 // --------------------------------------------------------------------
3134 // Preconditions
3135
Dominik Laskowski075d3172018-05-24 15:50:06 -07003136 // Insert display data so that the HWC thinks it created the virtual display.
3137 const auto displayId = Case::Display::DISPLAY_ID::get();
3138 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003139 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003140
3141 // A virtual display device is set up
3142 Case::Display::injectHwcDisplay(this);
3143 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3144 display.inject();
3145
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003146 // The display is set to HWC_POWER_MODE_NORMAL
3147 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003148
3149 // --------------------------------------------------------------------
3150 // Invocation
3151
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003152 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003153
3154 // --------------------------------------------------------------------
3155 // Postconditions
3156
3157 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3158}
3159
3160TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3161 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3162}
3163
3164TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3165 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3166}
3167
3168TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3169 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3170}
3171
3172TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3173 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3174}
3175
3176TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3177 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3178}
3179
3180TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3181 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3182}
3183
3184TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3185 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3186}
3187
3188TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3189 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3190}
3191
3192TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3193 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3194}
3195
3196TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3197 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3198}
3199
3200TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3201 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3202}
3203
3204TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3205 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3206}
3207
3208TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3209 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3210}
3211
3212TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3213 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3214}
3215
3216TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3217 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3218}
3219
3220TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3221 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3222}
3223
3224TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3225 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3226}
3227
3228TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3229 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3230}
3231
3232TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3233 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3234}
3235
3236TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3237 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3238}
3239
Lloyd Piquef58625d2017-12-19 13:22:33 -08003240} // namespace
3241} // namespace android