blob: b7464d2fdae8d8ecd426de437037040d79c8b24a [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::_;
48using testing::ByMove;
49using testing::DoAll;
50using testing::Mock;
51using 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
Dominik Laskowski1eba0202019-01-24 09:14:40 -0800324 static constexpr auto displayType() {
325 return static_cast<bool>(PRIMARY) ? EventThread::DisplayType::Primary
326 : EventThread::DisplayType::External;
327 }
328
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800329 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700330 auto injector =
331 FakeDisplayDeviceInjector(test->mFlinger, DISPLAY_ID::get(),
332 static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY));
333
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800334 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700335 injector.setNativeWindow(test->mNativeWindow);
336
337 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800338 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700339 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
340 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
341 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
342 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800343 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
344 .WillRepeatedly(Return(0));
345 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
346 .WillRepeatedly(Return(0));
347 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
348 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800349 return injector;
350 }
351
352 // Called by tests to set up any native window creation call expectations.
353 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
354 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
355 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800356
Alec Mouriba013fa2018-10-16 12:43:11 -0700357 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
358 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
359 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
360 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800361 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
362 .WillRepeatedly(Return(0));
363 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
364 .WillRepeatedly(Return(0));
365 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
366 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800367 }
368
369 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
370 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
371 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
372 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
373 .WillRepeatedly(Return(NO_ERROR));
374 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
375 .WillRepeatedly(Return(NO_ERROR));
376 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
377 .WillRepeatedly(Return(NO_ERROR));
378 }
379
380 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
381 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
382 }
383};
384
Dominik Laskowski075d3172018-05-24 15:50:06 -0700385template <hwc2_display_t hwcDisplayId, HWC2::DisplayType hwcDisplayType, typename DisplayVariant,
386 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800387struct HwcDisplayVariant {
388 // The display id supplied by the HWC
389 static constexpr hwc2_display_t HWC_DISPLAY_ID = hwcDisplayId;
390
391 // The HWC display type
392 static constexpr HWC2::DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
393
394 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700395 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800396
397 static void injectPendingHotplugEvent(DisplayTransactionTest* test,
398 HWC2::Connection connection) {
399 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
400 HotplugEvent{HWC_DISPLAY_ID, connection});
401 }
402
403 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800404 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700405 const auto displayId = DisplayVariant::DISPLAY_ID::get();
406 ASSERT_TRUE(displayId);
407 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
408 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800409 .setHwcDisplayId(HWC_DISPLAY_ID)
410 .setWidth(DisplayVariant::WIDTH)
411 .setHeight(DisplayVariant::HEIGHT)
412 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
413 .inject(&test->mFlinger, test->mComposer);
414 }
415
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800416 // Called by tests to inject a HWC display setup
417 static void injectHwcDisplay(DisplayTransactionTest* test) {
418 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
419 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
420 Return(Error::NONE)));
421 injectHwcDisplayWithNoDefaultCapabilities(test);
422 }
423
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800424 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
425 EXPECT_CALL(*test->mComposer, getDisplayType(HWC_DISPLAY_ID, _))
426 .WillOnce(DoAll(SetArgPointee<1>(static_cast<IComposerClient::DisplayType>(
427 HWC_DISPLAY_TYPE)),
428 Return(Error::NONE)));
429 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
430 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
431 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
432 Return(Error::NONE)));
433 EXPECT_CALL(*test->mComposer,
434 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
435 IComposerClient::Attribute::WIDTH, _))
436 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
437 EXPECT_CALL(*test->mComposer,
438 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
439 IComposerClient::Attribute::HEIGHT, _))
440 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
441 EXPECT_CALL(*test->mComposer,
442 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
443 IComposerClient::Attribute::VSYNC_PERIOD, _))
444 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
445 EXPECT_CALL(*test->mComposer,
446 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
447 IComposerClient::Attribute::DPI_X, _))
448 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
449 EXPECT_CALL(*test->mComposer,
450 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
451 IComposerClient::Attribute::DPI_Y, _))
452 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800453 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
454 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
455 Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700456
457 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
458 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
459 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
460 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
461 Return(Error::NONE)));
462 } else {
463 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
464 .WillOnce(Return(Error::UNSUPPORTED));
465 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800466 }
467
468 // Called by tests to set up HWC call expectations
469 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
470 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700471 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800472 }
473};
474
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800475// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
476constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
477 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
478
Dominik Laskowski075d3172018-05-24 15:50:06 -0700479template <hwc2_display_t hwcDisplayId, typename PhysicalDisplay, int width, int height,
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800480 Critical critical>
481struct PhysicalDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700482 : DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height, critical, Async::FALSE,
483 Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
484 HwcDisplayVariant<hwcDisplayId, HWC2::DisplayType::Physical,
485 DisplayVariant<PhysicalDisplayId<PhysicalDisplay>, width, height,
486 critical, Async::FALSE, Secure::TRUE,
487 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
488 PhysicalDisplay> {};
489
490template <bool hasIdentificationData>
491struct PrimaryDisplay {
492 static constexpr Primary PRIMARY = Primary::TRUE;
493 static constexpr uint8_t PORT = 255;
494 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
495 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
496};
497
498template <bool hasIdentificationData>
499struct ExternalDisplay {
500 static constexpr Primary PRIMARY = Primary::FALSE;
501 static constexpr uint8_t PORT = 254;
502 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
503 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
504};
505
506struct TertiaryDisplay {
507 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800508 static constexpr uint8_t PORT = 253;
509 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700510};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800511
512// A primary display is a physical display that is critical
513using PrimaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700514 PhysicalDisplayVariant<1001, PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800515
516// An external display is physical display that is not critical.
517using ExternalDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700518 PhysicalDisplayVariant<1002, ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800519
520using TertiaryDisplayVariant =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700521 PhysicalDisplayVariant<1003, TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800522
523// A virtual display not supported by the HWC.
524constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
525
526template <int width, int height, Secure secure>
527struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700528 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
529 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
530 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
531 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
532
533 static void injectHwcDisplay(DisplayTransactionTest*) {}
534
535 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
536 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
537 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800538
539 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
540 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
541 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
542 }
543};
544
545// A virtual display supported by the HWC.
546constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
547
548template <int width, int height, Secure secure>
549struct HwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700550 : DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE, secure,
551 Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
552 HwcDisplayVariant<
553 1010, HWC2::DisplayType::Virtual,
554 DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
555 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
556 using Base = DisplayVariant<VirtualDisplayId<42>, width, height, Critical::FALSE, Async::TRUE,
557 secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800558 using Self = HwcVirtualDisplayVariant<width, height, secure>;
559
560 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
561 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
562 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
563 }
564
565 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
566 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
567 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
568 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
569 }
570};
571
572// For this variant, SurfaceFlinger should not configure itself with wide
573// display support, so the display should not be configured for wide-color
574// support.
575struct WideColorSupportNotConfiguredVariant {
576 static constexpr bool WIDE_COLOR_SUPPORTED = false;
577
578 static void injectConfigChange(DisplayTransactionTest* test) {
579 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700580 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800581 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
582 }
583
584 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
585 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
586 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
587 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
588 }
589};
590
591// For this variant, SurfaceFlinger should configure itself with wide display
592// support, and the display should respond with an non-empty list of supported
593// color modes. Wide-color support should be configured.
594template <typename Display>
595struct WideColorP3ColorimetricSupportedVariant {
596 static constexpr bool WIDE_COLOR_SUPPORTED = true;
597
598 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700599 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800600 test->mFlinger.mutableHasWideColorDisplay() = true;
601 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
602 }
603
604 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800605 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
606
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800607 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
608 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
609 Return(Error::NONE)));
610 EXPECT_CALL(*test->mComposer,
611 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
612 .WillOnce(DoAll(SetArgPointee<2>(
613 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
614 Return(Error::NONE)));
615 EXPECT_CALL(*test->mComposer,
616 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
617 RenderIntent::COLORIMETRIC))
618 .WillOnce(Return(Error::NONE));
619 }
620};
621
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800622// For this variant, SurfaceFlinger should configure itself with wide display
623// support, but the display should respond with an empty list of supported color
624// modes. Wide-color support for the display should not be configured.
625template <typename Display>
626struct WideColorNotSupportedVariant {
627 static constexpr bool WIDE_COLOR_SUPPORTED = false;
628
629 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700630 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800631 test->mFlinger.mutableHasWideColorDisplay() = true;
632 }
633
634 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
635 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
636 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700637 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800638 }
639};
640
641// For this variant, the display is not a HWC display, so no HDR support should
642// be configured.
643struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800644 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800645 static constexpr bool HDR10_SUPPORTED = false;
646 static constexpr bool HDR_HLG_SUPPORTED = false;
647 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
648 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
649 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
650 }
651};
652
Valerie Haue9e843a2018-12-18 13:39:23 -0800653template <typename Display>
654struct Hdr10PlusSupportedVariant {
655 static constexpr bool HDR10_PLUS_SUPPORTED = true;
656 static constexpr bool HDR10_SUPPORTED = true;
657 static constexpr bool HDR_HLG_SUPPORTED = false;
658 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
659 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
660 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
661 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
662 Hdr::HDR10_PLUS,
663 Hdr::HDR10,
664 })),
665 Return(Error::NONE)));
666 }
667};
668
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800669// For this variant, the composer should respond with a non-empty list of HDR
670// modes containing HDR10, so HDR10 support should be configured.
671template <typename Display>
672struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800673 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800674 static constexpr bool HDR10_SUPPORTED = true;
675 static constexpr bool HDR_HLG_SUPPORTED = false;
676 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
677 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
678 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
679 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
680 Return(Error::NONE)));
681 }
682};
683
684// For this variant, the composer should respond with a non-empty list of HDR
685// modes containing HLG, so HLG support should be configured.
686template <typename Display>
687struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800688 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800689 static constexpr bool HDR10_SUPPORTED = false;
690 static constexpr bool HDR_HLG_SUPPORTED = true;
691 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
692 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
693 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
694 .WillOnce(
695 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
696 }
697};
698
699// For this variant, the composer should respond with a non-empty list of HDR
700// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
701template <typename Display>
702struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800703 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800704 static constexpr bool HDR10_SUPPORTED = false;
705 static constexpr bool HDR_HLG_SUPPORTED = false;
706 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
707 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
708 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
709 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
710 Return(Error::NONE)));
711 }
712};
713
714// For this variant, the composer should respond with am empty list of HDR
715// modes, so no HDR support should be configured.
716template <typename Display>
717struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800718 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800719 static constexpr bool HDR10_SUPPORTED = false;
720 static constexpr bool HDR_HLG_SUPPORTED = false;
721 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
722 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
723 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
724 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
725 }
726};
727
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700728struct NonHwcPerFrameMetadataSupportVariant {
729 static constexpr int PER_FRAME_METADATA_KEYS = 0;
730 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800731 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700732 }
733};
734
735template <typename Display>
736struct NoPerFrameMetadataSupportVariant {
737 static constexpr int PER_FRAME_METADATA_KEYS = 0;
738 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800739 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
740 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700741 }
742};
743
744template <typename Display>
745struct Smpte2086PerFrameMetadataSupportVariant {
746 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
747 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800748 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
749 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800750 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
751 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
752 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
753 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
754 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
755 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
756 PerFrameMetadataKey::WHITE_POINT_X,
757 PerFrameMetadataKey::WHITE_POINT_Y,
758 PerFrameMetadataKey::MAX_LUMINANCE,
759 PerFrameMetadataKey::MIN_LUMINANCE,
760 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700761 }
762};
763
764template <typename Display>
765struct Cta861_3_PerFrameMetadataSupportVariant {
766 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
767 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800768 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
769 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800770 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
771 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
772 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700773 }
774};
775
Valerie Haue9e843a2018-12-18 13:39:23 -0800776template <typename Display>
777struct Hdr10_Plus_PerFrameMetadataSupportVariant {
778 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
779 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
780 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
781 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
782 PerFrameMetadataKey::HDR10_PLUS_SEI,
783 })));
784 }
785};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800786/* ------------------------------------------------------------------------
787 * Typical display configurations to test
788 */
789
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700790template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
791 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800792struct Case {
793 using Display = DisplayPolicy;
794 using WideColorSupport = WideColorSupportPolicy;
795 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700796 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800797};
798
799using SimplePrimaryDisplayCase =
800 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700801 HdrNotSupportedVariant<PrimaryDisplayVariant>,
802 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800803using SimpleExternalDisplayCase =
804 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700805 HdrNotSupportedVariant<ExternalDisplayVariant>,
806 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800807using SimpleTertiaryDisplayCase =
808 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700809 HdrNotSupportedVariant<TertiaryDisplayVariant>,
810 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800811using NonHwcVirtualDisplayCase =
812 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700813 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
814 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800815using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
816using HwcVirtualDisplayCase =
817 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -0700818 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +0800819 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800820using WideColorP3ColorimetricDisplayCase =
821 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700822 HdrNotSupportedVariant<PrimaryDisplayVariant>,
823 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -0800824using Hdr10PlusDisplayCase =
825 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
826 Hdr10SupportedVariant<PrimaryDisplayVariant>,
827 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800828using Hdr10DisplayCase =
829 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700830 Hdr10SupportedVariant<PrimaryDisplayVariant>,
831 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800832using HdrHlgDisplayCase =
833 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700834 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
835 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800836using HdrDolbyVisionDisplayCase =
837 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700838 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
839 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
840using HdrSmpte2086DisplayCase =
841 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
842 HdrNotSupportedVariant<PrimaryDisplayVariant>,
843 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
844using HdrCta861_3_DisplayCase =
845 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
846 HdrNotSupportedVariant<PrimaryDisplayVariant>,
847 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -0700848
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800849/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -0800850 *
851 * SurfaceFlinger::onHotplugReceived
852 */
853
854TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
855 constexpr int currentSequenceId = 123;
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700856 constexpr hwc2_display_t hwcDisplayId1 = 456;
857 constexpr hwc2_display_t hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -0800858
859 // --------------------------------------------------------------------
860 // Preconditions
861
862 // Set the current sequence id for accepted events
863 mFlinger.mutableComposerSequenceId() = currentSequenceId;
864
865 // Set the main thread id so that the current thread does not appear to be
866 // the main thread.
867 mFlinger.mutableMainThreadId() = std::thread::id();
868
869 // --------------------------------------------------------------------
870 // Call Expectations
871
872 // We expect invalidate() to be invoked once to trigger display transaction
873 // processing.
874 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
875
876 // --------------------------------------------------------------------
877 // Invocation
878
879 // Simulate two hotplug events (a connect and a disconnect)
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700880 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, HWC2::Connection::Connected);
881 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, HWC2::Connection::Disconnected);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800882
883 // --------------------------------------------------------------------
884 // Postconditions
885
886 // The display transaction needed flag should be set.
887 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
888
889 // All events should be in the pending event queue.
890 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
891 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700892 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800893 EXPECT_EQ(HWC2::Connection::Connected, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700894 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Lloyd Pique6cf11032018-01-22 18:57:44 -0800895 EXPECT_EQ(HWC2::Connection::Disconnected, pendingEvents[1].connection);
896}
897
898TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
899 constexpr int currentSequenceId = 123;
900 constexpr int otherSequenceId = 321;
901 constexpr hwc2_display_t displayId = 456;
902
903 // --------------------------------------------------------------------
904 // Preconditions
905
906 // Set the current sequence id for accepted events
907 mFlinger.mutableComposerSequenceId() = currentSequenceId;
908
909 // Set the main thread id so that the current thread does not appear to be
910 // the main thread.
911 mFlinger.mutableMainThreadId() = std::thread::id();
912
913 // --------------------------------------------------------------------
914 // Call Expectations
915
916 // We do not expect any calls to invalidate().
917 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
918
919 // --------------------------------------------------------------------
920 // Invocation
921
922 // Call with an unexpected sequence id
923 mFlinger.onHotplugReceived(otherSequenceId, displayId, HWC2::Connection::Invalid);
924
925 // --------------------------------------------------------------------
926 // Postconditions
927
928 // The display transaction needed flag should not be set
929 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
930
931 // There should be no pending events
932 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
933}
934
935TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
936 constexpr int currentSequenceId = 123;
937 constexpr hwc2_display_t displayId1 = 456;
938
939 // --------------------------------------------------------------------
940 // Note:
941 // --------------------------------------------------------------------
942 // This test case is a bit tricky. We want to verify that
943 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
944 // don't really want to provide coverage for everything the later function
945 // does as there are specific tests for it.
946 // --------------------------------------------------------------------
947
948 // --------------------------------------------------------------------
949 // Preconditions
950
951 // Set the current sequence id for accepted events
952 mFlinger.mutableComposerSequenceId() = currentSequenceId;
953
954 // Set the main thread id so that the current thread does appear to be the
955 // main thread.
956 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
957
958 // --------------------------------------------------------------------
959 // Call Expectations
960
961 // We expect invalidate() to be invoked once to trigger display transaction
962 // processing.
963 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
964
965 // --------------------------------------------------------------------
966 // Invocation
967
968 // Simulate a disconnect on a display id that is not connected. This should
969 // be enqueued by onHotplugReceived(), and dequeued by
970 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
971 mFlinger.onHotplugReceived(currentSequenceId, displayId1, HWC2::Connection::Disconnected);
972
973 // --------------------------------------------------------------------
974 // Postconditions
975
976 // The display transaction needed flag should be set.
977 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
978
979 // There should be no event queued on return, as it should have been
980 // processed.
981 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
982}
983
984/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -0800985 * SurfaceFlinger::createDisplay
986 */
987
988TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
989 const String8 name("virtual.test");
990
991 // --------------------------------------------------------------------
992 // Call Expectations
993
994 // The call should notify the interceptor that a display was created.
995 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
996
997 // --------------------------------------------------------------------
998 // Invocation
999
1000 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1001
1002 // --------------------------------------------------------------------
1003 // Postconditions
1004
1005 // The display should have been added to the current state
1006 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1007 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001008 EXPECT_TRUE(display.isVirtual());
1009 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001010 EXPECT_EQ(name.string(), display.displayName);
1011
1012 // --------------------------------------------------------------------
1013 // Cleanup conditions
1014
1015 // Destroying the display invalidates the display state.
1016 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1017}
1018
1019TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1020 const String8 name("virtual.test");
1021
1022 // --------------------------------------------------------------------
1023 // Call Expectations
1024
1025 // The call should notify the interceptor that a display was created.
1026 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1027
1028 // --------------------------------------------------------------------
1029 // Invocation
1030
1031 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1032
1033 // --------------------------------------------------------------------
1034 // Postconditions
1035
1036 // The display should have been added to the current state
1037 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1038 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001039 EXPECT_TRUE(display.isVirtual());
1040 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001041 EXPECT_EQ(name.string(), display.displayName);
1042
1043 // --------------------------------------------------------------------
1044 // Cleanup conditions
1045
1046 // Destroying the display invalidates the display state.
1047 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1048}
1049
1050/* ------------------------------------------------------------------------
1051 * SurfaceFlinger::destroyDisplay
1052 */
1053
1054TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1055 using Case = NonHwcVirtualDisplayCase;
1056
1057 // --------------------------------------------------------------------
1058 // Preconditions
1059
1060 // A virtual display exists
1061 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1062 existing.inject();
1063
1064 // --------------------------------------------------------------------
1065 // Call Expectations
1066
1067 // The call should notify the interceptor that a display was created.
1068 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1069
1070 // Destroying the display invalidates the display state.
1071 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1072
1073 // --------------------------------------------------------------------
1074 // Invocation
1075
1076 mFlinger.destroyDisplay(existing.token());
1077
1078 // --------------------------------------------------------------------
1079 // Postconditions
1080
1081 // The display should have been removed from the current state
1082 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1083
1084 // Ths display should still exist in the drawing state
1085 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1086
1087 // The display transaction needed flasg should be set
1088 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1089}
1090
1091TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1092 // --------------------------------------------------------------------
1093 // Preconditions
1094
1095 sp<BBinder> displayToken = new BBinder();
1096
1097 // --------------------------------------------------------------------
1098 // Invocation
1099
1100 mFlinger.destroyDisplay(displayToken);
1101}
1102
1103/* ------------------------------------------------------------------------
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001104 * SurfaceFlinger::resetDisplayState
1105 */
1106
1107TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
1108 using Case = NonHwcVirtualDisplayCase;
1109
1110 // --------------------------------------------------------------------
1111 // Preconditions
1112
1113 // vsync is enabled and available
1114 mFlinger.mutablePrimaryHWVsyncEnabled() = true;
1115 mFlinger.mutableHWVsyncAvailable() = true;
1116
1117 // A display exists
1118 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1119 existing.inject();
1120
1121 // --------------------------------------------------------------------
1122 // Call Expectations
1123
1124 // The call disable vsyncs
1125 EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);
1126
Lloyd Pique41be5d22018-06-21 13:11:48 -07001127 // The call ends any display resyncs
1128 EXPECT_CALL(*mPrimaryDispSync, endResync()).Times(1);
1129
Lloyd Piqued6fbb8a2018-01-22 19:08:36 -08001130 // --------------------------------------------------------------------
1131 // Invocation
1132
1133 mFlinger.resetDisplayState();
1134
1135 // --------------------------------------------------------------------
1136 // Postconditions
1137
1138 // vsyncs should be off and not available.
1139 EXPECT_FALSE(mFlinger.mutablePrimaryHWVsyncEnabled());
1140 EXPECT_FALSE(mFlinger.mutableHWVsyncAvailable());
1141
1142 // The display should have been removed from the display map.
1143 EXPECT_FALSE(hasDisplayDevice(existing.token()));
1144
1145 // The display should still exist in the current state
1146 EXPECT_TRUE(hasCurrentDisplayState(existing.token()));
1147
1148 // The display should have been removed from the drawing state
1149 EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
1150}
1151
1152/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001153 * DisplayDevice::GetBestColorMode
1154 */
1155class GetBestColorModeTest : public DisplayTransactionTest {
1156public:
Dominik Laskowski34157762018-10-31 13:07:19 -07001157 static constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001158
Valerie Hau9758ae02018-10-09 16:05:09 -07001159 GetBestColorModeTest()
1160 : DisplayTransactionTest(),
Dominik Laskowski075d3172018-05-24 15:50:06 -07001161 mInjector(FakeDisplayDeviceInjector(mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */,
1162 true /* isPrimary */)) {}
Valerie Hau9758ae02018-10-09 16:05:09 -07001163
1164 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1165
1166 void addHwcColorModesMapping(ui::ColorMode colorMode,
1167 std::vector<ui::RenderIntent> renderIntents) {
1168 mHwcColorModes[colorMode] = renderIntents;
1169 }
1170
1171 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1172
1173 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1174
1175 void getBestColorMode() {
1176 mInjector.setHwcColorModes(mHwcColorModes);
1177 mInjector.setHasWideColorGamut(mHasWideColorGamut);
Alec Mouriba013fa2018-10-16 12:43:11 -07001178 mInjector.setNativeWindow(mNativeWindow);
1179
1180 // Creating a DisplayDevice requires getting default dimensions from the
1181 // native window.
1182 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
1183 .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
1184 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
1185 .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001186 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
1187 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
1188 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Valerie Hau9758ae02018-10-09 16:05:09 -07001189 auto displayDevice = mInjector.inject();
1190
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001191 displayDevice->getCompositionDisplay()
1192 ->getDisplayColorProfile()
1193 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1194 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001195 }
1196
1197 ui::Dataspace mOutDataspace;
1198 ui::ColorMode mOutColorMode;
1199 ui::RenderIntent mOutRenderIntent;
1200
1201private:
1202 ui::Dataspace mInputDataspace;
1203 ui::RenderIntent mInputRenderIntent;
1204 bool mHasWideColorGamut = false;
1205 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
1206 FakeDisplayDeviceInjector mInjector;
1207};
1208
1209TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1210 addHwcColorModesMapping(ui::ColorMode::SRGB,
1211 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1212 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1213 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1214 setHasWideColorGamut(true);
1215
1216 getBestColorMode();
1217
Peiyong Lin14724e62018-12-05 07:27:30 -08001218 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001219 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1220 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1221}
1222
1223TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1224 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1225 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1226 addHwcColorModesMapping(ui::ColorMode::SRGB,
1227 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1228 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1229 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1230 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1231 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1232 setHasWideColorGamut(true);
1233
1234 getBestColorMode();
1235
1236 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1237 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1238 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1239}
1240
1241TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1242 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1243 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1244 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1245 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1246 setHasWideColorGamut(true);
1247
1248 getBestColorMode();
1249
1250 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1251 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1252 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1253}
1254
1255/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001256 * SurfaceFlinger::getDisplayNativePrimaries
1257 */
1258
1259class GetDisplayNativePrimaries : public DisplayTransactionTest {
1260public:
1261 GetDisplayNativePrimaries();
1262 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1263 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1264
1265private:
1266 static constexpr float mStartingTestValue = 1.0f;
1267};
1268
1269GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1270 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1271 injectFakeNativeWindowSurfaceFactory();
1272}
1273
1274void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1275 ui::DisplayPrimaries& primaries) {
1276 float startingVal = mStartingTestValue;
1277 primaries.red.X = startingVal++;
1278 primaries.red.Y = startingVal++;
1279 primaries.red.Z = startingVal++;
1280 primaries.green.X = startingVal++;
1281 primaries.green.Y = startingVal++;
1282 primaries.green.Z = startingVal++;
1283 primaries.blue.X = startingVal++;
1284 primaries.blue.Y = startingVal++;
1285 primaries.blue.Z = startingVal++;
1286 primaries.white.X = startingVal++;
1287 primaries.white.Y = startingVal++;
1288 primaries.white.Z = startingVal++;
1289}
1290
1291void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1292 const ui::DisplayPrimaries& primaries) {
1293 float startingVal = mStartingTestValue;
1294 EXPECT_EQ(primaries.red.X, startingVal++);
1295 EXPECT_EQ(primaries.red.Y, startingVal++);
1296 EXPECT_EQ(primaries.red.Z, startingVal++);
1297 EXPECT_EQ(primaries.green.X, startingVal++);
1298 EXPECT_EQ(primaries.green.Y, startingVal++);
1299 EXPECT_EQ(primaries.green.Z, startingVal++);
1300 EXPECT_EQ(primaries.blue.X, startingVal++);
1301 EXPECT_EQ(primaries.blue.Y, startingVal++);
1302 EXPECT_EQ(primaries.blue.Z, startingVal++);
1303 EXPECT_EQ(primaries.white.X, startingVal++);
1304 EXPECT_EQ(primaries.white.Y, startingVal++);
1305 EXPECT_EQ(primaries.white.Z, startingVal++);
1306}
1307
1308TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1309 ui::DisplayPrimaries primaries;
1310 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1311}
1312
1313TEST_F(GetDisplayNativePrimaries, internalDisplayWithDefaultPrimariesData) {
1314 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1315 injector.inject();
1316 auto internalDisplayToken = injector.token();
1317 // A nullptr would trigger a different execution path than what's being tested here
1318 EXPECT_NE(nullptr, internalDisplayToken.get());
1319
1320 mFlinger.initDefaultDisplayNativePrimaries();
1321
1322 ui::DisplayPrimaries primaries;
1323 // Expecting sRGB primaries
1324 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1325 EXPECT_EQ(primaries.red.X, 0.4123f);
1326 EXPECT_EQ(primaries.red.Y, 0.2126f);
1327 EXPECT_EQ(primaries.red.Z, 0.0193f);
1328 EXPECT_EQ(primaries.green.X, 0.3576f);
1329 EXPECT_EQ(primaries.green.Y, 0.7152f);
1330 EXPECT_EQ(primaries.green.Z, 0.1192f);
1331 EXPECT_EQ(primaries.blue.X, 0.1805f);
1332 EXPECT_EQ(primaries.blue.Y, 0.0722f);
1333 EXPECT_EQ(primaries.blue.Z, 0.9506f);
1334 EXPECT_EQ(primaries.white.X, 0.9505f);
1335 EXPECT_EQ(primaries.white.Y, 1.0000f);
1336 EXPECT_EQ(primaries.white.Z, 1.0891f);
1337}
1338
1339TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1340 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1341 injector.inject();
1342 auto internalDisplayToken = injector.token();
1343
1344 ui::DisplayPrimaries expectedPrimaries;
1345 populateDummyDisplayNativePrimaries(expectedPrimaries);
1346 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1347
1348 ui::DisplayPrimaries primaries;
1349 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1350
1351 checkDummyDisplayNativePrimaries(primaries);
1352}
1353
1354TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1355 sp<BBinder> notInternalDisplayToken = new BBinder();
1356
1357 ui::DisplayPrimaries primaries;
1358 populateDummyDisplayNativePrimaries(primaries);
1359 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
1360
1361 // Check primaries argument wasn't modified in case of failure
1362 checkDummyDisplayNativePrimaries(primaries);
1363}
1364
1365/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001366 * SurfaceFlinger::setupNewDisplayDeviceInternal
1367 */
1368
1369class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1370public:
1371 template <typename T>
1372 void setupNewDisplayDeviceInternalTest();
1373};
1374
1375template <typename Case>
1376void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1377 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001378 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1379 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001380 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001381
1382 // --------------------------------------------------------------------
1383 // Preconditions
1384
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001385 // Wide color displays support is configured appropriately
1386 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001387
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001388 // The display is setup with the HWC.
1389 Case::Display::injectHwcDisplay(this);
1390
1391 // SurfaceFlinger will use a test-controlled factory for native window
1392 // surfaces.
1393 injectFakeNativeWindowSurfaceFactory();
1394
1395 // --------------------------------------------------------------------
1396 // Call Expectations
1397
1398 // Various native window calls will be made.
1399 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001400 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001401 Case::WideColorSupport::setupComposerCallExpectations(this);
1402 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001403 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001404
1405 // --------------------------------------------------------------------
1406 // Invocation
1407
1408 DisplayDeviceState state;
Dominik Laskowski075d3172018-05-24 15:50:06 -07001409 state.displayId = static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1410 : Case::Display::DISPLAY_ID::get();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001411 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1412
Dominik Laskowski075d3172018-05-24 15:50:06 -07001413 auto device =
1414 mFlinger.setupNewDisplayDeviceInternal(displayToken, Case::Display::DISPLAY_ID::get(),
1415 state, displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001416
1417 // --------------------------------------------------------------------
1418 // Postconditions
1419
1420 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001421 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
1422 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001423 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001424 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001425 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1426 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1427 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001428 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001429 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1430 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1431 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001432 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1433 // remapped, and the test only ever sets up one config. If there were an error
1434 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
1435 EXPECT_EQ(0, device->getActiveConfig());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001436 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1437 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001438}
1439
1440TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1441 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1442}
1443
1444TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1445 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1446}
1447
1448TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1449 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1450}
1451
1452TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Dominik Laskowski075d3172018-05-24 15:50:06 -07001453 using Case = HwcVirtualDisplayCase;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001454
Dominik Laskowski075d3172018-05-24 15:50:06 -07001455 // Insert display data so that the HWC thinks it created the virtual display.
1456 const auto displayId = Case::Display::DISPLAY_ID::get();
1457 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001458 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001459
1460 setupNewDisplayDeviceInternalTest<Case>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001461}
1462
1463TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1464 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1465}
1466
Valerie Haue9e843a2018-12-18 13:39:23 -08001467TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1468 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1469}
1470
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001471TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1472 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1473}
1474
1475TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1476 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1477}
1478
1479TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1480 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1481}
1482
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001483TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1484 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1485}
1486
1487TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1488 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1489}
1490
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001491/* ------------------------------------------------------------------------
1492 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1493 */
1494
1495class HandleTransactionLockedTest : public DisplayTransactionTest {
1496public:
1497 template <typename Case>
1498 void setupCommonPreconditions();
1499
1500 template <typename Case>
1501 void setupCommonCallExpectationsForConnectProcessing();
1502
1503 template <typename Case>
1504 void setupCommonCallExpectationsForDisconnectProcessing();
1505
1506 template <typename Case>
1507 void processesHotplugConnectCommon();
1508
1509 template <typename Case>
1510 void ignoresHotplugConnectCommon();
1511
1512 template <typename Case>
1513 void processesHotplugDisconnectCommon();
1514
1515 template <typename Case>
1516 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1517
1518 template <typename Case>
1519 void verifyPhysicalDisplayIsConnected();
1520
1521 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1522};
1523
1524template <typename Case>
1525void HandleTransactionLockedTest::setupCommonPreconditions() {
1526 // Wide color displays support is configured appropriately
1527 Case::WideColorSupport::injectConfigChange(this);
1528
1529 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1530 injectFakeBufferQueueFactory();
1531
1532 // SurfaceFlinger will use a test-controlled factory for native window
1533 // surfaces.
1534 injectFakeNativeWindowSurfaceFactory();
1535}
1536
1537template <typename Case>
1538void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1539 Case::Display::setupHwcHotplugCallExpectations(this);
1540
1541 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1542 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1543 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1544 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1545
1546 Case::WideColorSupport::setupComposerCallExpectations(this);
1547 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001548 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001549
1550 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001551
1552 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::displayType(), true)).Times(1);
1553 EXPECT_CALL(*mSFEventThread, onHotplugReceived(Case::Display::displayType(), true)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001554}
1555
1556template <typename Case>
1557void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1558 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001559
1560 EXPECT_CALL(*mEventThread, onHotplugReceived(Case::Display::displayType(), false)).Times(1);
1561 EXPECT_CALL(*mSFEventThread, onHotplugReceived(Case::Display::displayType(), false)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001562}
1563
1564template <typename Case>
1565void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1566 // The display device should have been set up in the list of displays.
1567 ASSERT_TRUE(hasDisplayDevice(displayToken));
1568 const auto& device = getDisplayDevice(displayToken);
1569 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001570 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001571
1572 // The display should have been set up in the current display state
1573 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1574 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001575 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
1576 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1577 : Case::Display::DISPLAY_ID::get(),
1578 current.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001579
1580 // The display should have been set up in the drawing display state
1581 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1582 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001583 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
1584 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL) ? std::nullopt
1585 : Case::Display::DISPLAY_ID::get(),
1586 draw.displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001587}
1588
1589template <typename Case>
1590void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1591 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001592 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001593
Dominik Laskowski075d3172018-05-24 15:50:06 -07001594 // SF should have a display token.
1595 const auto displayId = Case::Display::DISPLAY_ID::get();
1596 ASSERT_TRUE(displayId);
1597 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1598 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001599
1600 verifyDisplayIsConnected<Case>(displayToken);
1601}
1602
1603void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1604 EXPECT_FALSE(hasDisplayDevice(displayToken));
1605 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1606 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1607}
1608
1609template <typename Case>
1610void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1611 // --------------------------------------------------------------------
1612 // Preconditions
1613
1614 setupCommonPreconditions<Case>();
1615
1616 // A hotplug connect event is enqueued for a display
1617 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001618
1619 // --------------------------------------------------------------------
1620 // Call Expectations
1621
1622 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001623
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001624 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001625
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001626 // --------------------------------------------------------------------
1627 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08001628
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001629 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08001630
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001631 // --------------------------------------------------------------------
1632 // Postconditions
1633
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001634 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08001635
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001636 // --------------------------------------------------------------------
1637 // Cleanup conditions
1638
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001639 EXPECT_CALL(*mComposer,
1640 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001641 .WillOnce(Return(Error::NONE));
1642 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08001643}
1644
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001645template <typename Case>
1646void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
1647 // --------------------------------------------------------------------
1648 // Preconditions
1649
1650 setupCommonPreconditions<Case>();
1651
1652 // A hotplug connect event is enqueued for a display
1653 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1654
1655 // --------------------------------------------------------------------
1656 // Invocation
1657
1658 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1659
1660 // --------------------------------------------------------------------
1661 // Postconditions
1662
1663 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001664 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001665}
1666
1667template <typename Case>
1668void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
1669 // --------------------------------------------------------------------
1670 // Preconditions
1671
1672 setupCommonPreconditions<Case>();
1673
1674 // A hotplug disconnect event is enqueued for a display
1675 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1676
1677 // The display is already completely set up.
1678 Case::Display::injectHwcDisplay(this);
1679 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1680 existing.inject();
1681
1682 // --------------------------------------------------------------------
1683 // Call Expectations
1684
1685 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
Lloyd Pique438e9e72018-09-04 18:06:08 -07001686 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
1687 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001688
1689 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1690
1691 // --------------------------------------------------------------------
1692 // Invocation
1693
1694 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1695
1696 // --------------------------------------------------------------------
1697 // Postconditions
1698
1699 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001700 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001701
Dominik Laskowski075d3172018-05-24 15:50:06 -07001702 // SF should not have a display token.
1703 const auto displayId = Case::Display::DISPLAY_ID::get();
1704 ASSERT_TRUE(displayId);
1705 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001706
1707 // The existing token should have been removed
1708 verifyDisplayIsNotConnected(existing.token());
1709}
1710
1711TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
1712 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1713}
1714
1715TEST_F(HandleTransactionLockedTest,
1716 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
1717 // Inject an external display.
1718 ExternalDisplayVariant::injectHwcDisplay(this);
1719
1720 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
1721}
1722
1723TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
1724 // Inject a primary display.
1725 PrimaryDisplayVariant::injectHwcDisplay(this);
1726
1727 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
1728}
1729
1730TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
1731 // Inject both a primary and external display.
1732 PrimaryDisplayVariant::injectHwcDisplay(this);
1733 ExternalDisplayVariant::injectHwcDisplay(this);
1734
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001735 // TODO: This is an unnecessary call.
1736 EXPECT_CALL(*mComposer,
1737 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
1738 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
1739 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
1740 Return(Error::NONE)));
1741
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001742 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1743
1744 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
1745}
1746
1747TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfExternalForVrComposer) {
1748 // Inject a primary display.
1749 PrimaryDisplayVariant::injectHwcDisplay(this);
1750
1751 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(true));
1752
1753 ignoresHotplugConnectCommon<SimpleExternalDisplayCase>();
1754}
1755
1756TEST_F(HandleTransactionLockedTest, processHotplugDisconnectPrimaryDisplay) {
1757 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
1758}
1759
1760TEST_F(HandleTransactionLockedTest, processHotplugDisconnectExternalDisplay) {
1761 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
1762}
1763
1764TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
1765 using Case = SimplePrimaryDisplayCase;
1766
1767 // --------------------------------------------------------------------
1768 // Preconditions
1769
1770 setupCommonPreconditions<Case>();
1771
1772 // A hotplug connect event is enqueued for a display
1773 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1774 // A hotplug disconnect event is also enqueued for the same display
1775 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1776
1777 // --------------------------------------------------------------------
1778 // Call Expectations
1779
1780 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1781
1782 setupCommonCallExpectationsForConnectProcessing<Case>();
1783 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1784
1785 EXPECT_CALL(*mComposer,
1786 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1787 .WillOnce(Return(Error::NONE));
1788 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1789
1790 // --------------------------------------------------------------------
1791 // Invocation
1792
1793 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1794
1795 // --------------------------------------------------------------------
1796 // Postconditions
1797
1798 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001799 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001800
Dominik Laskowski075d3172018-05-24 15:50:06 -07001801 // SF should not have a display token.
1802 const auto displayId = Case::Display::DISPLAY_ID::get();
1803 ASSERT_TRUE(displayId);
1804 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001805}
1806
1807TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
1808 using Case = SimplePrimaryDisplayCase;
1809
1810 // --------------------------------------------------------------------
1811 // Preconditions
1812
1813 setupCommonPreconditions<Case>();
1814
1815 // The display is already completely set up.
1816 Case::Display::injectHwcDisplay(this);
1817 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1818 existing.inject();
1819
1820 // A hotplug disconnect event is enqueued for a display
1821 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Disconnected);
1822 // A hotplug connect event is also enqueued for the same display
1823 Case::Display::injectPendingHotplugEvent(this, HWC2::Connection::Connected);
1824
1825 // --------------------------------------------------------------------
1826 // Call Expectations
1827
1828 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1829
1830 setupCommonCallExpectationsForConnectProcessing<Case>();
1831 setupCommonCallExpectationsForDisconnectProcessing<Case>();
1832
1833 // --------------------------------------------------------------------
1834 // Invocation
1835
1836 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1837
1838 // --------------------------------------------------------------------
1839 // Postconditions
1840
1841 // The existing token should have been removed
1842 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001843 const auto displayId = Case::Display::DISPLAY_ID::get();
1844 ASSERT_TRUE(displayId);
1845 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1846 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001847
1848 // A new display should be connected in its place
1849
1850 verifyPhysicalDisplayIsConnected<Case>();
1851
1852 // --------------------------------------------------------------------
1853 // Cleanup conditions
1854
1855 EXPECT_CALL(*mComposer,
1856 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
1857 .WillOnce(Return(Error::NONE));
1858 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1859}
1860
1861TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
1862 using Case = HwcVirtualDisplayCase;
1863
1864 // --------------------------------------------------------------------
1865 // Preconditions
1866
1867 // The HWC supports at least one virtual display
1868 injectMockComposer(1);
1869
1870 setupCommonPreconditions<Case>();
1871
1872 // A virtual display was added to the current state, and it has a
1873 // surface(producer)
1874 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07001875
Dominik Laskowski075d3172018-05-24 15:50:06 -07001876 DisplayDeviceState state;
1877 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001878
1879 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07001880 state.surface = surface;
1881 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001882
1883 // --------------------------------------------------------------------
1884 // Call Expectations
1885
1886 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1887 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1888
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001889 EXPECT_CALL(*mComposer, getDisplayCapabilities(Case::Display::HWC_DISPLAY_ID, _))
1890 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
1891 Return(Error::NONE)));
1892
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001893 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
1894 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
1895 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
1896 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
1897 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
1898 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
1899 Return(NO_ERROR)));
1900 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
1901 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
1902
1903 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
1904
Lloyd Pique86fa3db2019-02-04 18:46:01 -08001905 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001906 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
1907
1908 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
1909 Case::WideColorSupport::setupComposerCallExpectations(this);
1910 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001911 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001912
1913 // --------------------------------------------------------------------
1914 // Invocation
1915
1916 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1917
1918 // --------------------------------------------------------------------
1919 // Postconditions
1920
1921 // The display device should have been set up in the list of displays.
1922 verifyDisplayIsConnected<Case>(displayToken);
1923
1924 // --------------------------------------------------------------------
1925 // Cleanup conditions
1926
1927 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
1928 .WillOnce(Return(Error::NONE));
1929 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
1930}
1931
1932TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
1933 using Case = HwcVirtualDisplayCase;
1934
1935 // --------------------------------------------------------------------
1936 // Preconditions
1937
1938 // The HWC supports at least one virtual display
1939 injectMockComposer(1);
1940
1941 setupCommonPreconditions<Case>();
1942
1943 // A virtual display was added to the current state, but it does not have a
1944 // surface.
1945 sp<BBinder> displayToken = new BBinder();
1946
Dominik Laskowski075d3172018-05-24 15:50:06 -07001947 DisplayDeviceState state;
1948 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001949
Dominik Laskowski075d3172018-05-24 15:50:06 -07001950 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001951
1952 // --------------------------------------------------------------------
1953 // Call Expectations
1954
1955 // --------------------------------------------------------------------
1956 // Invocation
1957
1958 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1959
1960 // --------------------------------------------------------------------
1961 // Postconditions
1962
1963 // There will not be a display device set up.
1964 EXPECT_FALSE(hasDisplayDevice(displayToken));
1965
1966 // The drawing display state will be set from the current display state.
1967 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1968 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001969 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001970}
1971
1972TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
1973 using Case = HwcVirtualDisplayCase;
1974
1975 // --------------------------------------------------------------------
1976 // Preconditions
1977
1978 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07001979 const auto displayId = Case::Display::DISPLAY_ID::get();
1980 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08001981 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001982 Case::Display::injectHwcDisplay(this);
1983 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1984 existing.inject();
1985 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
1986
1987 // --------------------------------------------------------------------
1988 // Call Expectations
1989
1990 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillRepeatedly(Return(false));
1991
1992 // --------------------------------------------------------------------
1993 // Invocation
1994
1995 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
1996
1997 // --------------------------------------------------------------------
1998 // Postconditions
1999
2000 // The existing token should have been removed
2001 verifyDisplayIsNotConnected(existing.token());
2002}
2003
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002004TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2005 using Case = NonHwcVirtualDisplayCase;
2006
2007 constexpr uint32_t oldLayerStack = 0u;
2008 constexpr uint32_t newLayerStack = 123u;
2009
2010 // --------------------------------------------------------------------
2011 // Preconditions
2012
2013 // A display is set up
2014 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2015 display.inject();
2016
2017 // There is a change to the layerStack state
2018 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2019 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2020
2021 // --------------------------------------------------------------------
2022 // Invocation
2023
2024 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2025
2026 // --------------------------------------------------------------------
2027 // Postconditions
2028
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002029 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002030}
2031
2032TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2033 using Case = NonHwcVirtualDisplayCase;
2034
2035 constexpr int oldTransform = 0;
2036 constexpr int newTransform = 2;
2037
2038 // --------------------------------------------------------------------
2039 // Preconditions
2040
2041 // A display is set up
2042 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2043 display.inject();
2044
2045 // There is a change to the orientation state
2046 display.mutableDrawingDisplayState().orientation = oldTransform;
2047 display.mutableCurrentDisplayState().orientation = newTransform;
2048
2049 // --------------------------------------------------------------------
2050 // Invocation
2051
2052 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2053
2054 // --------------------------------------------------------------------
2055 // Postconditions
2056
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002057 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002058}
2059
2060TEST_F(HandleTransactionLockedTest, processesDisplayViewportChanges) {
2061 using Case = NonHwcVirtualDisplayCase;
2062
2063 const Rect oldViewport(0, 0, 0, 0);
2064 const Rect newViewport(0, 0, 123, 456);
2065
2066 // --------------------------------------------------------------------
2067 // Preconditions
2068
2069 // A display is set up
2070 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2071 display.inject();
2072
2073 // There is a change to the viewport state
2074 display.mutableDrawingDisplayState().viewport = oldViewport;
2075 display.mutableCurrentDisplayState().viewport = newViewport;
2076
2077 // --------------------------------------------------------------------
2078 // Invocation
2079
2080 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2081
2082 // --------------------------------------------------------------------
2083 // Postconditions
2084
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002085 EXPECT_EQ(newViewport, display.mutableDisplayDevice()->getViewport());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002086}
2087
2088TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2089 using Case = NonHwcVirtualDisplayCase;
2090
2091 const Rect oldFrame(0, 0, 0, 0);
2092 const Rect newFrame(0, 0, 123, 456);
2093
2094 // --------------------------------------------------------------------
2095 // Preconditions
2096
2097 // A display is set up
2098 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2099 display.inject();
2100
2101 // There is a change to the viewport state
2102 display.mutableDrawingDisplayState().frame = oldFrame;
2103 display.mutableCurrentDisplayState().frame = newFrame;
2104
2105 // --------------------------------------------------------------------
2106 // Invocation
2107
2108 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2109
2110 // --------------------------------------------------------------------
2111 // Postconditions
2112
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002113 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getFrame());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002114}
2115
2116TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2117 using Case = NonHwcVirtualDisplayCase;
2118
2119 constexpr int oldWidth = 0;
2120 constexpr int oldHeight = 10;
2121 constexpr int newWidth = 123;
2122
2123 // --------------------------------------------------------------------
2124 // Preconditions
2125
2126 // A display is set up
2127 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002128 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002129 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002130 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2131 display.setNativeWindow(nativeWindow);
2132 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002133 // Setup injection expections
2134 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2135 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2136 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2137 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002138 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2139 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2140 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002141 display.inject();
2142
2143 // There is a change to the viewport state
2144 display.mutableDrawingDisplayState().width = oldWidth;
2145 display.mutableDrawingDisplayState().height = oldHeight;
2146 display.mutableCurrentDisplayState().width = newWidth;
2147 display.mutableCurrentDisplayState().height = oldHeight;
2148
2149 // --------------------------------------------------------------------
2150 // Call Expectations
2151
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002152 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002153
2154 // --------------------------------------------------------------------
2155 // Invocation
2156
2157 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2158}
2159
2160TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2161 using Case = NonHwcVirtualDisplayCase;
2162
2163 constexpr int oldWidth = 0;
2164 constexpr int oldHeight = 10;
2165 constexpr int newHeight = 123;
2166
2167 // --------------------------------------------------------------------
2168 // Preconditions
2169
2170 // A display is set up
2171 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002172 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002173 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002174 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2175 display.setNativeWindow(nativeWindow);
2176 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002177 // Setup injection expections
2178 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2179 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2180 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2181 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002182 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2183 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2184 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002185 display.inject();
2186
2187 // There is a change to the viewport state
2188 display.mutableDrawingDisplayState().width = oldWidth;
2189 display.mutableDrawingDisplayState().height = oldHeight;
2190 display.mutableCurrentDisplayState().width = oldWidth;
2191 display.mutableCurrentDisplayState().height = newHeight;
2192
2193 // --------------------------------------------------------------------
2194 // Call Expectations
2195
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002196 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002197
2198 // --------------------------------------------------------------------
2199 // Invocation
2200
2201 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2202}
2203
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002204/* ------------------------------------------------------------------------
2205 * SurfaceFlinger::setDisplayStateLocked
2206 */
2207
2208TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2209 // --------------------------------------------------------------------
2210 // Preconditions
2211
2212 // We have an unknown display token not associated with a known display
2213 sp<BBinder> displayToken = new BBinder();
2214
2215 // The requested display state references the unknown display.
2216 DisplayState state;
2217 state.what = DisplayState::eLayerStackChanged;
2218 state.token = displayToken;
2219 state.layerStack = 456;
2220
2221 // --------------------------------------------------------------------
2222 // Invocation
2223
2224 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2225
2226 // --------------------------------------------------------------------
2227 // Postconditions
2228
2229 // The returned flags are empty
2230 EXPECT_EQ(0u, flags);
2231
2232 // The display token still doesn't match anything known.
2233 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2234}
2235
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002236TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2237 using Case = SimplePrimaryDisplayCase;
2238
2239 // --------------------------------------------------------------------
2240 // Preconditions
2241
2242 // A display is already set up
2243 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2244 display.inject();
2245
2246 // No changes are made to the display
2247 DisplayState state;
2248 state.what = 0;
2249 state.token = display.token();
2250
2251 // --------------------------------------------------------------------
2252 // Invocation
2253
2254 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2255
2256 // --------------------------------------------------------------------
2257 // Postconditions
2258
2259 // The returned flags are empty
2260 EXPECT_EQ(0u, flags);
2261}
2262
2263TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2264 using Case = SimplePrimaryDisplayCase;
2265
2266 // --------------------------------------------------------------------
2267 // Preconditions
2268
2269 // A display is already set up
2270 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2271 display.inject();
2272
2273 // There is a surface that can be set.
2274 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2275
2276 // The current display state has the surface set
2277 display.mutableCurrentDisplayState().surface = surface;
2278
2279 // The incoming request sets the same surface
2280 DisplayState state;
2281 state.what = DisplayState::eSurfaceChanged;
2282 state.token = display.token();
2283 state.surface = surface;
2284
2285 // --------------------------------------------------------------------
2286 // Invocation
2287
2288 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2289
2290 // --------------------------------------------------------------------
2291 // Postconditions
2292
2293 // The returned flags are empty
2294 EXPECT_EQ(0u, flags);
2295
2296 // The current display state is unchanged.
2297 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2298}
2299
2300TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2301 using Case = SimplePrimaryDisplayCase;
2302
2303 // --------------------------------------------------------------------
2304 // Preconditions
2305
2306 // A display is already set up
2307 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2308 display.inject();
2309
2310 // There is a surface that can be set.
2311 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2312
2313 // The current display state does not have a surface
2314 display.mutableCurrentDisplayState().surface = nullptr;
2315
2316 // The incoming request sets a surface
2317 DisplayState state;
2318 state.what = DisplayState::eSurfaceChanged;
2319 state.token = display.token();
2320 state.surface = surface;
2321
2322 // --------------------------------------------------------------------
2323 // Invocation
2324
2325 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2326
2327 // --------------------------------------------------------------------
2328 // Postconditions
2329
2330 // The returned flags indicate a transaction is needed
2331 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2332
2333 // The current display layer stack state is set to the new value
2334 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2335}
2336
2337TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2338 using Case = SimplePrimaryDisplayCase;
2339
2340 // --------------------------------------------------------------------
2341 // Preconditions
2342
2343 // A display is already set up
2344 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2345 display.inject();
2346
2347 // The display has a layer stack set
2348 display.mutableCurrentDisplayState().layerStack = 456u;
2349
2350 // The incoming request sets the same layer stack
2351 DisplayState state;
2352 state.what = DisplayState::eLayerStackChanged;
2353 state.token = display.token();
2354 state.layerStack = 456u;
2355
2356 // --------------------------------------------------------------------
2357 // Invocation
2358
2359 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2360
2361 // --------------------------------------------------------------------
2362 // Postconditions
2363
2364 // The returned flags are empty
2365 EXPECT_EQ(0u, flags);
2366
2367 // The current display state is unchanged
2368 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2369}
2370
2371TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2372 using Case = SimplePrimaryDisplayCase;
2373
2374 // --------------------------------------------------------------------
2375 // Preconditions
2376
2377 // A display is set up
2378 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2379 display.inject();
2380
2381 // The display has a layer stack set
2382 display.mutableCurrentDisplayState().layerStack = 654u;
2383
2384 // The incoming request sets a different layer stack
2385 DisplayState state;
2386 state.what = DisplayState::eLayerStackChanged;
2387 state.token = display.token();
2388 state.layerStack = 456u;
2389
2390 // --------------------------------------------------------------------
2391 // Invocation
2392
2393 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2394
2395 // --------------------------------------------------------------------
2396 // Postconditions
2397
2398 // The returned flags indicate a transaction is needed
2399 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2400
2401 // The desired display state has been set to the new value.
2402 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2403}
2404
2405TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2406 using Case = SimplePrimaryDisplayCase;
2407 constexpr int initialOrientation = 180;
2408 const Rect initialFrame = {1, 2, 3, 4};
2409 const Rect initialViewport = {5, 6, 7, 8};
2410
2411 // --------------------------------------------------------------------
2412 // Preconditions
2413
2414 // A display is set up
2415 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2416 display.inject();
2417
2418 // The current display state projection state is all set
2419 display.mutableCurrentDisplayState().orientation = initialOrientation;
2420 display.mutableCurrentDisplayState().frame = initialFrame;
2421 display.mutableCurrentDisplayState().viewport = initialViewport;
2422
2423 // The incoming request sets the same projection state
2424 DisplayState state;
2425 state.what = DisplayState::eDisplayProjectionChanged;
2426 state.token = display.token();
2427 state.orientation = initialOrientation;
2428 state.frame = initialFrame;
2429 state.viewport = initialViewport;
2430
2431 // --------------------------------------------------------------------
2432 // Invocation
2433
2434 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2435
2436 // --------------------------------------------------------------------
2437 // Postconditions
2438
2439 // The returned flags are empty
2440 EXPECT_EQ(0u, flags);
2441
2442 // The current display state is unchanged
2443 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2444
2445 EXPECT_EQ(initialFrame, display.getCurrentDisplayState().frame);
2446 EXPECT_EQ(initialViewport, display.getCurrentDisplayState().viewport);
2447}
2448
2449TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2450 using Case = SimplePrimaryDisplayCase;
2451 constexpr int initialOrientation = 90;
2452 constexpr int desiredOrientation = 180;
2453
2454 // --------------------------------------------------------------------
2455 // Preconditions
2456
2457 // A display is set up
2458 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2459 display.inject();
2460
2461 // The current display state has an orientation set
2462 display.mutableCurrentDisplayState().orientation = initialOrientation;
2463
2464 // The incoming request sets a different orientation
2465 DisplayState state;
2466 state.what = DisplayState::eDisplayProjectionChanged;
2467 state.token = display.token();
2468 state.orientation = desiredOrientation;
2469
2470 // --------------------------------------------------------------------
2471 // Invocation
2472
2473 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2474
2475 // --------------------------------------------------------------------
2476 // Postconditions
2477
2478 // The returned flags indicate a transaction is needed
2479 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2480
2481 // The current display state has the new value.
2482 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2483}
2484
2485TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2486 using Case = SimplePrimaryDisplayCase;
2487 const Rect initialFrame = {0, 0, 0, 0};
2488 const Rect desiredFrame = {5, 6, 7, 8};
2489
2490 // --------------------------------------------------------------------
2491 // Preconditions
2492
2493 // A display is set up
2494 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2495 display.inject();
2496
2497 // The current display state does not have a frame
2498 display.mutableCurrentDisplayState().frame = initialFrame;
2499
2500 // The incoming request sets a frame
2501 DisplayState state;
2502 state.what = DisplayState::eDisplayProjectionChanged;
2503 state.token = display.token();
2504 state.frame = desiredFrame;
2505
2506 // --------------------------------------------------------------------
2507 // Invocation
2508
2509 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2510
2511 // --------------------------------------------------------------------
2512 // Postconditions
2513
2514 // The returned flags indicate a transaction is needed
2515 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2516
2517 // The current display state has the new value.
2518 EXPECT_EQ(desiredFrame, display.getCurrentDisplayState().frame);
2519}
2520
2521TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfViewportChanged) {
2522 using Case = SimplePrimaryDisplayCase;
2523 const Rect initialViewport = {0, 0, 0, 0};
2524 const Rect desiredViewport = {5, 6, 7, 8};
2525
2526 // --------------------------------------------------------------------
2527 // Preconditions
2528
2529 // A display is set up
2530 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2531 display.inject();
2532
2533 // The current display state does not have a viewport
2534 display.mutableCurrentDisplayState().viewport = initialViewport;
2535
2536 // The incoming request sets a viewport
2537 DisplayState state;
2538 state.what = DisplayState::eDisplayProjectionChanged;
2539 state.token = display.token();
2540 state.viewport = desiredViewport;
2541
2542 // --------------------------------------------------------------------
2543 // Invocation
2544
2545 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2546
2547 // --------------------------------------------------------------------
2548 // Postconditions
2549
2550 // The returned flags indicate a transaction is needed
2551 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2552
2553 // The current display state has the new value.
2554 EXPECT_EQ(desiredViewport, display.getCurrentDisplayState().viewport);
2555}
2556
2557TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2558 using Case = SimplePrimaryDisplayCase;
2559 constexpr uint32_t initialWidth = 1024;
2560 constexpr uint32_t initialHeight = 768;
2561
2562 // --------------------------------------------------------------------
2563 // Preconditions
2564
2565 // A display is set up
2566 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2567 display.inject();
2568
2569 // The current display state has a size set
2570 display.mutableCurrentDisplayState().width = initialWidth;
2571 display.mutableCurrentDisplayState().height = initialHeight;
2572
2573 // The incoming request sets the same display size
2574 DisplayState state;
2575 state.what = DisplayState::eDisplaySizeChanged;
2576 state.token = display.token();
2577 state.width = initialWidth;
2578 state.height = initialHeight;
2579
2580 // --------------------------------------------------------------------
2581 // Invocation
2582
2583 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2584
2585 // --------------------------------------------------------------------
2586 // Postconditions
2587
2588 // The returned flags are empty
2589 EXPECT_EQ(0u, flags);
2590
2591 // The current display state is unchanged
2592 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2593 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2594}
2595
2596TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2597 using Case = SimplePrimaryDisplayCase;
2598 constexpr uint32_t initialWidth = 0;
2599 constexpr uint32_t desiredWidth = 1024;
2600
2601 // --------------------------------------------------------------------
2602 // Preconditions
2603
2604 // A display is set up
2605 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2606 display.inject();
2607
2608 // The display does not yet have a width
2609 display.mutableCurrentDisplayState().width = initialWidth;
2610
2611 // The incoming request sets a display width
2612 DisplayState state;
2613 state.what = DisplayState::eDisplaySizeChanged;
2614 state.token = display.token();
2615 state.width = desiredWidth;
2616
2617 // --------------------------------------------------------------------
2618 // Invocation
2619
2620 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2621
2622 // --------------------------------------------------------------------
2623 // Postconditions
2624
2625 // The returned flags indicate a transaction is needed
2626 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2627
2628 // The current display state has the new value.
2629 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2630}
2631
2632TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2633 using Case = SimplePrimaryDisplayCase;
2634 constexpr uint32_t initialHeight = 0;
2635 constexpr uint32_t desiredHeight = 768;
2636
2637 // --------------------------------------------------------------------
2638 // Preconditions
2639
2640 // A display is set up
2641 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2642 display.inject();
2643
2644 // The display does not yet have a height
2645 display.mutableCurrentDisplayState().height = initialHeight;
2646
2647 // The incoming request sets a display height
2648 DisplayState state;
2649 state.what = DisplayState::eDisplaySizeChanged;
2650 state.token = display.token();
2651 state.height = desiredHeight;
2652
2653 // --------------------------------------------------------------------
2654 // Invocation
2655
2656 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2657
2658 // --------------------------------------------------------------------
2659 // Postconditions
2660
2661 // The returned flags indicate a transaction is needed
2662 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2663
2664 // The current display state has the new value.
2665 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
2666}
2667
Lloyd Pique86016da2018-03-01 16:09:38 -08002668/* ------------------------------------------------------------------------
2669 * SurfaceFlinger::onInitializeDisplays
2670 */
2671
2672TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
2673 using Case = SimplePrimaryDisplayCase;
2674
2675 // --------------------------------------------------------------------
2676 // Preconditions
2677
2678 // A primary display is set up
2679 Case::Display::injectHwcDisplay(this);
2680 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
2681 primaryDisplay.inject();
2682
2683 // --------------------------------------------------------------------
2684 // Call Expectations
2685
2686 // We expect the surface interceptor to possibly be used, but we treat it as
2687 // disabled since it is called as a side effect rather than directly by this
2688 // function.
2689 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
2690
2691 // We expect a call to get the active display config.
2692 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
2693
2694 // We expect invalidate() to be invoked once to trigger display transaction
2695 // processing.
2696 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
2697
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002698 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
2699
Lloyd Pique86016da2018-03-01 16:09:38 -08002700 // --------------------------------------------------------------------
2701 // Invocation
2702
2703 mFlinger.onInitializeDisplays();
2704
2705 // --------------------------------------------------------------------
2706 // Postconditions
2707
2708 // The primary display should have a current state
2709 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
2710 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
2711 // The layer stack state should be set to zero
2712 EXPECT_EQ(0u, primaryDisplayState.layerStack);
2713 // The orientation state should be set to zero
2714 EXPECT_EQ(0, primaryDisplayState.orientation);
2715
2716 // The frame state should be set to INVALID
2717 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.frame);
2718
2719 // The viewport state should be set to INVALID
2720 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.viewport);
2721
2722 // The width and height should both be zero
2723 EXPECT_EQ(0u, primaryDisplayState.width);
2724 EXPECT_EQ(0u, primaryDisplayState.height);
2725
2726 // The display should be set to HWC_POWER_MODE_NORMAL
2727 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
2728 auto displayDevice = primaryDisplay.mutableDisplayDevice();
2729 EXPECT_EQ(HWC_POWER_MODE_NORMAL, displayDevice->getPowerMode());
2730
2731 // The display refresh period should be set in the frame tracker.
2732 FrameStats stats;
2733 mFlinger.getAnimFrameTracker().getStats(&stats);
2734 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
2735
2736 // The display transaction needed flag should be set.
2737 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
2738
2739 // The compositor timing should be set to default values
2740 const auto& compositorTiming = mFlinger.getCompositorTiming();
2741 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
2742 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
2743 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
2744}
2745
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002746/* ------------------------------------------------------------------------
2747 * SurfaceFlinger::setPowerModeInternal
2748 */
2749
2750// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07002751template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002752struct DozeIsSupportedVariant {
2753 static constexpr bool DOZE_SUPPORTED = true;
2754 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2755 IComposerClient::PowerMode::DOZE;
2756 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2757 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07002758
2759 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2760 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2761 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>(
2762 {Hwc2::DisplayCapability::DOZE})),
2763 Return(Error::NONE)));
2764 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002765};
2766
Peiyong Lined531a32018-10-26 18:27:56 -07002767template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002768// Used when we simulate a display that does not support doze.
2769struct DozeNotSupportedVariant {
2770 static constexpr bool DOZE_SUPPORTED = false;
2771 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
2772 IComposerClient::PowerMode::ON;
2773 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
2774 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07002775
2776 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
2777 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
2778 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
2779 Return(Error::NONE)));
2780 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002781};
2782
2783struct EventThreadBaseSupportedVariant {
2784 static void setupEventAndEventControlThreadNoCallExpectations(DisplayTransactionTest* test) {
2785 // The event control thread should not be notified.
2786 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(_)).Times(0);
2787
2788 // The event thread should not be notified.
2789 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
2790 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
2791 }
2792};
2793
2794struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
2795 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2796 // These calls are only expected for the primary display.
2797
2798 // Instead expect no calls.
2799 setupEventAndEventControlThreadNoCallExpectations(test);
2800 }
2801
2802 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2803 // These calls are only expected for the primary display.
2804
2805 // Instead expect no calls.
2806 setupEventAndEventControlThreadNoCallExpectations(test);
2807 }
2808};
2809
2810struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
2811 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
2812 // The event control thread should be notified to enable vsyncs
2813 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(true)).Times(1);
2814
2815 // The event thread should be notified that the screen was acquired.
2816 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
2817 }
2818
2819 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
2820 // There should be a call to setVsyncEnabled(false)
2821 EXPECT_CALL(*test->mEventControlThread, setVsyncEnabled(false)).Times(1);
2822
2823 // The event thread should not be notified that the screen was released.
2824 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
2825 }
2826};
2827
Lloyd Pique41be5d22018-06-21 13:11:48 -07002828struct DispSyncIsSupportedVariant {
2829 static void setupBeginResyncCallExpectations(DisplayTransactionTest* test) {
2830 EXPECT_CALL(*test->mPrimaryDispSync, reset()).Times(1);
2831 EXPECT_CALL(*test->mPrimaryDispSync, setPeriod(DEFAULT_REFRESH_RATE)).Times(1);
2832 EXPECT_CALL(*test->mPrimaryDispSync, beginResync()).Times(1);
2833 }
2834
2835 static void setupEndResyncCallExpectations(DisplayTransactionTest* test) {
2836 EXPECT_CALL(*test->mPrimaryDispSync, endResync()).Times(1);
2837 }
2838};
2839
2840struct DispSyncNotSupportedVariant {
2841 static void setupBeginResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2842
2843 static void setupEndResyncCallExpectations(DisplayTransactionTest* /* test */) {}
2844};
2845
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002846// --------------------------------------------------------------------
2847// Note:
2848//
2849// There are a large number of transitions we could test, however we only test a
2850// selected subset which provides complete test coverage of the implementation.
2851// --------------------------------------------------------------------
2852
2853template <int initialPowerMode, int targetPowerMode>
2854struct TransitionVariantCommon {
2855 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
2856 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
2857
2858 static void verifyPostconditions(DisplayTransactionTest*) {}
2859};
2860
2861struct TransitionOffToOnVariant
2862 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_NORMAL> {
2863 template <typename Case>
2864 static void setupCallExpectations(DisplayTransactionTest* test) {
2865 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2866 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002867 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002868 Case::setupRepaintEverythingCallExpectations(test);
2869 }
2870
2871 static void verifyPostconditions(DisplayTransactionTest* test) {
2872 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2873 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2874 }
2875};
2876
2877struct TransitionOffToDozeSuspendVariant
2878 : public TransitionVariantCommon<HWC_POWER_MODE_OFF, HWC_POWER_MODE_DOZE_SUSPEND> {
2879 template <typename Case>
2880 static void setupCallExpectations(DisplayTransactionTest* test) {
2881 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2882 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2883 Case::setupRepaintEverythingCallExpectations(test);
2884 }
2885
2886 static void verifyPostconditions(DisplayTransactionTest* test) {
2887 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2888 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
2889 }
2890};
2891
2892struct TransitionOnToOffVariant
2893 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_OFF> {
2894 template <typename Case>
2895 static void setupCallExpectations(DisplayTransactionTest* test) {
2896 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002897 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002898 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2899 }
2900
2901 static void verifyPostconditions(DisplayTransactionTest* test) {
2902 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2903 }
2904};
2905
2906struct TransitionDozeSuspendToOffVariant
2907 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_OFF> {
2908 template <typename Case>
2909 static void setupCallExpectations(DisplayTransactionTest* test) {
2910 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2911 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
2912 }
2913
2914 static void verifyPostconditions(DisplayTransactionTest* test) {
2915 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
2916 }
2917};
2918
2919struct TransitionOnToDozeVariant
2920 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE> {
2921 template <typename Case>
2922 static void setupCallExpectations(DisplayTransactionTest* test) {
2923 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2924 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2925 }
2926};
2927
2928struct TransitionDozeSuspendToDozeVariant
2929 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_DOZE> {
2930 template <typename Case>
2931 static void setupCallExpectations(DisplayTransactionTest* test) {
2932 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002933 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002934 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
2935 }
2936};
2937
2938struct TransitionDozeToOnVariant
2939 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE, HWC_POWER_MODE_NORMAL> {
2940 template <typename Case>
2941 static void setupCallExpectations(DisplayTransactionTest* test) {
2942 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2943 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2944 }
2945};
2946
2947struct TransitionDozeSuspendToOnVariant
2948 : public TransitionVariantCommon<HWC_POWER_MODE_DOZE_SUSPEND, HWC_POWER_MODE_NORMAL> {
2949 template <typename Case>
2950 static void setupCallExpectations(DisplayTransactionTest* test) {
2951 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002952 Case::DispSync::setupBeginResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002953 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
2954 }
2955};
2956
2957struct TransitionOnToDozeSuspendVariant
2958 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_DOZE_SUSPEND> {
2959 template <typename Case>
2960 static void setupCallExpectations(DisplayTransactionTest* test) {
2961 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
Lloyd Pique41be5d22018-06-21 13:11:48 -07002962 Case::DispSync::setupEndResyncCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002963 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
2964 }
2965};
2966
2967struct TransitionOnToUnknownVariant
2968 : public TransitionVariantCommon<HWC_POWER_MODE_NORMAL, HWC_POWER_MODE_LEET> {
2969 template <typename Case>
2970 static void setupCallExpectations(DisplayTransactionTest* test) {
2971 Case::EventThread::setupEventAndEventControlThreadNoCallExpectations(test);
2972 Case::setupNoComposerPowerModeCallExpectations(test);
2973 }
2974};
2975
2976// --------------------------------------------------------------------
2977// Note:
2978//
2979// Rather than testing the cartesian product of of
2980// DozeIsSupported/DozeNotSupported with all other options, we use one for one
2981// display type, and the other for another display type.
2982// --------------------------------------------------------------------
2983
2984template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07002985 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002986struct DisplayPowerCase {
2987 using Display = DisplayVariant;
2988 using Doze = DozeVariant;
2989 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07002990 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002991 using Transition = TransitionVariant;
2992
2993 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, int mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002994 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08002995 auto display = Display::makeFakeExistingDisplayInjector(test);
2996 display.inject();
2997 display.mutableDisplayDevice()->setPowerMode(mode);
2998 return display;
2999 }
3000
3001 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
3002 test->mFlinger.mutablePrimaryHWVsyncEnabled() = enabled;
3003 }
3004
3005 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3006 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3007 }
3008
3009 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test, int mode) {
3010 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
3011 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, mode)).Times(1);
3012 }
3013
3014 static void setupComposerCallExpectations(DisplayTransactionTest* test,
3015 IComposerClient::PowerMode mode) {
3016 // Any calls to get the active config will return a default value.
3017 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3018 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3019 Return(Error::NONE)));
3020
3021 // Any calls to get whether the display supports dozing will return the value set by the
3022 // policy variant.
3023 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3024 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3025
3026 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3027 }
3028
3029 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3030 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3031 }
3032};
3033
3034// A sample configuration for the primary display.
3035// In addition to having event thread support, we emulate doze support.
3036template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003037using PrimaryDisplayPowerCase =
3038 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3039 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3040 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003041
3042// A sample configuration for the external display.
3043// In addition to not having event thread support, we emulate not having doze
3044// support.
3045template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003046using ExternalDisplayPowerCase =
3047 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3048 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3049 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003050
3051class SetPowerModeInternalTest : public DisplayTransactionTest {
3052public:
3053 template <typename Case>
3054 void transitionDisplayCommon();
3055};
3056
3057template <int PowerMode>
3058struct PowerModeInitialVSyncEnabled : public std::false_type {};
3059
3060template <>
3061struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_NORMAL> : public std::true_type {};
3062
3063template <>
3064struct PowerModeInitialVSyncEnabled<HWC_POWER_MODE_DOZE> : public std::true_type {};
3065
3066template <typename Case>
3067void SetPowerModeInternalTest::transitionDisplayCommon() {
3068 // --------------------------------------------------------------------
3069 // Preconditions
3070
Peiyong Lined531a32018-10-26 18:27:56 -07003071 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003072 auto display =
3073 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3074 Case::setInitialPrimaryHWVsyncEnabled(this,
3075 PowerModeInitialVSyncEnabled<
3076 Case::Transition::INITIAL_POWER_MODE>::value);
3077
3078 // --------------------------------------------------------------------
3079 // Call Expectations
3080
3081 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3082 Case::Transition::template setupCallExpectations<Case>(this);
3083
3084 // --------------------------------------------------------------------
3085 // Invocation
3086
3087 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3088 Case::Transition::TARGET_POWER_MODE);
3089
3090 // --------------------------------------------------------------------
3091 // Postconditions
3092
3093 Case::Transition::verifyPostconditions(this);
3094}
3095
3096TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3097 using Case = SimplePrimaryDisplayCase;
3098
3099 // --------------------------------------------------------------------
3100 // Preconditions
3101
3102 // A primary display device is set up
3103 Case::Display::injectHwcDisplay(this);
3104 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3105 display.inject();
3106
Dominik Laskowskia2edf612018-06-01 13:15:16 -07003107 // The display is already set to HWC_POWER_MODE_NORMAL
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003108 display.mutableDisplayDevice()->setPowerMode(HWC_POWER_MODE_NORMAL);
3109
3110 // --------------------------------------------------------------------
3111 // Invocation
3112
3113 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_NORMAL);
3114
3115 // --------------------------------------------------------------------
3116 // Postconditions
3117
3118 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3119}
3120
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003121TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003122 using Case = HwcVirtualDisplayCase;
3123
3124 // --------------------------------------------------------------------
3125 // Preconditions
3126
Dominik Laskowski075d3172018-05-24 15:50:06 -07003127 // Insert display data so that the HWC thinks it created the virtual display.
3128 const auto displayId = Case::Display::DISPLAY_ID::get();
3129 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003130 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003131
3132 // A virtual display device is set up
3133 Case::Display::injectHwcDisplay(this);
3134 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3135 display.inject();
3136
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003137 // The display is set to HWC_POWER_MODE_NORMAL
3138 getDisplayDevice(display.token())->setPowerMode(HWC_POWER_MODE_NORMAL);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003139
3140 // --------------------------------------------------------------------
3141 // Invocation
3142
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003143 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), HWC_POWER_MODE_OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003144
3145 // --------------------------------------------------------------------
3146 // Postconditions
3147
3148 EXPECT_EQ(HWC_POWER_MODE_NORMAL, display.mutableDisplayDevice()->getPowerMode());
3149}
3150
3151TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3152 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3153}
3154
3155TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3156 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3157}
3158
3159TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3160 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3161}
3162
3163TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3164 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3165}
3166
3167TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3168 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3169}
3170
3171TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3172 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3173}
3174
3175TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3176 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3177}
3178
3179TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3180 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3181}
3182
3183TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3184 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3185}
3186
3187TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3188 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3189}
3190
3191TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3192 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3193}
3194
3195TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3196 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3197}
3198
3199TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3200 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3201}
3202
3203TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3204 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3205}
3206
3207TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3208 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3209}
3210
3211TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3212 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3213}
3214
3215TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3216 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3217}
3218
3219TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3220 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3221}
3222
3223TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3224 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3225}
3226
3227TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3228 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3229}
3230
Lloyd Piquef58625d2017-12-19 13:22:33 -08003231} // namespace
3232} // namespace android