blob: ff77ca54b931382307c672391c5886521fe23e8a [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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Lloyd Piquef58625d2017-12-19 13:22:33 -080021#undef LOG_TAG
22#define LOG_TAG "LibSurfaceFlingerUnittests"
23
Dominik Laskowski075d3172018-05-24 15:50:06 -070024#include <type_traits>
25
Lais Andrade3a6e47d2020-04-02 11:20:16 +010026#include <android/hardware/power/Boost.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070027#include <compositionengine/Display.h>
28#include <compositionengine/DisplayColorProfile.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070029#include <compositionengine/impl/Display.h>
Lloyd Pique33050472019-12-19 17:12:44 -080030#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070031#include <compositionengine/mock/Display.h>
32#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070033#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070034#include <compositionengine/mock/RenderSurface.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080035#include <gmock/gmock.h>
36#include <gtest/gtest.h>
Lloyd Pique1ebe0902019-10-04 14:47:13 -070037#include <gui/mock/GraphicBufferConsumer.h>
38#include <gui/mock/GraphicBufferProducer.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080039#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070040#include <renderengine/mock/RenderEngine.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070041#include <ui/DebugUtils.h>
Dominik Laskowski075d3172018-05-24 15:50:06 -070042
43#include "DisplayIdentificationTest.h"
Ana Krulecafb45842019-02-13 13:33:03 -080044#include "TestableScheduler.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080045#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080046#include "mock/DisplayHardware/MockComposer.h"
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070047#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080048#include "mock/MockEventThread.h"
49#include "mock/MockMessageQueue.h"
50#include "mock/MockNativeWindowSurface.h"
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070051#include "mock/MockSchedulerCallback.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080052#include "mock/MockSurfaceInterceptor.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070053#include "mock/MockVsyncController.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080054#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080055
56namespace android {
57namespace {
58
Peiyong Line9d809e2020-04-14 13:10:48 -070059namespace hal = android::hardware::graphics::composer::hal;
60
Lais Andrade3a6e47d2020-04-02 11:20:16 +010061using android::hardware::power::Boost;
62
Lloyd Piquee39cad22017-12-20 17:01:29 -080063using testing::_;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070064using testing::AnyNumber;
Lloyd Piquee39cad22017-12-20 17:01:29 -080065using testing::DoAll;
66using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080067using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080068using testing::Return;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070069using testing::ReturnRefOfCopy;
Lloyd Piquee39cad22017-12-20 17:01:29 -080070using testing::SetArgPointee;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070071using testing::StrictMock;
Lloyd Piquee39cad22017-12-20 17:01:29 -080072
Peiyong Line9d809e2020-04-14 13:10:48 -070073using hal::ColorMode;
74using hal::Connection;
75using hal::DisplayCapability;
76using hal::DisplayType;
77using hal::Error;
78using hal::Hdr;
79using hal::HWDisplayId;
80using hal::IComposer;
81using hal::IComposerClient;
82using hal::PerFrameMetadataKey;
83using hal::PowerMode;
84using hal::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080085
Lloyd Piquec11e0d32018-01-22 18:44:59 -080086using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
87using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080088using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080089using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080090
Ady Abraham2492a022020-07-24 11:09:55 -070091constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'667;
Lloyd Piquee39cad22017-12-20 17:01:29 -080092constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080093constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080094
Peiyong Lin65248e02020-04-18 21:15:07 -070095constexpr int POWER_MODE_LEET = 1337; // An out of range power mode value
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080096
Lloyd Piquec11e0d32018-01-22 18:44:59 -080097/* ------------------------------------------------------------------------
98 * Boolean avoidance
99 *
100 * To make calls and template instantiations more readable, we define some
101 * local enums along with an implicit bool conversion.
102 */
103
104#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
105
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800106BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700107BOOL_SUBSTITUTE(Critical);
108BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800109BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700110BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800111
112/* ------------------------------------------------------------------------
113 *
114 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800115
Lloyd Piquef58625d2017-12-19 13:22:33 -0800116class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800117public:
Lloyd Piquef58625d2017-12-19 13:22:33 -0800118 DisplayTransactionTest();
119 ~DisplayTransactionTest() override;
120
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800121 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800122 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800123
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700124 void injectMockScheduler();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800125 void injectMockComposer(int virtualDisplayCount);
126 void injectFakeBufferQueueFactory();
127 void injectFakeNativeWindowSurfaceFactory();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700128 sp<DisplayDevice> injectDefaultInternalDisplay(std::function<void(FakeDisplayDeviceInjector&)>);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800129
130 // --------------------------------------------------------------------
131 // Postcondition helpers
132
Peiyong Line9d809e2020-04-14 13:10:48 -0700133 bool hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800134 bool hasTransactionFlagSet(int flag);
135 bool hasDisplayDevice(sp<IBinder> displayToken);
136 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
137 bool hasCurrentDisplayState(sp<IBinder> displayToken);
138 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
139 bool hasDrawingDisplayState(sp<IBinder> displayToken);
140 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
141
142 // --------------------------------------------------------------------
143 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800144
Lloyd Piquef58625d2017-12-19 13:22:33 -0800145 TestableSurfaceFlinger mFlinger;
Alec Mouriba013fa2018-10-16 12:43:11 -0700146 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800147 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700148 Hwc2::mock::PowerAdvisor mPowerAdvisor;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800149
150 // These mocks are created by the test, but are destroyed by SurfaceFlinger
151 // by virtue of being stored into a std::unique_ptr. However we still need
152 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700153 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800154 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800155 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
156 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700157
Ady Abraham8cb21882020-08-26 18:22:05 -0700158 mock::VsyncController* mVsyncController = new mock::VsyncController;
159 mock::VSyncTracker* mVSyncTracker = new mock::VSyncTracker;
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700160 mock::SchedulerCallback mSchedulerCallback;
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700161 mock::EventThread* mEventThread = new mock::EventThread;
162 mock::EventThread* mSFEventThread = new mock::EventThread;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800163
164 // These mocks are created only when expected to be created via a factory.
165 sp<mock::GraphicBufferConsumer> mConsumer;
166 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700167 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800168};
169
170DisplayTransactionTest::DisplayTransactionTest() {
171 const ::testing::TestInfo* const test_info =
172 ::testing::UnitTest::GetInstance()->current_test_info();
173 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800174
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800175 // Default to no wide color display support configured
176 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700177 mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800178 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800179
180 // Default to using HWC virtual displays
181 mFlinger.mutableUseHwcVirtualDisplays() = true;
182
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800183 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
184 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
185 });
186
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800187 mFlinger.setCreateNativeWindowSurface([](auto) {
188 ADD_FAILURE() << "Unexpected request to create a native window surface.";
189 return nullptr;
190 });
191
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700192 injectMockScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800193 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700194 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800195 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800196
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800197 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800198}
199
200DisplayTransactionTest::~DisplayTransactionTest() {
201 const ::testing::TestInfo* const test_info =
202 ::testing::UnitTest::GetInstance()->current_test_info();
203 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
204}
205
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700206void DisplayTransactionTest::injectMockScheduler() {
Ana Krulecafb45842019-02-13 13:33:03 -0800207 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700208 EXPECT_CALL(*mEventThread, createEventConnection(_, _))
209 .WillOnce(Return(new EventThreadConnection(mEventThread, ResyncCallback(),
210 ISurfaceComposer::eConfigChangedSuppress)));
211
Ana Krulecafb45842019-02-13 13:33:03 -0800212 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700213 EXPECT_CALL(*mSFEventThread, createEventConnection(_, _))
214 .WillOnce(Return(new EventThreadConnection(mSFEventThread, ResyncCallback(),
215 ISurfaceComposer::eConfigChangedSuppress)));
Ana Krulecafb45842019-02-13 13:33:03 -0800216
Ady Abraham8cb21882020-08-26 18:22:05 -0700217 mFlinger.setupScheduler(std::unique_ptr<scheduler::VsyncController>(mVsyncController),
218 std::unique_ptr<scheduler::VSyncTracker>(mVSyncTracker),
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700219 std::unique_ptr<EventThread>(mEventThread),
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700220 std::unique_ptr<EventThread>(mSFEventThread), &mSchedulerCallback);
Ana Krulecafb45842019-02-13 13:33:03 -0800221}
222
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800223void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
224 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800225 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
226 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800227
Lloyd Piquee39cad22017-12-20 17:01:29 -0800228 Mock::VerifyAndClear(mComposer);
229}
230
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800231void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800232 // This setup is only expected once per test.
233 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
234
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800235 mConsumer = new mock::GraphicBufferConsumer();
236 mProducer = new mock::GraphicBufferProducer();
237
238 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
239 *outProducer = mProducer;
240 *outConsumer = mConsumer;
241 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800242}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800243
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800244void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800245 // This setup is only expected once per test.
246 ASSERT_TRUE(mNativeWindowSurface == nullptr);
247
Lloyd Pique22098362018-09-13 11:46:49 -0700248 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800249
Lloyd Pique22098362018-09-13 11:46:49 -0700250 mFlinger.setCreateNativeWindowSurface([this](auto) {
251 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
252 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800253}
254
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700255sp<DisplayDevice> DisplayTransactionTest::injectDefaultInternalDisplay(
256 std::function<void(FakeDisplayDeviceInjector&)> injectExtra) {
Marin Shalamanova524a092020-07-27 21:39:55 +0200257 constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID(777);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700258 constexpr int DEFAULT_DISPLAY_WIDTH = 1080;
259 constexpr int DEFAULT_DISPLAY_HEIGHT = 1920;
Peiyong Line9d809e2020-04-14 13:10:48 -0700260 constexpr HWDisplayId DEFAULT_DISPLAY_HWC_DISPLAY_ID = 0;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700261
262 // The DisplayDevice is required to have a framebuffer (behind the
263 // ANativeWindow interface) which uses the actual hardware display
264 // size.
265 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
266 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
267 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
268 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
269 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT));
270 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT));
271 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64));
272 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(AnyNumber());
273
274 auto compositionDisplay = compositionengine::impl::
275 createDisplay(mFlinger.getCompositionEngine(),
276 compositionengine::DisplayCreationArgsBuilder()
277 .setPhysical(
278 {DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal})
279 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
280 .setPowerAdvisor(&mPowerAdvisor)
281 .build());
282
283 auto injector =
284 FakeDisplayDeviceInjector(mFlinger, compositionDisplay, DisplayConnectionType::Internal,
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100285 DEFAULT_DISPLAY_HWC_DISPLAY_ID, true /* isPrimary */);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700286
287 injector.setNativeWindow(mNativeWindow);
288 if (injectExtra) {
289 injectExtra(injector);
290 }
291
292 auto displayDevice = injector.inject();
293
294 Mock::VerifyAndClear(mNativeWindow.get());
295
296 return displayDevice;
297}
298
Peiyong Line9d809e2020-04-14 13:10:48 -0700299bool DisplayTransactionTest::hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700300 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800301}
302
303bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
304 return mFlinger.mutableTransactionFlags() & flag;
305}
306
307bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700308 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800309}
310
311sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700312 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800313}
314
315bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
316 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
317}
318
319const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
320 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
321}
322
323bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
324 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
325}
326
327const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
328 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
329}
330
331/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800332 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800333 */
334
Dominik Laskowski075d3172018-05-24 15:50:06 -0700335template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200336struct PhysicalDisplayIdType {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700337
Marin Shalamanova524a092020-07-27 21:39:55 +0200338template <uint64_t displayId>
339using VirtualDisplayIdType = std::integral_constant<uint64_t, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700340
341struct NoDisplayId {};
342
343template <typename>
344struct IsPhysicalDisplayId : std::bool_constant<false> {};
345
346template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200347struct IsPhysicalDisplayId<PhysicalDisplayIdType<PhysicalDisplay>> : std::bool_constant<true> {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700348
349template <typename>
350struct DisplayIdGetter;
351
352template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200353struct DisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> {
354 static std::optional<PhysicalDisplayId> get() {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700355 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
Marin Shalamanova524a092020-07-27 21:39:55 +0200356 return PhysicalDisplayId::fromPort(static_cast<bool>(PhysicalDisplay::PRIMARY)
357 ? LEGACY_DISPLAY_TYPE_PRIMARY
358 : LEGACY_DISPLAY_TYPE_EXTERNAL);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700359 }
360
361 const auto info =
362 parseDisplayIdentificationData(PhysicalDisplay::PORT,
363 PhysicalDisplay::GET_IDENTIFICATION_DATA());
364 return info ? std::make_optional(info->id) : std::nullopt;
365 }
366};
367
Marin Shalamanova524a092020-07-27 21:39:55 +0200368template <uint64_t displayId>
369struct DisplayIdGetter<VirtualDisplayIdType<displayId>> {
370 // TODO(b/160679868) Use VirtualDisplayId
371 static std::optional<PhysicalDisplayId> get() { return PhysicalDisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700372};
373
374template <>
375struct DisplayIdGetter<NoDisplayId> {
376 static std::optional<DisplayId> get() { return {}; }
377};
378
Dominik Laskowski55c85402020-01-21 16:25:47 -0800379template <typename>
380struct DisplayConnectionTypeGetter {
381 static constexpr std::optional<DisplayConnectionType> value;
382};
383
384template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200385struct DisplayConnectionTypeGetter<PhysicalDisplayIdType<PhysicalDisplay>> {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800386 static constexpr std::optional<DisplayConnectionType> value = PhysicalDisplay::CONNECTION_TYPE;
387};
388
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100389template <typename>
390struct HwcDisplayIdGetter {
Peiyong Line9d809e2020-04-14 13:10:48 -0700391 static constexpr std::optional<HWDisplayId> value;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100392};
393
Peiyong Line9d809e2020-04-14 13:10:48 -0700394constexpr HWDisplayId HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID = 1010;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100395
Marin Shalamanova524a092020-07-27 21:39:55 +0200396template <uint64_t displayId>
397struct HwcDisplayIdGetter<VirtualDisplayIdType<displayId>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700398 static constexpr std::optional<HWDisplayId> value = HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100399};
400
401template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200402struct HwcDisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700403 static constexpr std::optional<HWDisplayId> value = PhysicalDisplay::HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100404};
405
Dominik Laskowski075d3172018-05-24 15:50:06 -0700406// DisplayIdType can be:
Marin Shalamanova524a092020-07-27 21:39:55 +0200407// 1) PhysicalDisplayIdType<...> for generated ID of physical display backed by HWC.
408// 2) VirtualDisplayIdType<...> for hard-coded ID of virtual display backed by HWC.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700409// 3) NoDisplayId for virtual display without HWC backing.
410template <typename DisplayIdType, int width, int height, Critical critical, Async async,
411 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800412struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700413 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800414 using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100415 using HWC_DISPLAY_ID_OPT = HwcDisplayIdGetter<DisplayIdType>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700416
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800417 // The display width and height
418 static constexpr int WIDTH = width;
419 static constexpr int HEIGHT = height;
420
421 static constexpr int GRALLOC_USAGE = grallocUsage;
422
Dominik Laskowski075d3172018-05-24 15:50:06 -0700423 // Whether the display is virtual or physical
424 static constexpr Virtual VIRTUAL =
425 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800426
427 // When creating native window surfaces for the framebuffer, whether those should be critical
428 static constexpr Critical CRITICAL = critical;
429
430 // When creating native window surfaces for the framebuffer, whether those should be async
431 static constexpr Async ASYNC = async;
432
433 // Whether the display should be treated as secure
434 static constexpr Secure SECURE = secure;
435
Dominik Laskowski075d3172018-05-24 15:50:06 -0700436 // Whether the display is primary
437 static constexpr Primary PRIMARY = primary;
438
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800439 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700440 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder();
441 if (auto displayId = DISPLAY_ID::get()) {
442 ceDisplayArgs.setPhysical({*displayId, DisplayConnectionType::Internal});
443 } else {
444 ceDisplayArgs.setUseHwcVirtualDisplays(false);
445 }
446 ceDisplayArgs.setPixels({WIDTH, HEIGHT}).setPowerAdvisor(&test->mPowerAdvisor).build();
447
448 auto compositionDisplay =
449 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
450 ceDisplayArgs.build());
451
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100452 auto injector = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
453 CONNECTION_TYPE::value, HWC_DISPLAY_ID_OPT::value,
454 static_cast<bool>(PRIMARY));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700455
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800456 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700457 injector.setNativeWindow(test->mNativeWindow);
458
459 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800460 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700461 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
462 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
463 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
464 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800465 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
466 .WillRepeatedly(Return(0));
467 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
468 .WillRepeatedly(Return(0));
469 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
470 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700471 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
472 .WillRepeatedly(Return(0));
473
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800474 return injector;
475 }
476
477 // Called by tests to set up any native window creation call expectations.
478 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
479 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
480 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800481
Alec Mouriba013fa2018-10-16 12:43:11 -0700482 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
483 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
484 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
485 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800486 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
487 .WillRepeatedly(Return(0));
488 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
489 .WillRepeatedly(Return(0));
490 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
491 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700492 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
493 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800494 }
495
496 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
497 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
498 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
499 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
500 .WillRepeatedly(Return(NO_ERROR));
501 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
502 .WillRepeatedly(Return(NO_ERROR));
503 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
504 .WillRepeatedly(Return(NO_ERROR));
505 }
506
507 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
508 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
509 }
510};
511
Peiyong Line9d809e2020-04-14 13:10:48 -0700512template <HWDisplayId hwcDisplayId, DisplayType hwcDisplayType, typename DisplayVariant,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700513 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800514struct HwcDisplayVariant {
515 // The display id supplied by the HWC
Peiyong Line9d809e2020-04-14 13:10:48 -0700516 static constexpr HWDisplayId HWC_DISPLAY_ID = hwcDisplayId;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800517
518 // The HWC display type
Peiyong Line9d809e2020-04-14 13:10:48 -0700519 static constexpr DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800520
521 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700522 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin65248e02020-04-18 21:15:07 -0700523 static constexpr PowerMode INIT_POWER_MODE = PowerMode::ON;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800524
Peiyong Line9d809e2020-04-14 13:10:48 -0700525 static void injectPendingHotplugEvent(DisplayTransactionTest* test, Connection connection) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800526 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
527 HotplugEvent{HWC_DISPLAY_ID, connection});
528 }
529
530 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800531 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700532 const auto displayId = DisplayVariant::DISPLAY_ID::get();
533 ASSERT_TRUE(displayId);
534 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
535 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800536 .setHwcDisplayId(HWC_DISPLAY_ID)
537 .setWidth(DisplayVariant::WIDTH)
538 .setHeight(DisplayVariant::HEIGHT)
539 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700540 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800541 .inject(&test->mFlinger, test->mComposer);
542 }
543
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800544 // Called by tests to inject a HWC display setup
545 static void injectHwcDisplay(DisplayTransactionTest* test) {
546 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700547 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800548 Return(Error::NONE)));
Peiyong Lin65248e02020-04-18 21:15:07 -0700549 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY_ID, INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700550 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800551 injectHwcDisplayWithNoDefaultCapabilities(test);
552 }
553
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700554 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
555 DisplayTransactionTest* test) {
556 const ::testing::TestInfo* const test_info =
557 ::testing::UnitTest::GetInstance()->current_test_info();
558
559 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
560 .setPhysical({*DisplayVariant::DISPLAY_ID::get(),
561 PhysicalDisplay::CONNECTION_TYPE})
562 .setPixels({DisplayVariant::WIDTH, DisplayVariant::HEIGHT})
563 .setIsSecure(static_cast<bool>(DisplayVariant::SECURE))
564 .setPowerAdvisor(&test->mPowerAdvisor)
565 .setName(std::string("Injected display for ") +
566 test_info->test_case_name() + "." + test_info->name())
567 .build();
568
569 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
570 ceDisplayArgs);
571 }
572
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800573 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800574 constexpr auto CONNECTION_TYPE =
575 PhysicalDisplay::CONNECTION_TYPE == DisplayConnectionType::Internal
576 ? IComposerClient::DisplayConnectionType::INTERNAL
577 : IComposerClient::DisplayConnectionType::EXTERNAL;
578
579 EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700580 .WillOnce(DoAll(SetArgPointee<1>(CONNECTION_TYPE), Return(hal::V2_4::Error::NONE)));
Dominik Laskowski55c85402020-01-21 16:25:47 -0800581
Peiyong Line9d809e2020-04-14 13:10:48 -0700582 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_))
583 .WillOnce(Return(hal::Error::NONE));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800584 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
585 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
586 Return(Error::NONE)));
587 EXPECT_CALL(*test->mComposer,
588 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
589 IComposerClient::Attribute::WIDTH, _))
590 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
591 EXPECT_CALL(*test->mComposer,
592 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
593 IComposerClient::Attribute::HEIGHT, _))
594 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
595 EXPECT_CALL(*test->mComposer,
596 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
597 IComposerClient::Attribute::VSYNC_PERIOD, _))
598 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
599 EXPECT_CALL(*test->mComposer,
600 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
601 IComposerClient::Attribute::DPI_X, _))
602 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
603 EXPECT_CALL(*test->mComposer,
604 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
605 IComposerClient::Attribute::DPI_Y, _))
606 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Ady Abraham7159f572019-10-11 11:10:18 -0700607 EXPECT_CALL(*test->mComposer,
608 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
609 IComposerClient::Attribute::CONFIG_GROUP, _))
610 .WillOnce(DoAll(SetArgPointee<3>(-1), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700611
612 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
613 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200614 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
615 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
616 Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700617 } else {
618 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200619 .WillOnce(Return(Error::UNSUPPORTED));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700620 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800621 }
622
623 // Called by tests to set up HWC call expectations
624 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
625 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700626 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800627 }
628};
629
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800630// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
631constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
632 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
633
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100634template <typename PhysicalDisplay, int width, int height, Critical critical>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800635struct PhysicalDisplayVariant
Marin Shalamanova524a092020-07-27 21:39:55 +0200636 : DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, critical,
637 Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY,
638 GRALLOC_USAGE_PHYSICAL_DISPLAY>,
Peiyong Line9d809e2020-04-14 13:10:48 -0700639 HwcDisplayVariant<PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL,
Marin Shalamanova524a092020-07-27 21:39:55 +0200640 DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700641 critical, Async::FALSE, Secure::TRUE,
642 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
643 PhysicalDisplay> {};
644
645template <bool hasIdentificationData>
646struct PrimaryDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800647 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::Internal;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700648 static constexpr Primary PRIMARY = Primary::TRUE;
649 static constexpr uint8_t PORT = 255;
Peiyong Line9d809e2020-04-14 13:10:48 -0700650 static constexpr HWDisplayId HWC_DISPLAY_ID = 1001;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700651 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
652 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
653};
654
655template <bool hasIdentificationData>
656struct ExternalDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800657 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::External;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700658 static constexpr Primary PRIMARY = Primary::FALSE;
659 static constexpr uint8_t PORT = 254;
Peiyong Line9d809e2020-04-14 13:10:48 -0700660 static constexpr HWDisplayId HWC_DISPLAY_ID = 1002;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700661 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
662 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
663};
664
665struct TertiaryDisplay {
666 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800667 static constexpr uint8_t PORT = 253;
Peiyong Line9d809e2020-04-14 13:10:48 -0700668 static constexpr HWDisplayId HWC_DISPLAY_ID = 1003;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800669 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700670};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800671
672// A primary display is a physical display that is critical
673using PrimaryDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100674 PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800675
676// An external display is physical display that is not critical.
677using ExternalDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100678 PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800679
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100680using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800681
682// A virtual display not supported by the HWC.
683constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
684
685template <int width, int height, Secure secure>
686struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700687 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
688 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
689 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
690 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
691
692 static void injectHwcDisplay(DisplayTransactionTest*) {}
693
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700694 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
695 DisplayTransactionTest* test) {
696 const ::testing::TestInfo* const test_info =
697 ::testing::UnitTest::GetInstance()->current_test_info();
698
699 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
700 .setPixels({Base::WIDTH, Base::HEIGHT})
701 .setIsSecure(static_cast<bool>(Base::SECURE))
702 .setPowerAdvisor(&test->mPowerAdvisor)
703 .setName(std::string("Injected display for ") +
704 test_info->test_case_name() + "." + test_info->name())
705 .build();
706
707 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
708 ceDisplayArgs);
709 }
710
Dominik Laskowski075d3172018-05-24 15:50:06 -0700711 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
712 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
713 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800714
715 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
716 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
717 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
718 }
719};
720
721// A virtual display supported by the HWC.
722constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
723
724template <int width, int height, Secure secure>
725struct HwcVirtualDisplayVariant
Marin Shalamanova524a092020-07-27 21:39:55 +0200726 : DisplayVariant<VirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE,
727 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
728 HwcDisplayVariant<HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL,
729 DisplayVariant<VirtualDisplayIdType<42>, width, height, Critical::FALSE,
730 Async::TRUE, secure, Primary::FALSE,
731 GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
732 using Base = DisplayVariant<VirtualDisplayIdType<42>, width, height, Critical::FALSE,
733 Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800734 using Self = HwcVirtualDisplayVariant<width, height, secure>;
735
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700736 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
737 DisplayTransactionTest* test) {
738 const ::testing::TestInfo* const test_info =
739 ::testing::UnitTest::GetInstance()->current_test_info();
740
741 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
742 .setUseHwcVirtualDisplays(false)
743 .setPixels({Base::WIDTH, Base::HEIGHT})
744 .setIsSecure(static_cast<bool>(Base::SECURE))
745 .setPowerAdvisor(&test->mPowerAdvisor)
746 .setName(std::string("Injected display for ") +
747 test_info->test_case_name() + "." + test_info->name())
748 .build();
749
750 auto compositionDisplay =
751 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
752 ceDisplayArgs);
753 compositionDisplay->setDisplayIdForTesting(Base::DISPLAY_ID::get());
754
755 // Insert display data so that the HWC thinks it created the virtual display.
756 if (const auto displayId = Base::DISPLAY_ID::get()) {
757 test->mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
758 }
759
760 return compositionDisplay;
761 }
762
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800763 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
764 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
765 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
766 }
767
768 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
769 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
770 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
771 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
772 }
773};
774
775// For this variant, SurfaceFlinger should not configure itself with wide
776// display support, so the display should not be configured for wide-color
777// support.
778struct WideColorSupportNotConfiguredVariant {
779 static constexpr bool WIDE_COLOR_SUPPORTED = false;
780
781 static void injectConfigChange(DisplayTransactionTest* test) {
782 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700783 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800784 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800785 }
786
787 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
788 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
789 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
790 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
791 }
792};
793
794// For this variant, SurfaceFlinger should configure itself with wide display
795// support, and the display should respond with an non-empty list of supported
796// color modes. Wide-color support should be configured.
797template <typename Display>
798struct WideColorP3ColorimetricSupportedVariant {
799 static constexpr bool WIDE_COLOR_SUPPORTED = true;
800
801 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700802 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800803 test->mFlinger.mutableHasWideColorDisplay() = true;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800804 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800805 }
806
807 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800808 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
809
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800810 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
811 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
812 Return(Error::NONE)));
813 EXPECT_CALL(*test->mComposer,
814 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
815 .WillOnce(DoAll(SetArgPointee<2>(
816 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
817 Return(Error::NONE)));
818 EXPECT_CALL(*test->mComposer,
819 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
820 RenderIntent::COLORIMETRIC))
821 .WillOnce(Return(Error::NONE));
822 }
823};
824
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800825// For this variant, SurfaceFlinger should configure itself with wide display
826// support, but the display should respond with an empty list of supported color
827// modes. Wide-color support for the display should not be configured.
828template <typename Display>
829struct WideColorNotSupportedVariant {
830 static constexpr bool WIDE_COLOR_SUPPORTED = false;
831
832 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700833 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800834 test->mFlinger.mutableHasWideColorDisplay() = true;
835 }
836
837 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
838 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
839 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700840 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800841 }
842};
843
844// For this variant, the display is not a HWC display, so no HDR support should
845// be configured.
846struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800847 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800848 static constexpr bool HDR10_SUPPORTED = false;
849 static constexpr bool HDR_HLG_SUPPORTED = false;
850 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
851 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
852 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
853 }
854};
855
Valerie Haue9e843a2018-12-18 13:39:23 -0800856template <typename Display>
857struct Hdr10PlusSupportedVariant {
858 static constexpr bool HDR10_PLUS_SUPPORTED = true;
859 static constexpr bool HDR10_SUPPORTED = true;
860 static constexpr bool HDR_HLG_SUPPORTED = false;
861 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
862 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
863 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
864 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
865 Hdr::HDR10_PLUS,
866 Hdr::HDR10,
867 })),
868 Return(Error::NONE)));
869 }
870};
871
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800872// For this variant, the composer should respond with a non-empty list of HDR
873// modes containing HDR10, so HDR10 support should be configured.
874template <typename Display>
875struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800876 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800877 static constexpr bool HDR10_SUPPORTED = true;
878 static constexpr bool HDR_HLG_SUPPORTED = false;
879 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
880 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
881 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
882 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
883 Return(Error::NONE)));
884 }
885};
886
887// For this variant, the composer should respond with a non-empty list of HDR
888// modes containing HLG, so HLG support should be configured.
889template <typename Display>
890struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800891 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800892 static constexpr bool HDR10_SUPPORTED = false;
893 static constexpr bool HDR_HLG_SUPPORTED = true;
894 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
895 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
896 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
897 .WillOnce(
898 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
899 }
900};
901
902// For this variant, the composer should respond with a non-empty list of HDR
903// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
904template <typename Display>
905struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800906 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800907 static constexpr bool HDR10_SUPPORTED = false;
908 static constexpr bool HDR_HLG_SUPPORTED = false;
909 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
910 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
911 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
912 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
913 Return(Error::NONE)));
914 }
915};
916
917// For this variant, the composer should respond with am empty list of HDR
918// modes, so no HDR support should be configured.
919template <typename Display>
920struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800921 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800922 static constexpr bool HDR10_SUPPORTED = false;
923 static constexpr bool HDR_HLG_SUPPORTED = false;
924 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
925 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
926 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
927 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
928 }
929};
930
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700931struct NonHwcPerFrameMetadataSupportVariant {
932 static constexpr int PER_FRAME_METADATA_KEYS = 0;
933 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800934 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700935 }
936};
937
938template <typename Display>
939struct NoPerFrameMetadataSupportVariant {
940 static constexpr int PER_FRAME_METADATA_KEYS = 0;
941 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800942 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
943 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700944 }
945};
946
947template <typename Display>
948struct Smpte2086PerFrameMetadataSupportVariant {
949 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
950 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800951 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
952 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800953 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
954 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
955 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
956 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
957 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
958 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
959 PerFrameMetadataKey::WHITE_POINT_X,
960 PerFrameMetadataKey::WHITE_POINT_Y,
961 PerFrameMetadataKey::MAX_LUMINANCE,
962 PerFrameMetadataKey::MIN_LUMINANCE,
963 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700964 }
965};
966
967template <typename Display>
968struct Cta861_3_PerFrameMetadataSupportVariant {
969 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
970 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800971 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
972 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800973 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
974 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
975 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700976 }
977};
978
Valerie Haue9e843a2018-12-18 13:39:23 -0800979template <typename Display>
980struct Hdr10_Plus_PerFrameMetadataSupportVariant {
981 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
982 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
983 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
984 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
985 PerFrameMetadataKey::HDR10_PLUS_SEI,
986 })));
987 }
988};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800989/* ------------------------------------------------------------------------
990 * Typical display configurations to test
991 */
992
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700993template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
994 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800995struct Case {
996 using Display = DisplayPolicy;
997 using WideColorSupport = WideColorSupportPolicy;
998 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700999 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001000};
1001
1002using SimplePrimaryDisplayCase =
1003 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001004 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1005 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001006using SimpleExternalDisplayCase =
1007 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001008 HdrNotSupportedVariant<ExternalDisplayVariant>,
1009 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001010using SimpleTertiaryDisplayCase =
1011 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001012 HdrNotSupportedVariant<TertiaryDisplayVariant>,
1013 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001014using NonHwcVirtualDisplayCase =
1015 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001016 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
1017 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001018using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
1019using HwcVirtualDisplayCase =
1020 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -07001021 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +08001022 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001023using WideColorP3ColorimetricDisplayCase =
1024 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001025 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1026 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -08001027using Hdr10PlusDisplayCase =
1028 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1029 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1030 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001031using Hdr10DisplayCase =
1032 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001033 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1034 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001035using HdrHlgDisplayCase =
1036 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001037 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
1038 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001039using HdrDolbyVisionDisplayCase =
1040 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001041 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
1042 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1043using HdrSmpte2086DisplayCase =
1044 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1045 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1046 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1047using HdrCta861_3_DisplayCase =
1048 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1049 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1050 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -07001051
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001052/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -08001053 *
1054 * SurfaceFlinger::onHotplugReceived
1055 */
1056
1057TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
1058 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001059 constexpr HWDisplayId hwcDisplayId1 = 456;
1060 constexpr HWDisplayId hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001061
1062 // --------------------------------------------------------------------
1063 // Preconditions
1064
1065 // Set the current sequence id for accepted events
1066 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1067
1068 // Set the main thread id so that the current thread does not appear to be
1069 // the main thread.
1070 mFlinger.mutableMainThreadId() = std::thread::id();
1071
1072 // --------------------------------------------------------------------
1073 // Call Expectations
1074
1075 // We expect invalidate() to be invoked once to trigger display transaction
1076 // processing.
1077 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1078
1079 // --------------------------------------------------------------------
1080 // Invocation
1081
1082 // Simulate two hotplug events (a connect and a disconnect)
Peiyong Line9d809e2020-04-14 13:10:48 -07001083 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, Connection::CONNECTED);
1084 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001085
1086 // --------------------------------------------------------------------
1087 // Postconditions
1088
1089 // The display transaction needed flag should be set.
1090 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1091
1092 // All events should be in the pending event queue.
1093 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
1094 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001095 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001096 EXPECT_EQ(Connection::CONNECTED, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001097 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001098 EXPECT_EQ(Connection::DISCONNECTED, pendingEvents[1].connection);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001099}
1100
1101TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
1102 constexpr int currentSequenceId = 123;
1103 constexpr int otherSequenceId = 321;
Peiyong Line9d809e2020-04-14 13:10:48 -07001104 constexpr HWDisplayId displayId = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001105
1106 // --------------------------------------------------------------------
1107 // Preconditions
1108
1109 // Set the current sequence id for accepted events
1110 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1111
1112 // Set the main thread id so that the current thread does not appear to be
1113 // the main thread.
1114 mFlinger.mutableMainThreadId() = std::thread::id();
1115
1116 // --------------------------------------------------------------------
1117 // Call Expectations
1118
1119 // We do not expect any calls to invalidate().
1120 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
1121
1122 // --------------------------------------------------------------------
1123 // Invocation
1124
1125 // Call with an unexpected sequence id
Peiyong Line9d809e2020-04-14 13:10:48 -07001126 mFlinger.onHotplugReceived(otherSequenceId, displayId, Connection::INVALID);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001127
1128 // --------------------------------------------------------------------
1129 // Postconditions
1130
1131 // The display transaction needed flag should not be set
1132 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1133
1134 // There should be no pending events
1135 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1136}
1137
1138TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
1139 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001140 constexpr HWDisplayId displayId1 = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001141
1142 // --------------------------------------------------------------------
1143 // Note:
1144 // --------------------------------------------------------------------
1145 // This test case is a bit tricky. We want to verify that
1146 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
1147 // don't really want to provide coverage for everything the later function
1148 // does as there are specific tests for it.
1149 // --------------------------------------------------------------------
1150
1151 // --------------------------------------------------------------------
1152 // Preconditions
1153
1154 // Set the current sequence id for accepted events
1155 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1156
1157 // Set the main thread id so that the current thread does appear to be the
1158 // main thread.
1159 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
1160
1161 // --------------------------------------------------------------------
1162 // Call Expectations
1163
1164 // We expect invalidate() to be invoked once to trigger display transaction
1165 // processing.
1166 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1167
1168 // --------------------------------------------------------------------
1169 // Invocation
1170
1171 // Simulate a disconnect on a display id that is not connected. This should
1172 // be enqueued by onHotplugReceived(), and dequeued by
1173 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
Peiyong Line9d809e2020-04-14 13:10:48 -07001174 mFlinger.onHotplugReceived(currentSequenceId, displayId1, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001175
1176 // --------------------------------------------------------------------
1177 // Postconditions
1178
1179 // The display transaction needed flag should be set.
1180 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1181
1182 // There should be no event queued on return, as it should have been
1183 // processed.
1184 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1185}
1186
1187/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001188 * SurfaceFlinger::createDisplay
1189 */
1190
1191TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1192 const String8 name("virtual.test");
1193
1194 // --------------------------------------------------------------------
1195 // Call Expectations
1196
1197 // The call should notify the interceptor that a display was created.
1198 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1199
1200 // --------------------------------------------------------------------
1201 // Invocation
1202
1203 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1204
1205 // --------------------------------------------------------------------
1206 // Postconditions
1207
1208 // The display should have been added to the current state
1209 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1210 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001211 EXPECT_TRUE(display.isVirtual());
1212 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001213 EXPECT_EQ(name.string(), display.displayName);
1214
1215 // --------------------------------------------------------------------
1216 // Cleanup conditions
1217
1218 // Destroying the display invalidates the display state.
1219 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1220}
1221
1222TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1223 const String8 name("virtual.test");
1224
1225 // --------------------------------------------------------------------
1226 // Call Expectations
1227
1228 // The call should notify the interceptor that a display was created.
1229 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1230
1231 // --------------------------------------------------------------------
1232 // Invocation
1233
1234 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
1235
1236 // --------------------------------------------------------------------
1237 // Postconditions
1238
1239 // The display should have been added to the current state
1240 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1241 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001242 EXPECT_TRUE(display.isVirtual());
1243 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001244 EXPECT_EQ(name.string(), display.displayName);
1245
1246 // --------------------------------------------------------------------
1247 // Cleanup conditions
1248
1249 // Destroying the display invalidates the display state.
1250 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1251}
1252
1253/* ------------------------------------------------------------------------
1254 * SurfaceFlinger::destroyDisplay
1255 */
1256
1257TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1258 using Case = NonHwcVirtualDisplayCase;
1259
1260 // --------------------------------------------------------------------
1261 // Preconditions
1262
1263 // A virtual display exists
1264 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1265 existing.inject();
1266
1267 // --------------------------------------------------------------------
1268 // Call Expectations
1269
1270 // The call should notify the interceptor that a display was created.
1271 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1272
1273 // Destroying the display invalidates the display state.
1274 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1275
1276 // --------------------------------------------------------------------
1277 // Invocation
1278
1279 mFlinger.destroyDisplay(existing.token());
1280
1281 // --------------------------------------------------------------------
1282 // Postconditions
1283
1284 // The display should have been removed from the current state
1285 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1286
1287 // Ths display should still exist in the drawing state
1288 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1289
1290 // The display transaction needed flasg should be set
1291 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1292}
1293
1294TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1295 // --------------------------------------------------------------------
1296 // Preconditions
1297
1298 sp<BBinder> displayToken = new BBinder();
1299
1300 // --------------------------------------------------------------------
1301 // Invocation
1302
1303 mFlinger.destroyDisplay(displayToken);
1304}
1305
1306/* ------------------------------------------------------------------------
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001307 * SurfaceFlinger::notifyPowerBoost
1308 */
1309
1310TEST_F(DisplayTransactionTest, notifyPowerBoostNotifiesTouchEvent) {
1311 mFlinger.scheduler()->replaceTouchTimer(100);
1312 std::this_thread::sleep_for(10ms); // wait for callback to be triggered
1313 EXPECT_TRUE(mFlinger.scheduler()->isTouchActive()); // Starting timer activates touch
1314
1315 std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback
1316 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1317
1318 EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::CAMERA_SHOT)));
1319 std::this_thread::sleep_for(10ms); // wait for callback to maybe be triggered
1320 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1321
1322 std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback
1323 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1324
1325 EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::INTERACTION)));
1326 std::this_thread::sleep_for(10ms); // wait for callback to be triggered.
1327 EXPECT_TRUE(mFlinger.scheduler()->isTouchActive());
1328}
1329
1330/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001331 * DisplayDevice::GetBestColorMode
1332 */
1333class GetBestColorModeTest : public DisplayTransactionTest {
1334public:
Valerie Hau9758ae02018-10-09 16:05:09 -07001335 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1336
1337 void addHwcColorModesMapping(ui::ColorMode colorMode,
1338 std::vector<ui::RenderIntent> renderIntents) {
1339 mHwcColorModes[colorMode] = renderIntents;
1340 }
1341
1342 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1343
1344 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1345
1346 void getBestColorMode() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001347 auto displayDevice =
1348 injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1349 injector.setHwcColorModes(mHwcColorModes);
1350 injector.setHasWideColorGamut(mHasWideColorGamut);
1351 injector.setNativeWindow(mNativeWindow);
1352 });
Valerie Hau9758ae02018-10-09 16:05:09 -07001353
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001354 displayDevice->getCompositionDisplay()
1355 ->getDisplayColorProfile()
1356 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1357 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001358 }
1359
1360 ui::Dataspace mOutDataspace;
1361 ui::ColorMode mOutColorMode;
1362 ui::RenderIntent mOutRenderIntent;
1363
1364private:
1365 ui::Dataspace mInputDataspace;
1366 ui::RenderIntent mInputRenderIntent;
1367 bool mHasWideColorGamut = false;
1368 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
Valerie Hau9758ae02018-10-09 16:05:09 -07001369};
1370
1371TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1372 addHwcColorModesMapping(ui::ColorMode::SRGB,
1373 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1374 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1375 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1376 setHasWideColorGamut(true);
1377
1378 getBestColorMode();
1379
Peiyong Lin14724e62018-12-05 07:27:30 -08001380 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001381 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1382 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1383}
1384
1385TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1386 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1387 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1388 addHwcColorModesMapping(ui::ColorMode::SRGB,
1389 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1390 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1391 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1392 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1393 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1394 setHasWideColorGamut(true);
1395
1396 getBestColorMode();
1397
1398 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1399 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1400 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1401}
1402
1403TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1404 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1405 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1406 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1407 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1408 setHasWideColorGamut(true);
1409
1410 getBestColorMode();
1411
1412 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1413 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1414 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1415}
1416
1417/* ------------------------------------------------------------------------
Lloyd Pique33050472019-12-19 17:12:44 -08001418 * DisplayDevice::setProjection
1419 */
1420
1421class DisplayDeviceSetProjectionTest : public DisplayTransactionTest {
1422public:
Lloyd Pique33050472019-12-19 17:12:44 -08001423 static constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1080; // arbitrary
1424 static constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1920; // arbitrary
1425
1426 static constexpr int32_t TRANSFORM_FLAGS_ROT_0 = 0;
1427 static constexpr int32_t TRANSFORM_FLAGS_ROT_90 = HAL_TRANSFORM_ROT_90;
1428 static constexpr int32_t TRANSFORM_FLAGS_ROT_180 = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V;
1429 static constexpr int32_t TRANSFORM_FLAGS_ROT_270 =
1430 HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
1431
1432 DisplayDeviceSetProjectionTest(ui::Size flingerDisplaySize, ui::Size hardwareDisplaySize,
1433 ui::Rotation physicalOrientation)
1434 : mFlingerDisplaySize(flingerDisplaySize),
1435 mHardwareDisplaySize(hardwareDisplaySize),
1436 mPhysicalOrientation(physicalOrientation),
1437 mDisplayDevice(createDisplayDevice()) {}
1438
1439 sp<DisplayDevice> createDisplayDevice() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001440 return injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1441 injector.setPhysicalOrientation(mPhysicalOrientation);
1442 });
Lloyd Pique33050472019-12-19 17:12:44 -08001443 }
1444
1445 ui::Size SwapWH(const ui::Size size) const { return ui::Size(size.height, size.width); }
1446
1447 void setProjectionForRotation0() {
1448 // A logical rotation of 0 uses the SurfaceFlinger display size
1449 mDisplayDevice->setProjection(ui::ROTATION_0, Rect(mFlingerDisplaySize),
1450 Rect(mFlingerDisplaySize));
1451 }
1452
1453 void setProjectionForRotation90() {
1454 // A logical rotation of 90 uses the SurfaceFlinger display size with
1455 // the width/height swapped.
1456 mDisplayDevice->setProjection(ui::ROTATION_90, Rect(SwapWH(mFlingerDisplaySize)),
1457 Rect(SwapWH(mFlingerDisplaySize)));
1458 }
1459
1460 void setProjectionForRotation180() {
1461 // A logical rotation of 180 uses the SurfaceFlinger display size
1462 mDisplayDevice->setProjection(ui::ROTATION_180, Rect(mFlingerDisplaySize),
1463 Rect(mFlingerDisplaySize));
1464 }
1465
1466 void setProjectionForRotation270() {
1467 // A logical rotation of 270 uses the SurfaceFlinger display size with
1468 // the width/height swapped.
1469 mDisplayDevice->setProjection(ui::ROTATION_270, Rect(SwapWH(mFlingerDisplaySize)),
1470 Rect(SwapWH(mFlingerDisplaySize)));
1471 }
1472
1473 void expectStateForHardwareTransform0() {
1474 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1475 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_0, mHardwareDisplaySize.width,
1476 mHardwareDisplaySize.height),
1477 compositionState.transform);
1478 EXPECT_EQ(TRANSFORM_FLAGS_ROT_0, compositionState.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001479 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content);
1480 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.orientedDisplaySpace.content);
1481 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001482 EXPECT_EQ(false, compositionState.needsFiltering);
1483 }
1484
1485 void expectStateForHardwareTransform90() {
1486 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1487 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width,
1488 mHardwareDisplaySize.height),
1489 compositionState.transform);
1490 EXPECT_EQ(TRANSFORM_FLAGS_ROT_90, compositionState.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001491 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content);
1492 // For 90, the orientedDisplaySpaceRect and layerStackSpaceRect have the hardware display
1493 // size width and height swapped
1494 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)),
1495 compositionState.orientedDisplaySpace.content);
1496 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001497 EXPECT_EQ(false, compositionState.needsFiltering);
1498 }
1499
1500 void expectStateForHardwareTransform180() {
1501 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1502 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width,
1503 mHardwareDisplaySize.height),
1504 compositionState.transform);
1505 EXPECT_EQ(TRANSFORM_FLAGS_ROT_180, compositionState.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001506 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.orientedDisplaySpace.content);
1507 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001508 EXPECT_EQ(false, compositionState.needsFiltering);
1509 }
1510
1511 void expectStateForHardwareTransform270() {
1512 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1513 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width,
1514 mHardwareDisplaySize.height),
1515 compositionState.transform);
1516 EXPECT_EQ(TRANSFORM_FLAGS_ROT_270, compositionState.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001517 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content);
1518 // For 270, the orientedDisplaySpaceRect and layerStackSpaceRect have the hardware display
1519 // size width and height swapped
1520 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)),
1521 compositionState.orientedDisplaySpace.content);
1522 EXPECT_EQ(Rect(SwapWH(mHardwareDisplaySize)), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001523 EXPECT_EQ(false, compositionState.needsFiltering);
1524 }
1525
1526 const ui::Size mFlingerDisplaySize;
1527 const ui::Size mHardwareDisplaySize;
1528 const ui::Rotation mPhysicalOrientation;
1529 const sp<DisplayDevice> mDisplayDevice;
1530};
1531
1532struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest {
1533 DisplayDeviceSetProjectionTest_Installed0()
1534 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1535 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1536 ui::ROTATION_0) {}
1537};
1538
1539TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) {
1540 setProjectionForRotation0();
1541 expectStateForHardwareTransform0();
1542}
1543
1544TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) {
1545 setProjectionForRotation90();
1546 expectStateForHardwareTransform90();
1547}
1548
1549TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) {
1550 setProjectionForRotation180();
1551 expectStateForHardwareTransform180();
1552}
1553
1554TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) {
1555 setProjectionForRotation270();
1556 expectStateForHardwareTransform270();
1557}
1558
1559struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest {
1560 DisplayDeviceSetProjectionTest_Installed90()
1561 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1562 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1563 ui::ROTATION_90) {}
1564};
1565
1566TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) {
1567 setProjectionForRotation0();
1568 expectStateForHardwareTransform90();
1569}
1570
1571TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) {
1572 setProjectionForRotation90();
1573 expectStateForHardwareTransform180();
1574}
1575
1576TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) {
1577 setProjectionForRotation180();
1578 expectStateForHardwareTransform270();
1579}
1580
1581TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) {
1582 setProjectionForRotation270();
1583 expectStateForHardwareTransform0();
1584}
1585
1586struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest {
1587 DisplayDeviceSetProjectionTest_Installed180()
1588 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1589 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1590 ui::ROTATION_180) {}
1591};
1592
1593TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) {
1594 setProjectionForRotation0();
1595 expectStateForHardwareTransform180();
1596}
1597
1598TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) {
1599 setProjectionForRotation90();
1600 expectStateForHardwareTransform270();
1601}
1602
1603TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) {
1604 setProjectionForRotation180();
1605 expectStateForHardwareTransform0();
1606}
1607
1608TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) {
1609 setProjectionForRotation270();
1610 expectStateForHardwareTransform90();
1611}
1612
1613struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest {
1614 DisplayDeviceSetProjectionTest_Installed270()
1615 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1616 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1617 ui::ROTATION_270) {}
1618};
1619
1620TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) {
1621 setProjectionForRotation0();
1622 expectStateForHardwareTransform270();
1623}
1624
1625TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) {
1626 setProjectionForRotation90();
1627 expectStateForHardwareTransform0();
1628}
1629
1630TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) {
1631 setProjectionForRotation180();
1632 expectStateForHardwareTransform90();
1633}
1634
1635TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) {
1636 setProjectionForRotation270();
1637 expectStateForHardwareTransform180();
1638}
1639
1640/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001641 * SurfaceFlinger::getDisplayNativePrimaries
1642 */
1643
1644class GetDisplayNativePrimaries : public DisplayTransactionTest {
1645public:
1646 GetDisplayNativePrimaries();
1647 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1648 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1649
1650private:
1651 static constexpr float mStartingTestValue = 1.0f;
1652};
1653
1654GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1655 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1656 injectFakeNativeWindowSurfaceFactory();
1657}
1658
1659void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1660 ui::DisplayPrimaries& primaries) {
1661 float startingVal = mStartingTestValue;
1662 primaries.red.X = startingVal++;
1663 primaries.red.Y = startingVal++;
1664 primaries.red.Z = startingVal++;
1665 primaries.green.X = startingVal++;
1666 primaries.green.Y = startingVal++;
1667 primaries.green.Z = startingVal++;
1668 primaries.blue.X = startingVal++;
1669 primaries.blue.Y = startingVal++;
1670 primaries.blue.Z = startingVal++;
1671 primaries.white.X = startingVal++;
1672 primaries.white.Y = startingVal++;
1673 primaries.white.Z = startingVal++;
1674}
1675
1676void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1677 const ui::DisplayPrimaries& primaries) {
1678 float startingVal = mStartingTestValue;
1679 EXPECT_EQ(primaries.red.X, startingVal++);
1680 EXPECT_EQ(primaries.red.Y, startingVal++);
1681 EXPECT_EQ(primaries.red.Z, startingVal++);
1682 EXPECT_EQ(primaries.green.X, startingVal++);
1683 EXPECT_EQ(primaries.green.Y, startingVal++);
1684 EXPECT_EQ(primaries.green.Z, startingVal++);
1685 EXPECT_EQ(primaries.blue.X, startingVal++);
1686 EXPECT_EQ(primaries.blue.Y, startingVal++);
1687 EXPECT_EQ(primaries.blue.Z, startingVal++);
1688 EXPECT_EQ(primaries.white.X, startingVal++);
1689 EXPECT_EQ(primaries.white.Y, startingVal++);
1690 EXPECT_EQ(primaries.white.Z, startingVal++);
1691}
1692
1693TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1694 ui::DisplayPrimaries primaries;
1695 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1696}
1697
Daniel Solomon42d04562019-01-20 21:03:19 -08001698TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1699 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1700 injector.inject();
1701 auto internalDisplayToken = injector.token();
1702
1703 ui::DisplayPrimaries expectedPrimaries;
1704 populateDummyDisplayNativePrimaries(expectedPrimaries);
1705 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1706
1707 ui::DisplayPrimaries primaries;
1708 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1709
1710 checkDummyDisplayNativePrimaries(primaries);
1711}
1712
1713TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1714 sp<BBinder> notInternalDisplayToken = new BBinder();
1715
1716 ui::DisplayPrimaries primaries;
1717 populateDummyDisplayNativePrimaries(primaries);
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001718 EXPECT_EQ(NAME_NOT_FOUND,
1719 mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
Daniel Solomon42d04562019-01-20 21:03:19 -08001720
1721 // Check primaries argument wasn't modified in case of failure
1722 checkDummyDisplayNativePrimaries(primaries);
1723}
1724
1725/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001726 * SurfaceFlinger::setupNewDisplayDeviceInternal
1727 */
1728
1729class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1730public:
1731 template <typename T>
1732 void setupNewDisplayDeviceInternalTest();
1733};
1734
1735template <typename Case>
1736void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1737 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001738 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1739 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001740 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001741
1742 // --------------------------------------------------------------------
1743 // Preconditions
1744
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001745 // Wide color displays support is configured appropriately
1746 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001747
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001748 // The display is setup with the HWC.
1749 Case::Display::injectHwcDisplay(this);
1750
1751 // SurfaceFlinger will use a test-controlled factory for native window
1752 // surfaces.
1753 injectFakeNativeWindowSurfaceFactory();
1754
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001755 // A compositionengine::Display has already been created
1756 auto compositionDisplay = Case::Display::injectCompositionDisplay(this);
1757
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001758 // --------------------------------------------------------------------
1759 // Call Expectations
1760
1761 // Various native window calls will be made.
1762 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001763 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001764 Case::WideColorSupport::setupComposerCallExpectations(this);
1765 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001766 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001767
1768 // --------------------------------------------------------------------
1769 // Invocation
1770
1771 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -08001772 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1773 const auto displayId = Case::Display::DISPLAY_ID::get();
1774 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001775 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1776 ASSERT_TRUE(hwcDisplayId);
Marin Shalamanova524a092020-07-27 21:39:55 +02001777 state.physical = {.id = static_cast<PhysicalDisplayId>(*displayId),
1778 .type = *connectionType,
1779 .hwcDisplayId = *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001780 }
1781
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001782 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1783
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001784 auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state,
1785 displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001786
1787 // --------------------------------------------------------------------
1788 // Postconditions
1789
1790 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001791 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001792 EXPECT_EQ(Case::Display::CONNECTION_TYPE::value, device->getConnectionType());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001793 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001794 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001795 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001796 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1797 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1798 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001799 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001800 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1801 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1802 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001803 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1804 // remapped, and the test only ever sets up one config. If there were an error
1805 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
Ady Abraham2139f732019-11-13 18:56:40 -08001806 EXPECT_EQ(0, device->getActiveConfig().value());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001807 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1808 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001809}
1810
1811TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1812 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1813}
1814
1815TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1816 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1817}
1818
1819TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1820 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1821}
1822
1823TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001824 setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001825}
1826
1827TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1828 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1829}
1830
Valerie Haue9e843a2018-12-18 13:39:23 -08001831TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1832 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1833}
1834
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001835TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1836 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1837}
1838
1839TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1840 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1841}
1842
1843TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1844 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1845}
1846
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001847TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1848 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1849}
1850
1851TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1852 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1853}
1854
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001855/* ------------------------------------------------------------------------
1856 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1857 */
1858
1859class HandleTransactionLockedTest : public DisplayTransactionTest {
1860public:
1861 template <typename Case>
1862 void setupCommonPreconditions();
1863
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001864 template <typename Case, bool connected>
1865 static void expectHotplugReceived(mock::EventThread*);
1866
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001867 template <typename Case>
1868 void setupCommonCallExpectationsForConnectProcessing();
1869
1870 template <typename Case>
1871 void setupCommonCallExpectationsForDisconnectProcessing();
1872
1873 template <typename Case>
1874 void processesHotplugConnectCommon();
1875
1876 template <typename Case>
1877 void ignoresHotplugConnectCommon();
1878
1879 template <typename Case>
1880 void processesHotplugDisconnectCommon();
1881
1882 template <typename Case>
1883 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1884
1885 template <typename Case>
1886 void verifyPhysicalDisplayIsConnected();
1887
1888 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1889};
1890
1891template <typename Case>
1892void HandleTransactionLockedTest::setupCommonPreconditions() {
1893 // Wide color displays support is configured appropriately
1894 Case::WideColorSupport::injectConfigChange(this);
1895
1896 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1897 injectFakeBufferQueueFactory();
1898
1899 // SurfaceFlinger will use a test-controlled factory for native window
1900 // surfaces.
1901 injectFakeNativeWindowSurfaceFactory();
1902}
1903
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001904template <typename Case, bool connected>
1905void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1906 const auto convert = [](auto physicalDisplayId) {
1907 return std::make_optional(DisplayId{physicalDisplayId});
1908 };
1909
1910 EXPECT_CALL(*eventThread,
1911 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1912 .Times(1);
1913}
1914
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001915template <typename Case>
1916void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1917 Case::Display::setupHwcHotplugCallExpectations(this);
1918
1919 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1920 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1921 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1922 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1923
1924 Case::WideColorSupport::setupComposerCallExpectations(this);
1925 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001926 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001927
1928 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001929 expectHotplugReceived<Case, true>(mEventThread);
1930 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001931}
1932
1933template <typename Case>
1934void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1935 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001936
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001937 expectHotplugReceived<Case, false>(mEventThread);
1938 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001939}
1940
1941template <typename Case>
1942void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1943 // The display device should have been set up in the list of displays.
1944 ASSERT_TRUE(hasDisplayDevice(displayToken));
1945 const auto& device = getDisplayDevice(displayToken);
1946 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001947 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001948
Dominik Laskowski55c85402020-01-21 16:25:47 -08001949 std::optional<DisplayDeviceState::Physical> expectedPhysical;
1950 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1951 const auto displayId = Case::Display::DISPLAY_ID::get();
1952 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001953 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1954 ASSERT_TRUE(hwcDisplayId);
Marin Shalamanova524a092020-07-27 21:39:55 +02001955 expectedPhysical = {.id = static_cast<PhysicalDisplayId>(*displayId),
Marin Shalamanov7ce87642020-05-06 13:45:58 +02001956 .type = *connectionType,
1957 .hwcDisplayId = *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001958 }
1959
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001960 // The display should have been set up in the current display state
1961 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1962 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001963 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001964 EXPECT_EQ(expectedPhysical, current.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001965
1966 // The display should have been set up in the drawing 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());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001970 EXPECT_EQ(expectedPhysical, draw.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001971}
1972
1973template <typename Case>
1974void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1975 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001976 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001977
Dominik Laskowski075d3172018-05-24 15:50:06 -07001978 // SF should have a display token.
1979 const auto displayId = Case::Display::DISPLAY_ID::get();
1980 ASSERT_TRUE(displayId);
1981 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1982 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001983
1984 verifyDisplayIsConnected<Case>(displayToken);
1985}
1986
1987void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1988 EXPECT_FALSE(hasDisplayDevice(displayToken));
1989 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1990 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1991}
1992
1993template <typename Case>
1994void HandleTransactionLockedTest::processesHotplugConnectCommon() {
1995 // --------------------------------------------------------------------
1996 // Preconditions
1997
1998 setupCommonPreconditions<Case>();
1999
2000 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002001 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002002
2003 // --------------------------------------------------------------------
2004 // Call Expectations
2005
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002006 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002007
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002008 // --------------------------------------------------------------------
2009 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08002010
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002011 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08002012
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002013 // --------------------------------------------------------------------
2014 // Postconditions
2015
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002016 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002017
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002018 // --------------------------------------------------------------------
2019 // Cleanup conditions
2020
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002021 EXPECT_CALL(*mComposer,
2022 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002023 .WillOnce(Return(Error::NONE));
2024 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08002025}
2026
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002027template <typename Case>
2028void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
2029 // --------------------------------------------------------------------
2030 // Preconditions
2031
2032 setupCommonPreconditions<Case>();
2033
2034 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002035 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002036
2037 // --------------------------------------------------------------------
2038 // Invocation
2039
2040 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2041
2042 // --------------------------------------------------------------------
2043 // Postconditions
2044
2045 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002046 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002047}
2048
2049template <typename Case>
2050void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
2051 // --------------------------------------------------------------------
2052 // Preconditions
2053
2054 setupCommonPreconditions<Case>();
2055
2056 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002057 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002058
2059 // The display is already completely set up.
2060 Case::Display::injectHwcDisplay(this);
2061 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2062 existing.inject();
2063
2064 // --------------------------------------------------------------------
2065 // Call Expectations
2066
Lloyd Pique438e9e72018-09-04 18:06:08 -07002067 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
2068 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002069
2070 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2071
2072 // --------------------------------------------------------------------
2073 // Invocation
2074
2075 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2076
2077 // --------------------------------------------------------------------
2078 // Postconditions
2079
2080 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002081 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002082
Dominik Laskowski075d3172018-05-24 15:50:06 -07002083 // SF should not have a display token.
2084 const auto displayId = Case::Display::DISPLAY_ID::get();
2085 ASSERT_TRUE(displayId);
2086 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002087
2088 // The existing token should have been removed
2089 verifyDisplayIsNotConnected(existing.token());
2090}
2091
2092TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
2093 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2094}
2095
2096TEST_F(HandleTransactionLockedTest,
2097 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
2098 // Inject an external display.
2099 ExternalDisplayVariant::injectHwcDisplay(this);
2100
2101 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2102}
2103
2104TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
2105 // Inject a primary display.
2106 PrimaryDisplayVariant::injectHwcDisplay(this);
2107
2108 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
2109}
2110
2111TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
2112 // Inject both a primary and external display.
2113 PrimaryDisplayVariant::injectHwcDisplay(this);
2114 ExternalDisplayVariant::injectHwcDisplay(this);
2115
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002116 // TODO: This is an unnecessary call.
2117 EXPECT_CALL(*mComposer,
2118 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
2119 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
2120 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
2121 Return(Error::NONE)));
2122
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002123 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
2124}
2125
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002126TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectPrimaryDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002127 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
2128}
2129
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002130TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectExternalDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002131 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
2132}
2133
2134TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
2135 using Case = SimplePrimaryDisplayCase;
2136
2137 // --------------------------------------------------------------------
2138 // Preconditions
2139
2140 setupCommonPreconditions<Case>();
2141
2142 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002143 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002144 // A hotplug disconnect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002145 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002146
2147 // --------------------------------------------------------------------
2148 // Call Expectations
2149
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002150 setupCommonCallExpectationsForConnectProcessing<Case>();
2151 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2152
2153 EXPECT_CALL(*mComposer,
2154 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2155 .WillOnce(Return(Error::NONE));
2156 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2157
2158 // --------------------------------------------------------------------
2159 // Invocation
2160
2161 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2162
2163 // --------------------------------------------------------------------
2164 // Postconditions
2165
2166 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002167 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002168
Dominik Laskowski075d3172018-05-24 15:50:06 -07002169 // SF should not have a display token.
2170 const auto displayId = Case::Display::DISPLAY_ID::get();
2171 ASSERT_TRUE(displayId);
2172 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002173}
2174
2175TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
2176 using Case = SimplePrimaryDisplayCase;
2177
2178 // --------------------------------------------------------------------
2179 // Preconditions
2180
2181 setupCommonPreconditions<Case>();
2182
2183 // The display is already completely set up.
2184 Case::Display::injectHwcDisplay(this);
2185 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2186 existing.inject();
2187
2188 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002189 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002190 // A hotplug connect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002191 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002192
2193 // --------------------------------------------------------------------
2194 // Call Expectations
2195
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002196 setupCommonCallExpectationsForConnectProcessing<Case>();
2197 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2198
2199 // --------------------------------------------------------------------
2200 // Invocation
2201
2202 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2203
2204 // --------------------------------------------------------------------
2205 // Postconditions
2206
2207 // The existing token should have been removed
2208 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07002209 const auto displayId = Case::Display::DISPLAY_ID::get();
2210 ASSERT_TRUE(displayId);
2211 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
2212 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002213
2214 // A new display should be connected in its place
2215
2216 verifyPhysicalDisplayIsConnected<Case>();
2217
2218 // --------------------------------------------------------------------
2219 // Cleanup conditions
2220
2221 EXPECT_CALL(*mComposer,
2222 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2223 .WillOnce(Return(Error::NONE));
2224 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2225}
2226
2227TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
2228 using Case = HwcVirtualDisplayCase;
2229
2230 // --------------------------------------------------------------------
2231 // Preconditions
2232
2233 // The HWC supports at least one virtual display
2234 injectMockComposer(1);
2235
2236 setupCommonPreconditions<Case>();
2237
2238 // A virtual display was added to the current state, and it has a
2239 // surface(producer)
2240 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07002241
Dominik Laskowski075d3172018-05-24 15:50:06 -07002242 DisplayDeviceState state;
2243 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002244
2245 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07002246 state.surface = surface;
2247 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002248
2249 // --------------------------------------------------------------------
2250 // Call Expectations
2251
2252 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
2253 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
2254
2255 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
2256 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
2257 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
2258 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
2259 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
2260 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
2261 Return(NO_ERROR)));
2262 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
2263 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
2264
2265 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
2266
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002267 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002268 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
2269
2270 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
2271 Case::WideColorSupport::setupComposerCallExpectations(this);
2272 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07002273 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002274
2275 // --------------------------------------------------------------------
2276 // Invocation
2277
2278 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2279
2280 // --------------------------------------------------------------------
2281 // Postconditions
2282
2283 // The display device should have been set up in the list of displays.
2284 verifyDisplayIsConnected<Case>(displayToken);
2285
2286 // --------------------------------------------------------------------
2287 // Cleanup conditions
2288
2289 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
2290 .WillOnce(Return(Error::NONE));
2291 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08002292
2293 // Cleanup
2294 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
2295 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002296}
2297
2298TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
2299 using Case = HwcVirtualDisplayCase;
2300
2301 // --------------------------------------------------------------------
2302 // Preconditions
2303
2304 // The HWC supports at least one virtual display
2305 injectMockComposer(1);
2306
2307 setupCommonPreconditions<Case>();
2308
2309 // A virtual display was added to the current state, but it does not have a
2310 // surface.
2311 sp<BBinder> displayToken = new BBinder();
2312
Dominik Laskowski075d3172018-05-24 15:50:06 -07002313 DisplayDeviceState state;
2314 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002315
Dominik Laskowski075d3172018-05-24 15:50:06 -07002316 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002317
2318 // --------------------------------------------------------------------
2319 // Call Expectations
2320
2321 // --------------------------------------------------------------------
2322 // Invocation
2323
2324 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2325
2326 // --------------------------------------------------------------------
2327 // Postconditions
2328
2329 // There will not be a display device set up.
2330 EXPECT_FALSE(hasDisplayDevice(displayToken));
2331
2332 // The drawing display state will be set from the current display state.
2333 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2334 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002335 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002336}
2337
2338TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
2339 using Case = HwcVirtualDisplayCase;
2340
2341 // --------------------------------------------------------------------
2342 // Preconditions
2343
2344 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002345 const auto displayId = Case::Display::DISPLAY_ID::get();
2346 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08002347 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002348 Case::Display::injectHwcDisplay(this);
2349 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2350 existing.inject();
2351 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2352
2353 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002354 // Invocation
2355
2356 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2357
2358 // --------------------------------------------------------------------
2359 // Postconditions
2360
2361 // The existing token should have been removed
2362 verifyDisplayIsNotConnected(existing.token());
2363}
2364
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002365TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2366 using Case = NonHwcVirtualDisplayCase;
2367
2368 constexpr uint32_t oldLayerStack = 0u;
2369 constexpr uint32_t newLayerStack = 123u;
2370
2371 // --------------------------------------------------------------------
2372 // Preconditions
2373
2374 // A display is set up
2375 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2376 display.inject();
2377
2378 // There is a change to the layerStack state
2379 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2380 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2381
2382 // --------------------------------------------------------------------
2383 // Invocation
2384
2385 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2386
2387 // --------------------------------------------------------------------
2388 // Postconditions
2389
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002390 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002391}
2392
2393TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2394 using Case = NonHwcVirtualDisplayCase;
2395
Dominik Laskowski718f9602019-11-09 20:01:35 -08002396 constexpr ui::Rotation oldTransform = ui::ROTATION_0;
2397 constexpr ui::Rotation newTransform = ui::ROTATION_180;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002398
2399 // --------------------------------------------------------------------
2400 // Preconditions
2401
2402 // A display is set up
2403 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2404 display.inject();
2405
2406 // There is a change to the orientation state
2407 display.mutableDrawingDisplayState().orientation = oldTransform;
2408 display.mutableCurrentDisplayState().orientation = newTransform;
2409
2410 // --------------------------------------------------------------------
2411 // Invocation
2412
2413 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2414
2415 // --------------------------------------------------------------------
2416 // Postconditions
2417
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002418 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002419}
2420
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002421TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackRectChanges) {
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002422 using Case = NonHwcVirtualDisplayCase;
2423
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002424 const Rect oldLayerStackRect(0, 0, 0, 0);
2425 const Rect newLayerStackRect(0, 0, 123, 456);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002426
2427 // --------------------------------------------------------------------
2428 // Preconditions
2429
2430 // A display is set up
2431 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2432 display.inject();
2433
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002434 // There is a change to the layerStackSpaceRect state
2435 display.mutableDrawingDisplayState().layerStackSpaceRect = oldLayerStackRect;
2436 display.mutableCurrentDisplayState().layerStackSpaceRect = newLayerStackRect;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002437
2438 // --------------------------------------------------------------------
2439 // Invocation
2440
2441 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2442
2443 // --------------------------------------------------------------------
2444 // Postconditions
2445
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002446 EXPECT_EQ(newLayerStackRect, display.mutableDisplayDevice()->getLayerStackSpaceRect());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002447}
2448
2449TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2450 using Case = NonHwcVirtualDisplayCase;
2451
2452 const Rect oldFrame(0, 0, 0, 0);
2453 const Rect newFrame(0, 0, 123, 456);
2454
2455 // --------------------------------------------------------------------
2456 // Preconditions
2457
2458 // A display is set up
2459 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2460 display.inject();
2461
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002462 // There is a change to the layerStackSpaceRect state
2463 display.mutableDrawingDisplayState().orientedDisplaySpaceRect = oldFrame;
2464 display.mutableCurrentDisplayState().orientedDisplaySpaceRect = newFrame;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002465
2466 // --------------------------------------------------------------------
2467 // Invocation
2468
2469 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2470
2471 // --------------------------------------------------------------------
2472 // Postconditions
2473
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002474 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getOrientedDisplaySpaceRect());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002475}
2476
2477TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2478 using Case = NonHwcVirtualDisplayCase;
2479
2480 constexpr int oldWidth = 0;
2481 constexpr int oldHeight = 10;
2482 constexpr int newWidth = 123;
2483
2484 // --------------------------------------------------------------------
2485 // Preconditions
2486
2487 // A display is set up
2488 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002489 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002490 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002491 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2492 display.setNativeWindow(nativeWindow);
2493 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002494 // Setup injection expections
2495 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2496 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2497 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2498 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002499 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2500 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2501 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002502 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002503 display.inject();
2504
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002505 // There is a change to the layerStackSpaceRect state
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002506 display.mutableDrawingDisplayState().width = oldWidth;
2507 display.mutableDrawingDisplayState().height = oldHeight;
2508 display.mutableCurrentDisplayState().width = newWidth;
2509 display.mutableCurrentDisplayState().height = oldHeight;
2510
2511 // --------------------------------------------------------------------
2512 // Call Expectations
2513
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002514 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002515
2516 // --------------------------------------------------------------------
2517 // Invocation
2518
2519 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2520}
2521
2522TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2523 using Case = NonHwcVirtualDisplayCase;
2524
2525 constexpr int oldWidth = 0;
2526 constexpr int oldHeight = 10;
2527 constexpr int newHeight = 123;
2528
2529 // --------------------------------------------------------------------
2530 // Preconditions
2531
2532 // A display is set up
2533 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002534 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002535 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002536 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2537 display.setNativeWindow(nativeWindow);
2538 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002539 // Setup injection expections
2540 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2541 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2542 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2543 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002544 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2545 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2546 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002547 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002548 display.inject();
2549
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002550 // There is a change to the layerStackSpaceRect state
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002551 display.mutableDrawingDisplayState().width = oldWidth;
2552 display.mutableDrawingDisplayState().height = oldHeight;
2553 display.mutableCurrentDisplayState().width = oldWidth;
2554 display.mutableCurrentDisplayState().height = newHeight;
2555
2556 // --------------------------------------------------------------------
2557 // Call Expectations
2558
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002559 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002560
2561 // --------------------------------------------------------------------
2562 // Invocation
2563
2564 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2565}
2566
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002567/* ------------------------------------------------------------------------
2568 * SurfaceFlinger::setDisplayStateLocked
2569 */
2570
2571TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2572 // --------------------------------------------------------------------
2573 // Preconditions
2574
2575 // We have an unknown display token not associated with a known display
2576 sp<BBinder> displayToken = new BBinder();
2577
2578 // The requested display state references the unknown display.
2579 DisplayState state;
2580 state.what = DisplayState::eLayerStackChanged;
2581 state.token = displayToken;
2582 state.layerStack = 456;
2583
2584 // --------------------------------------------------------------------
2585 // Invocation
2586
2587 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2588
2589 // --------------------------------------------------------------------
2590 // Postconditions
2591
2592 // The returned flags are empty
2593 EXPECT_EQ(0u, flags);
2594
2595 // The display token still doesn't match anything known.
2596 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2597}
2598
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002599TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2600 using Case = SimplePrimaryDisplayCase;
2601
2602 // --------------------------------------------------------------------
2603 // Preconditions
2604
2605 // A display is already set up
2606 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2607 display.inject();
2608
2609 // No changes are made to the display
2610 DisplayState state;
2611 state.what = 0;
2612 state.token = display.token();
2613
2614 // --------------------------------------------------------------------
2615 // Invocation
2616
2617 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2618
2619 // --------------------------------------------------------------------
2620 // Postconditions
2621
2622 // The returned flags are empty
2623 EXPECT_EQ(0u, flags);
2624}
2625
2626TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2627 using Case = SimplePrimaryDisplayCase;
2628
2629 // --------------------------------------------------------------------
2630 // Preconditions
2631
2632 // A display is already set up
2633 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2634 display.inject();
2635
2636 // There is a surface that can be set.
2637 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2638
2639 // The current display state has the surface set
2640 display.mutableCurrentDisplayState().surface = surface;
2641
2642 // The incoming request sets the same surface
2643 DisplayState state;
2644 state.what = DisplayState::eSurfaceChanged;
2645 state.token = display.token();
2646 state.surface = surface;
2647
2648 // --------------------------------------------------------------------
2649 // Invocation
2650
2651 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2652
2653 // --------------------------------------------------------------------
2654 // Postconditions
2655
2656 // The returned flags are empty
2657 EXPECT_EQ(0u, flags);
2658
2659 // The current display state is unchanged.
2660 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2661}
2662
2663TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2664 using Case = SimplePrimaryDisplayCase;
2665
2666 // --------------------------------------------------------------------
2667 // Preconditions
2668
2669 // A display is already set up
2670 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2671 display.inject();
2672
2673 // There is a surface that can be set.
2674 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2675
2676 // The current display state does not have a surface
2677 display.mutableCurrentDisplayState().surface = nullptr;
2678
2679 // The incoming request sets a surface
2680 DisplayState state;
2681 state.what = DisplayState::eSurfaceChanged;
2682 state.token = display.token();
2683 state.surface = surface;
2684
2685 // --------------------------------------------------------------------
2686 // Invocation
2687
2688 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2689
2690 // --------------------------------------------------------------------
2691 // Postconditions
2692
2693 // The returned flags indicate a transaction is needed
2694 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2695
2696 // The current display layer stack state is set to the new value
2697 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2698}
2699
2700TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2701 using Case = SimplePrimaryDisplayCase;
2702
2703 // --------------------------------------------------------------------
2704 // Preconditions
2705
2706 // A display is already set up
2707 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2708 display.inject();
2709
2710 // The display has a layer stack set
2711 display.mutableCurrentDisplayState().layerStack = 456u;
2712
2713 // The incoming request sets the same layer stack
2714 DisplayState state;
2715 state.what = DisplayState::eLayerStackChanged;
2716 state.token = display.token();
2717 state.layerStack = 456u;
2718
2719 // --------------------------------------------------------------------
2720 // Invocation
2721
2722 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2723
2724 // --------------------------------------------------------------------
2725 // Postconditions
2726
2727 // The returned flags are empty
2728 EXPECT_EQ(0u, flags);
2729
2730 // The current display state is unchanged
2731 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2732}
2733
2734TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2735 using Case = SimplePrimaryDisplayCase;
2736
2737 // --------------------------------------------------------------------
2738 // Preconditions
2739
2740 // A display is set up
2741 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2742 display.inject();
2743
2744 // The display has a layer stack set
2745 display.mutableCurrentDisplayState().layerStack = 654u;
2746
2747 // The incoming request sets a different layer stack
2748 DisplayState state;
2749 state.what = DisplayState::eLayerStackChanged;
2750 state.token = display.token();
2751 state.layerStack = 456u;
2752
2753 // --------------------------------------------------------------------
2754 // Invocation
2755
2756 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2757
2758 // --------------------------------------------------------------------
2759 // Postconditions
2760
2761 // The returned flags indicate a transaction is needed
2762 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2763
2764 // The desired display state has been set to the new value.
2765 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2766}
2767
2768TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2769 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002770 constexpr ui::Rotation initialOrientation = ui::ROTATION_180;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002771 const Rect initialOrientedDisplayRect = {1, 2, 3, 4};
2772 const Rect initialLayerStackRect = {5, 6, 7, 8};
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002773
2774 // --------------------------------------------------------------------
2775 // Preconditions
2776
2777 // A display is set up
2778 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2779 display.inject();
2780
2781 // The current display state projection state is all set
2782 display.mutableCurrentDisplayState().orientation = initialOrientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002783 display.mutableCurrentDisplayState().orientedDisplaySpaceRect = initialOrientedDisplayRect;
2784 display.mutableCurrentDisplayState().layerStackSpaceRect = initialLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002785
2786 // The incoming request sets the same projection state
2787 DisplayState state;
2788 state.what = DisplayState::eDisplayProjectionChanged;
2789 state.token = display.token();
2790 state.orientation = initialOrientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002791 state.orientedDisplaySpaceRect = initialOrientedDisplayRect;
2792 state.layerStackSpaceRect = initialLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002793
2794 // --------------------------------------------------------------------
2795 // Invocation
2796
2797 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2798
2799 // --------------------------------------------------------------------
2800 // Postconditions
2801
2802 // The returned flags are empty
2803 EXPECT_EQ(0u, flags);
2804
2805 // The current display state is unchanged
2806 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2807
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002808 EXPECT_EQ(initialOrientedDisplayRect,
2809 display.getCurrentDisplayState().orientedDisplaySpaceRect);
2810 EXPECT_EQ(initialLayerStackRect, display.getCurrentDisplayState().layerStackSpaceRect);
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002811}
2812
2813TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2814 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002815 constexpr ui::Rotation initialOrientation = ui::ROTATION_90;
2816 constexpr ui::Rotation desiredOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002817
2818 // --------------------------------------------------------------------
2819 // Preconditions
2820
2821 // A display is set up
2822 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2823 display.inject();
2824
2825 // The current display state has an orientation set
2826 display.mutableCurrentDisplayState().orientation = initialOrientation;
2827
2828 // The incoming request sets a different orientation
2829 DisplayState state;
2830 state.what = DisplayState::eDisplayProjectionChanged;
2831 state.token = display.token();
2832 state.orientation = desiredOrientation;
2833
2834 // --------------------------------------------------------------------
2835 // Invocation
2836
2837 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2838
2839 // --------------------------------------------------------------------
2840 // Postconditions
2841
2842 // The returned flags indicate a transaction is needed
2843 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2844
2845 // The current display state has the new value.
2846 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2847}
2848
2849TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2850 using Case = SimplePrimaryDisplayCase;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002851 const Rect initialOrientedDisplayRect = {0, 0, 0, 0};
2852 const Rect desiredOrientedDisplayRect = {5, 6, 7, 8};
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002853
2854 // --------------------------------------------------------------------
2855 // Preconditions
2856
2857 // A display is set up
2858 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2859 display.inject();
2860
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002861 // The current display state does not have a orientedDisplaySpaceRect
2862 display.mutableCurrentDisplayState().orientedDisplaySpaceRect = initialOrientedDisplayRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002863
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002864 // The incoming request sets a orientedDisplaySpaceRect
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002865 DisplayState state;
2866 state.what = DisplayState::eDisplayProjectionChanged;
2867 state.token = display.token();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002868 state.orientedDisplaySpaceRect = desiredOrientedDisplayRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002869
2870 // --------------------------------------------------------------------
2871 // Invocation
2872
2873 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2874
2875 // --------------------------------------------------------------------
2876 // Postconditions
2877
2878 // The returned flags indicate a transaction is needed
2879 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2880
2881 // The current display state has the new value.
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002882 EXPECT_EQ(desiredOrientedDisplayRect,
2883 display.getCurrentDisplayState().orientedDisplaySpaceRect);
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002884}
2885
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002886TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackRectChanged) {
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002887 using Case = SimplePrimaryDisplayCase;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002888 const Rect initialLayerStackRect = {0, 0, 0, 0};
2889 const Rect desiredLayerStackRect = {5, 6, 7, 8};
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002890
2891 // --------------------------------------------------------------------
2892 // Preconditions
2893
2894 // A display is set up
2895 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2896 display.inject();
2897
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002898 // The current display state does not have a layerStackSpaceRect
2899 display.mutableCurrentDisplayState().layerStackSpaceRect = initialLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002900
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002901 // The incoming request sets a layerStackSpaceRect
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002902 DisplayState state;
2903 state.what = DisplayState::eDisplayProjectionChanged;
2904 state.token = display.token();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002905 state.layerStackSpaceRect = desiredLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002906
2907 // --------------------------------------------------------------------
2908 // Invocation
2909
2910 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2911
2912 // --------------------------------------------------------------------
2913 // Postconditions
2914
2915 // The returned flags indicate a transaction is needed
2916 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2917
2918 // The current display state has the new value.
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002919 EXPECT_EQ(desiredLayerStackRect, display.getCurrentDisplayState().layerStackSpaceRect);
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002920}
2921
2922TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2923 using Case = SimplePrimaryDisplayCase;
2924 constexpr uint32_t initialWidth = 1024;
2925 constexpr uint32_t initialHeight = 768;
2926
2927 // --------------------------------------------------------------------
2928 // Preconditions
2929
2930 // A display is set up
2931 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2932 display.inject();
2933
2934 // The current display state has a size set
2935 display.mutableCurrentDisplayState().width = initialWidth;
2936 display.mutableCurrentDisplayState().height = initialHeight;
2937
2938 // The incoming request sets the same display size
2939 DisplayState state;
2940 state.what = DisplayState::eDisplaySizeChanged;
2941 state.token = display.token();
2942 state.width = initialWidth;
2943 state.height = initialHeight;
2944
2945 // --------------------------------------------------------------------
2946 // Invocation
2947
2948 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2949
2950 // --------------------------------------------------------------------
2951 // Postconditions
2952
2953 // The returned flags are empty
2954 EXPECT_EQ(0u, flags);
2955
2956 // The current display state is unchanged
2957 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2958 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2959}
2960
2961TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2962 using Case = SimplePrimaryDisplayCase;
2963 constexpr uint32_t initialWidth = 0;
2964 constexpr uint32_t desiredWidth = 1024;
2965
2966 // --------------------------------------------------------------------
2967 // Preconditions
2968
2969 // A display is set up
2970 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2971 display.inject();
2972
2973 // The display does not yet have a width
2974 display.mutableCurrentDisplayState().width = initialWidth;
2975
2976 // The incoming request sets a display width
2977 DisplayState state;
2978 state.what = DisplayState::eDisplaySizeChanged;
2979 state.token = display.token();
2980 state.width = desiredWidth;
2981
2982 // --------------------------------------------------------------------
2983 // Invocation
2984
2985 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2986
2987 // --------------------------------------------------------------------
2988 // Postconditions
2989
2990 // The returned flags indicate a transaction is needed
2991 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2992
2993 // The current display state has the new value.
2994 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
2995}
2996
2997TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
2998 using Case = SimplePrimaryDisplayCase;
2999 constexpr uint32_t initialHeight = 0;
3000 constexpr uint32_t desiredHeight = 768;
3001
3002 // --------------------------------------------------------------------
3003 // Preconditions
3004
3005 // A display is set up
3006 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3007 display.inject();
3008
3009 // The display does not yet have a height
3010 display.mutableCurrentDisplayState().height = initialHeight;
3011
3012 // The incoming request sets a display height
3013 DisplayState state;
3014 state.what = DisplayState::eDisplaySizeChanged;
3015 state.token = display.token();
3016 state.height = desiredHeight;
3017
3018 // --------------------------------------------------------------------
3019 // Invocation
3020
3021 uint32_t flags = mFlinger.setDisplayStateLocked(state);
3022
3023 // --------------------------------------------------------------------
3024 // Postconditions
3025
3026 // The returned flags indicate a transaction is needed
3027 EXPECT_EQ(eDisplayTransactionNeeded, flags);
3028
3029 // The current display state has the new value.
3030 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
3031}
3032
Lloyd Pique86016da2018-03-01 16:09:38 -08003033/* ------------------------------------------------------------------------
3034 * SurfaceFlinger::onInitializeDisplays
3035 */
3036
3037TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
3038 using Case = SimplePrimaryDisplayCase;
3039
3040 // --------------------------------------------------------------------
3041 // Preconditions
3042
3043 // A primary display is set up
3044 Case::Display::injectHwcDisplay(this);
3045 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
3046 primaryDisplay.inject();
3047
3048 // --------------------------------------------------------------------
3049 // Call Expectations
3050
3051 // We expect the surface interceptor to possibly be used, but we treat it as
3052 // disabled since it is called as a side effect rather than directly by this
3053 // function.
3054 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
3055
3056 // We expect a call to get the active display config.
3057 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
3058
3059 // We expect invalidate() to be invoked once to trigger display transaction
3060 // processing.
3061 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
3062
Ady Abraham8cb21882020-08-26 18:22:05 -07003063 EXPECT_CALL(*mVSyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003064
Lloyd Pique86016da2018-03-01 16:09:38 -08003065 // --------------------------------------------------------------------
3066 // Invocation
3067
3068 mFlinger.onInitializeDisplays();
3069
3070 // --------------------------------------------------------------------
3071 // Postconditions
3072
3073 // The primary display should have a current state
3074 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
3075 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
3076 // The layer stack state should be set to zero
3077 EXPECT_EQ(0u, primaryDisplayState.layerStack);
3078 // The orientation state should be set to zero
Dominik Laskowski718f9602019-11-09 20:01:35 -08003079 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
Lloyd Pique86016da2018-03-01 16:09:38 -08003080
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003081 // The orientedDisplaySpaceRect state should be set to INVALID
3082 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.orientedDisplaySpaceRect);
Lloyd Pique86016da2018-03-01 16:09:38 -08003083
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003084 // The layerStackSpaceRect state should be set to INVALID
3085 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.layerStackSpaceRect);
Lloyd Pique86016da2018-03-01 16:09:38 -08003086
3087 // The width and height should both be zero
3088 EXPECT_EQ(0u, primaryDisplayState.width);
3089 EXPECT_EQ(0u, primaryDisplayState.height);
3090
Peiyong Lin65248e02020-04-18 21:15:07 -07003091 // The display should be set to PowerMode::ON
Lloyd Pique86016da2018-03-01 16:09:38 -08003092 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
3093 auto displayDevice = primaryDisplay.mutableDisplayDevice();
Peiyong Lin65248e02020-04-18 21:15:07 -07003094 EXPECT_EQ(PowerMode::ON, displayDevice->getPowerMode());
Lloyd Pique86016da2018-03-01 16:09:38 -08003095
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003096 // The display refresh period should be set in the orientedDisplaySpaceRect tracker.
Lloyd Pique86016da2018-03-01 16:09:38 -08003097 FrameStats stats;
3098 mFlinger.getAnimFrameTracker().getStats(&stats);
3099 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
3100
3101 // The display transaction needed flag should be set.
3102 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
3103
3104 // The compositor timing should be set to default values
3105 const auto& compositorTiming = mFlinger.getCompositorTiming();
3106 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
3107 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
3108 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
3109}
3110
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003111/* ------------------------------------------------------------------------
3112 * SurfaceFlinger::setPowerModeInternal
3113 */
3114
3115// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07003116template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003117struct DozeIsSupportedVariant {
3118 static constexpr bool DOZE_SUPPORTED = true;
3119 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3120 IComposerClient::PowerMode::DOZE;
3121 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3122 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07003123
3124 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3125 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003126 .WillOnce(DoAll(SetArgPointee<1>(
3127 std::vector<DisplayCapability>({DisplayCapability::DOZE})),
Peiyong Lined531a32018-10-26 18:27:56 -07003128 Return(Error::NONE)));
3129 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003130};
3131
Peiyong Lined531a32018-10-26 18:27:56 -07003132template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003133// Used when we simulate a display that does not support doze.
3134struct DozeNotSupportedVariant {
3135 static constexpr bool DOZE_SUPPORTED = false;
3136 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3137 IComposerClient::PowerMode::ON;
3138 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3139 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07003140
3141 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3142 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003143 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Peiyong Lined531a32018-10-26 18:27:56 -07003144 Return(Error::NONE)));
3145 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003146};
3147
3148struct EventThreadBaseSupportedVariant {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003149 static void setupVsyncAndEventThreadNoCallExpectations(DisplayTransactionTest* test) {
3150 // The callback should not be notified to toggle VSYNC.
3151 EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(_)).Times(0);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003152
3153 // The event thread should not be notified.
3154 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
3155 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
3156 }
3157};
3158
3159struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
3160 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3161 // These calls are only expected for the primary display.
3162
3163 // Instead expect no calls.
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003164 setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003165 }
3166
3167 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3168 // These calls are only expected for the primary display.
3169
3170 // Instead expect no calls.
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003171 setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003172 }
3173};
3174
3175struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
3176 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003177 // The callback should be notified to enable VSYNC.
3178 EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(true)).Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003179
3180 // The event thread should be notified that the screen was acquired.
3181 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
3182 }
3183
3184 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003185 // The callback should be notified to disable VSYNC.
3186 EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(false)).Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003187
3188 // The event thread should not be notified that the screen was released.
3189 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
3190 }
3191};
3192
Lloyd Pique41be5d22018-06-21 13:11:48 -07003193struct DispSyncIsSupportedVariant {
Ady Abraham8cb21882020-08-26 18:22:05 -07003194 static void setupResetModelCallExpectations(DisplayTransactionTest* test) {
3195 EXPECT_CALL(*test->mVsyncController, startPeriodTransition(DEFAULT_REFRESH_RATE)).Times(1);
3196 EXPECT_CALL(*test->mVSyncTracker, resetModel()).Times(1);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003197 }
Lloyd Pique41be5d22018-06-21 13:11:48 -07003198};
3199
3200struct DispSyncNotSupportedVariant {
Ady Abraham8cb21882020-08-26 18:22:05 -07003201 static void setupResetModelCallExpectations(DisplayTransactionTest* /* test */) {}
Lloyd Pique41be5d22018-06-21 13:11:48 -07003202};
3203
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003204// --------------------------------------------------------------------
3205// Note:
3206//
3207// There are a large number of transitions we could test, however we only test a
3208// selected subset which provides complete test coverage of the implementation.
3209// --------------------------------------------------------------------
3210
Peiyong Lin65248e02020-04-18 21:15:07 -07003211template <PowerMode initialPowerMode, PowerMode targetPowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003212struct TransitionVariantCommon {
3213 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
3214 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
3215
3216 static void verifyPostconditions(DisplayTransactionTest*) {}
3217};
3218
Peiyong Lin65248e02020-04-18 21:15:07 -07003219struct TransitionOffToOnVariant : public TransitionVariantCommon<PowerMode::OFF, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003220 template <typename Case>
3221 static void setupCallExpectations(DisplayTransactionTest* test) {
3222 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3223 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Ady Abraham8cb21882020-08-26 18:22:05 -07003224 Case::DispSync::setupResetModelCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003225 Case::setupRepaintEverythingCallExpectations(test);
3226 }
3227
3228 static void verifyPostconditions(DisplayTransactionTest* test) {
3229 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3230 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3231 }
3232};
3233
3234struct TransitionOffToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003235 : public TransitionVariantCommon<PowerMode::OFF, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003236 template <typename Case>
3237 static void setupCallExpectations(DisplayTransactionTest* test) {
3238 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003239 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003240 Case::setupRepaintEverythingCallExpectations(test);
3241 }
3242
3243 static void verifyPostconditions(DisplayTransactionTest* test) {
3244 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3245 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3246 }
3247};
3248
Peiyong Lin65248e02020-04-18 21:15:07 -07003249struct TransitionOnToOffVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003250 template <typename Case>
3251 static void setupCallExpectations(DisplayTransactionTest* test) {
3252 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
3253 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3254 }
3255
3256 static void verifyPostconditions(DisplayTransactionTest* test) {
3257 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3258 }
3259};
3260
3261struct TransitionDozeSuspendToOffVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003262 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003263 template <typename Case>
3264 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003265 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003266 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3267 }
3268
3269 static void verifyPostconditions(DisplayTransactionTest* test) {
3270 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3271 }
3272};
3273
Peiyong Lin65248e02020-04-18 21:15:07 -07003274struct TransitionOnToDozeVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003275 template <typename Case>
3276 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003277 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003278 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3279 }
3280};
3281
3282struct TransitionDozeSuspendToDozeVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003283 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003284 template <typename Case>
3285 static void setupCallExpectations(DisplayTransactionTest* test) {
3286 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Ady Abraham8cb21882020-08-26 18:22:05 -07003287 Case::DispSync::setupResetModelCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003288 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3289 }
3290};
3291
Peiyong Lin65248e02020-04-18 21:15:07 -07003292struct TransitionDozeToOnVariant : public TransitionVariantCommon<PowerMode::DOZE, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003293 template <typename Case>
3294 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003295 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003296 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3297 }
3298};
3299
3300struct TransitionDozeSuspendToOnVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003301 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003302 template <typename Case>
3303 static void setupCallExpectations(DisplayTransactionTest* test) {
3304 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Ady Abraham8cb21882020-08-26 18:22:05 -07003305 Case::DispSync::setupResetModelCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003306 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3307 }
3308};
3309
3310struct TransitionOnToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003311 : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003312 template <typename Case>
3313 static void setupCallExpectations(DisplayTransactionTest* test) {
3314 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
3315 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3316 }
3317};
3318
3319struct TransitionOnToUnknownVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003320 : public TransitionVariantCommon<PowerMode::ON, static_cast<PowerMode>(POWER_MODE_LEET)> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003321 template <typename Case>
3322 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003323 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003324 Case::setupNoComposerPowerModeCallExpectations(test);
3325 }
3326};
3327
3328// --------------------------------------------------------------------
3329// Note:
3330//
3331// Rather than testing the cartesian product of of
3332// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3333// display type, and the other for another display type.
3334// --------------------------------------------------------------------
3335
3336template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003337 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003338struct DisplayPowerCase {
3339 using Display = DisplayVariant;
3340 using Doze = DozeVariant;
3341 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003342 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003343 using Transition = TransitionVariant;
3344
Peiyong Lin65248e02020-04-18 21:15:07 -07003345 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003346 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003347 auto display = Display::makeFakeExistingDisplayInjector(test);
3348 display.inject();
3349 display.mutableDisplayDevice()->setPowerMode(mode);
3350 return display;
3351 }
3352
3353 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003354 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003355 }
3356
3357 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3358 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3359 }
3360
Peiyong Lin65248e02020-04-18 21:15:07 -07003361 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test,
3362 PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003363 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
Peiyong Lin65248e02020-04-18 21:15:07 -07003364 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, static_cast<int32_t>(mode)))
3365 .Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003366 }
3367
Peiyong Lin65248e02020-04-18 21:15:07 -07003368 static void setupComposerCallExpectations(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003369 // Any calls to get the active config will return a default value.
3370 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3371 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3372 Return(Error::NONE)));
3373
3374 // Any calls to get whether the display supports dozing will return the value set by the
3375 // policy variant.
3376 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3377 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3378
3379 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3380 }
3381
3382 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3383 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3384 }
3385};
3386
3387// A sample configuration for the primary display.
3388// In addition to having event thread support, we emulate doze support.
3389template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003390using PrimaryDisplayPowerCase =
3391 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3392 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3393 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003394
3395// A sample configuration for the external display.
3396// In addition to not having event thread support, we emulate not having doze
3397// support.
3398template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003399using ExternalDisplayPowerCase =
3400 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3401 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3402 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003403
3404class SetPowerModeInternalTest : public DisplayTransactionTest {
3405public:
3406 template <typename Case>
3407 void transitionDisplayCommon();
3408};
3409
Peiyong Lin65248e02020-04-18 21:15:07 -07003410template <PowerMode PowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003411struct PowerModeInitialVSyncEnabled : public std::false_type {};
3412
3413template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003414struct PowerModeInitialVSyncEnabled<PowerMode::ON> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003415
3416template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003417struct PowerModeInitialVSyncEnabled<PowerMode::DOZE> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003418
3419template <typename Case>
3420void SetPowerModeInternalTest::transitionDisplayCommon() {
3421 // --------------------------------------------------------------------
3422 // Preconditions
3423
Peiyong Lined531a32018-10-26 18:27:56 -07003424 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003425 auto display =
3426 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3427 Case::setInitialPrimaryHWVsyncEnabled(this,
3428 PowerModeInitialVSyncEnabled<
3429 Case::Transition::INITIAL_POWER_MODE>::value);
3430
3431 // --------------------------------------------------------------------
3432 // Call Expectations
3433
3434 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3435 Case::Transition::template setupCallExpectations<Case>(this);
3436
3437 // --------------------------------------------------------------------
3438 // Invocation
3439
3440 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3441 Case::Transition::TARGET_POWER_MODE);
3442
3443 // --------------------------------------------------------------------
3444 // Postconditions
3445
3446 Case::Transition::verifyPostconditions(this);
3447}
3448
3449TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3450 using Case = SimplePrimaryDisplayCase;
3451
3452 // --------------------------------------------------------------------
3453 // Preconditions
3454
3455 // A primary display device is set up
3456 Case::Display::injectHwcDisplay(this);
3457 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3458 display.inject();
3459
Peiyong Lin65248e02020-04-18 21:15:07 -07003460 // The display is already set to PowerMode::ON
3461 display.mutableDisplayDevice()->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003462
3463 // --------------------------------------------------------------------
3464 // Invocation
3465
Peiyong Lin65248e02020-04-18 21:15:07 -07003466 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003467
3468 // --------------------------------------------------------------------
3469 // Postconditions
3470
Peiyong Lin65248e02020-04-18 21:15:07 -07003471 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003472}
3473
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003474TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003475 using Case = HwcVirtualDisplayCase;
3476
3477 // --------------------------------------------------------------------
3478 // Preconditions
3479
Dominik Laskowski075d3172018-05-24 15:50:06 -07003480 // Insert display data so that the HWC thinks it created the virtual display.
3481 const auto displayId = Case::Display::DISPLAY_ID::get();
3482 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003483 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003484
3485 // A virtual display device is set up
3486 Case::Display::injectHwcDisplay(this);
3487 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3488 display.inject();
3489
Peiyong Lin65248e02020-04-18 21:15:07 -07003490 // The display is set to PowerMode::ON
3491 getDisplayDevice(display.token())->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003492
3493 // --------------------------------------------------------------------
3494 // Invocation
3495
Peiyong Lin65248e02020-04-18 21:15:07 -07003496 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003497
3498 // --------------------------------------------------------------------
3499 // Postconditions
3500
Peiyong Lin65248e02020-04-18 21:15:07 -07003501 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003502}
3503
3504TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3505 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3506}
3507
3508TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3509 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3510}
3511
3512TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3513 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3514}
3515
3516TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3517 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3518}
3519
3520TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3521 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3522}
3523
3524TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3525 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3526}
3527
3528TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3529 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3530}
3531
3532TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3533 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3534}
3535
3536TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3537 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3538}
3539
3540TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3541 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3542}
3543
3544TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3545 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3546}
3547
3548TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3549 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3550}
3551
3552TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3553 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3554}
3555
3556TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3557 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3558}
3559
3560TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3561 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3562}
3563
3564TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3565 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3566}
3567
3568TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3569 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3570}
3571
3572TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3573 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3574}
3575
3576TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3577 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3578}
3579
3580TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3581 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3582}
3583
Lloyd Piquef58625d2017-12-19 13:22:33 -08003584} // namespace
3585} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08003586
3587// TODO(b/129481165): remove the #pragma below and fix conversion issues
3588#pragma clang diagnostic pop // ignored "-Wconversion"