blob: 5864d025a794cbc55037c42eda0d723d2e0f59b4 [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>
chaviwd4a61642020-09-01 14:53:46 -070027#include <binder/IPCThreadState.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070028#include <compositionengine/Display.h>
29#include <compositionengine/DisplayColorProfile.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070030#include <compositionengine/impl/Display.h>
Lloyd Pique33050472019-12-19 17:12:44 -080031#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070032#include <compositionengine/mock/Display.h>
33#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070034#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070035#include <compositionengine/mock/RenderSurface.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080036#include <gmock/gmock.h>
37#include <gtest/gtest.h>
Lloyd Pique1ebe0902019-10-04 14:47:13 -070038#include <gui/mock/GraphicBufferConsumer.h>
39#include <gui/mock/GraphicBufferProducer.h>
Lloyd Piquef58625d2017-12-19 13:22:33 -080040#include <log/log.h>
chaviwd4a61642020-09-01 14:53:46 -070041#include <private/android_filesystem_config.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070042#include <renderengine/mock/RenderEngine.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070043#include <ui/DebugUtils.h>
Dominik Laskowski075d3172018-05-24 15:50:06 -070044
45#include "DisplayIdentificationTest.h"
Ana Krulecafb45842019-02-13 13:33:03 -080046#include "TestableScheduler.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080047#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080048#include "mock/DisplayHardware/MockComposer.h"
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070049#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080050#include "mock/MockEventThread.h"
51#include "mock/MockMessageQueue.h"
52#include "mock/MockNativeWindowSurface.h"
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070053#include "mock/MockSchedulerCallback.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080054#include "mock/MockSurfaceInterceptor.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070055#include "mock/MockVsyncController.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080056#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080057
58namespace android {
59namespace {
60
Peiyong Line9d809e2020-04-14 13:10:48 -070061namespace hal = android::hardware::graphics::composer::hal;
62
Lais Andrade3a6e47d2020-04-02 11:20:16 +010063using android::hardware::power::Boost;
64
Lloyd Piquee39cad22017-12-20 17:01:29 -080065using testing::_;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070066using testing::AnyNumber;
Lloyd Piquee39cad22017-12-20 17:01:29 -080067using testing::DoAll;
68using testing::Mock;
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -080069using testing::ResultOf;
Lloyd Piquee39cad22017-12-20 17:01:29 -080070using testing::Return;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070071using testing::ReturnRefOfCopy;
Lloyd Piquee39cad22017-12-20 17:01:29 -080072using testing::SetArgPointee;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070073using testing::StrictMock;
Lloyd Piquee39cad22017-12-20 17:01:29 -080074
Peiyong Line9d809e2020-04-14 13:10:48 -070075using hal::ColorMode;
76using hal::Connection;
77using hal::DisplayCapability;
78using hal::DisplayType;
79using hal::Error;
80using hal::Hdr;
81using hal::HWDisplayId;
82using hal::IComposer;
83using hal::IComposerClient;
84using hal::PerFrameMetadataKey;
85using hal::PowerMode;
86using hal::RenderIntent;
Lloyd Piquee39cad22017-12-20 17:01:29 -080087
Lloyd Piquec11e0d32018-01-22 18:44:59 -080088using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
89using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080090using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080091using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Piquebc792092018-01-17 11:52:30 -080092
Ady Abraham2492a022020-07-24 11:09:55 -070093constexpr int32_t DEFAULT_REFRESH_RATE = 16'666'667;
Lloyd Piquee39cad22017-12-20 17:01:29 -080094constexpr int32_t DEFAULT_DPI = 320;
Lloyd Piquec11e0d32018-01-22 18:44:59 -080095constexpr int DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT = HAL_PIXEL_FORMAT_RGB_565;
Lloyd Piquee39cad22017-12-20 17:01:29 -080096
Peiyong Lin65248e02020-04-18 21:15:07 -070097constexpr int POWER_MODE_LEET = 1337; // An out of range power mode value
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -080098
Lloyd Piquec11e0d32018-01-22 18:44:59 -080099/* ------------------------------------------------------------------------
100 * Boolean avoidance
101 *
102 * To make calls and template instantiations more readable, we define some
103 * local enums along with an implicit bool conversion.
104 */
105
106#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };
107
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800108BOOL_SUBSTITUTE(Async);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700109BOOL_SUBSTITUTE(Critical);
110BOOL_SUBSTITUTE(Primary);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800111BOOL_SUBSTITUTE(Secure);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700112BOOL_SUBSTITUTE(Virtual);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800113
114/* ------------------------------------------------------------------------
115 *
116 */
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800117
Lloyd Piquef58625d2017-12-19 13:22:33 -0800118class DisplayTransactionTest : public testing::Test {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800119public:
Lloyd Piquef58625d2017-12-19 13:22:33 -0800120 DisplayTransactionTest();
121 ~DisplayTransactionTest() override;
122
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800123 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800124 // Mock/Fake injection
Lloyd Piquef58625d2017-12-19 13:22:33 -0800125
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700126 void injectMockScheduler();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800127 void injectMockComposer(int virtualDisplayCount);
128 void injectFakeBufferQueueFactory();
129 void injectFakeNativeWindowSurfaceFactory();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700130 sp<DisplayDevice> injectDefaultInternalDisplay(std::function<void(FakeDisplayDeviceInjector&)>);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800131
132 // --------------------------------------------------------------------
133 // Postcondition helpers
134
Peiyong Line9d809e2020-04-14 13:10:48 -0700135 bool hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800136 bool hasTransactionFlagSet(int flag);
137 bool hasDisplayDevice(sp<IBinder> displayToken);
138 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
139 bool hasCurrentDisplayState(sp<IBinder> displayToken);
140 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
141 bool hasDrawingDisplayState(sp<IBinder> displayToken);
142 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
143
144 // --------------------------------------------------------------------
145 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800146
Lloyd Piquef58625d2017-12-19 13:22:33 -0800147 TestableSurfaceFlinger mFlinger;
Alec Mouriba013fa2018-10-16 12:43:11 -0700148 sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800149 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700150 Hwc2::mock::PowerAdvisor mPowerAdvisor;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800151
152 // These mocks are created by the test, but are destroyed by SurfaceFlinger
153 // by virtue of being stored into a std::unique_ptr. However we still need
154 // to keep a reference to them for use in setting up call expectations.
Peiyong Lin833074a2018-08-28 11:53:54 -0700155 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800156 Hwc2::mock::Composer* mComposer = nullptr;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800157 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
Pablo Gamito5cfc6e52020-09-10 11:18:03 +0000158 sp<mock::SurfaceInterceptor> mSurfaceInterceptor = new mock::SurfaceInterceptor;
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700159
Ady Abraham8cb21882020-08-26 18:22:05 -0700160 mock::VsyncController* mVsyncController = new mock::VsyncController;
161 mock::VSyncTracker* mVSyncTracker = new mock::VSyncTracker;
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700162 mock::SchedulerCallback mSchedulerCallback;
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700163 mock::EventThread* mEventThread = new mock::EventThread;
164 mock::EventThread* mSFEventThread = new mock::EventThread;
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800165
166 // These mocks are created only when expected to be created via a factory.
167 sp<mock::GraphicBufferConsumer> mConsumer;
168 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique22098362018-09-13 11:46:49 -0700169 surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800170};
171
172DisplayTransactionTest::DisplayTransactionTest() {
173 const ::testing::TestInfo* const test_info =
174 ::testing::UnitTest::GetInstance()->current_test_info();
175 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800176
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800177 // Default to no wide color display support configured
178 mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700179 mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800180 mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800181
182 // Default to using HWC virtual displays
183 mFlinger.mutableUseHwcVirtualDisplays() = true;
184
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800185 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
186 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
187 });
188
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800189 mFlinger.setCreateNativeWindowSurface([](auto) {
190 ADD_FAILURE() << "Unexpected request to create a native window surface.";
191 return nullptr;
192 });
193
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700194 injectMockScheduler();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800195 mFlinger.mutableEventQueue().reset(mMessageQueue);
Peiyong Lin833074a2018-08-28 11:53:54 -0700196 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Pablo Gamito5cfc6e52020-09-10 11:18:03 +0000197 mFlinger.mutableInterceptor() = mSurfaceInterceptor;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800198
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800199 injectMockComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800200}
201
202DisplayTransactionTest::~DisplayTransactionTest() {
203 const ::testing::TestInfo* const test_info =
204 ::testing::UnitTest::GetInstance()->current_test_info();
205 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
206}
207
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700208void DisplayTransactionTest::injectMockScheduler() {
Ana Krulecafb45842019-02-13 13:33:03 -0800209 EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700210 EXPECT_CALL(*mEventThread, createEventConnection(_, _))
211 .WillOnce(Return(new EventThreadConnection(mEventThread, ResyncCallback(),
212 ISurfaceComposer::eConfigChangedSuppress)));
213
Ana Krulecafb45842019-02-13 13:33:03 -0800214 EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700215 EXPECT_CALL(*mSFEventThread, createEventConnection(_, _))
216 .WillOnce(Return(new EventThreadConnection(mSFEventThread, ResyncCallback(),
217 ISurfaceComposer::eConfigChangedSuppress)));
Ana Krulecafb45842019-02-13 13:33:03 -0800218
Ady Abraham8cb21882020-08-26 18:22:05 -0700219 mFlinger.setupScheduler(std::unique_ptr<scheduler::VsyncController>(mVsyncController),
220 std::unique_ptr<scheduler::VSyncTracker>(mVSyncTracker),
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700221 std::unique_ptr<EventThread>(mEventThread),
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700222 std::unique_ptr<EventThread>(mSFEventThread), &mSchedulerCallback);
Ana Krulecafb45842019-02-13 13:33:03 -0800223}
224
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800225void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) {
226 mComposer = new Hwc2::mock::Composer();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800227 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
228 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800229
Lloyd Piquee39cad22017-12-20 17:01:29 -0800230 Mock::VerifyAndClear(mComposer);
231}
232
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800233void DisplayTransactionTest::injectFakeBufferQueueFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800234 // This setup is only expected once per test.
235 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
236
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800237 mConsumer = new mock::GraphicBufferConsumer();
238 mProducer = new mock::GraphicBufferProducer();
239
240 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
241 *outProducer = mProducer;
242 *outConsumer = mConsumer;
243 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800244}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800245
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800246void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800247 // This setup is only expected once per test.
248 ASSERT_TRUE(mNativeWindowSurface == nullptr);
249
Lloyd Pique22098362018-09-13 11:46:49 -0700250 mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800251
Lloyd Pique22098362018-09-13 11:46:49 -0700252 mFlinger.setCreateNativeWindowSurface([this](auto) {
253 return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
254 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800255}
256
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700257sp<DisplayDevice> DisplayTransactionTest::injectDefaultInternalDisplay(
258 std::function<void(FakeDisplayDeviceInjector&)> injectExtra) {
Marin Shalamanova524a092020-07-27 21:39:55 +0200259 constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID(777);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700260 constexpr int DEFAULT_DISPLAY_WIDTH = 1080;
261 constexpr int DEFAULT_DISPLAY_HEIGHT = 1920;
Peiyong Line9d809e2020-04-14 13:10:48 -0700262 constexpr HWDisplayId DEFAULT_DISPLAY_HWC_DISPLAY_ID = 0;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700263
264 // The DisplayDevice is required to have a framebuffer (behind the
265 // ANativeWindow interface) which uses the actual hardware display
266 // size.
267 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
268 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
269 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
270 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
271 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT));
272 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT));
273 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64));
274 EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(AnyNumber());
275
276 auto compositionDisplay = compositionengine::impl::
277 createDisplay(mFlinger.getCompositionEngine(),
278 compositionengine::DisplayCreationArgsBuilder()
279 .setPhysical(
280 {DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal})
281 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
282 .setPowerAdvisor(&mPowerAdvisor)
283 .build());
284
285 auto injector =
286 FakeDisplayDeviceInjector(mFlinger, compositionDisplay, DisplayConnectionType::Internal,
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100287 DEFAULT_DISPLAY_HWC_DISPLAY_ID, true /* isPrimary */);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700288
289 injector.setNativeWindow(mNativeWindow);
290 if (injectExtra) {
291 injectExtra(injector);
292 }
293
294 auto displayDevice = injector.inject();
295
296 Mock::VerifyAndClear(mNativeWindow.get());
297
298 return displayDevice;
299}
300
Peiyong Line9d809e2020-04-14 13:10:48 -0700301bool DisplayTransactionTest::hasPhysicalHwcDisplay(HWDisplayId hwcDisplayId) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700302 return mFlinger.mutableHwcPhysicalDisplayIdMap().count(hwcDisplayId) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800303}
304
305bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
306 return mFlinger.mutableTransactionFlags() & flag;
307}
308
309bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700310 return mFlinger.mutableDisplays().count(displayToken) == 1;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800311}
312
313sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
Dominik Laskowski9fae1022018-05-29 13:17:40 -0700314 return mFlinger.mutableDisplays()[displayToken];
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800315}
316
317bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
318 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
319}
320
321const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
322 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
323}
324
325bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
326 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
327}
328
329const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
330 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
331}
332
333/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800334 *
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800335 */
336
Dominik Laskowski075d3172018-05-24 15:50:06 -0700337template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200338struct PhysicalDisplayIdType {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700339
Marin Shalamanova524a092020-07-27 21:39:55 +0200340template <uint64_t displayId>
341using VirtualDisplayIdType = std::integral_constant<uint64_t, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700342
343struct NoDisplayId {};
344
345template <typename>
346struct IsPhysicalDisplayId : std::bool_constant<false> {};
347
348template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200349struct IsPhysicalDisplayId<PhysicalDisplayIdType<PhysicalDisplay>> : std::bool_constant<true> {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700350
351template <typename>
352struct DisplayIdGetter;
353
354template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200355struct DisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> {
356 static std::optional<PhysicalDisplayId> get() {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700357 if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
Marin Shalamanova524a092020-07-27 21:39:55 +0200358 return PhysicalDisplayId::fromPort(static_cast<bool>(PhysicalDisplay::PRIMARY)
359 ? LEGACY_DISPLAY_TYPE_PRIMARY
360 : LEGACY_DISPLAY_TYPE_EXTERNAL);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700361 }
362
363 const auto info =
364 parseDisplayIdentificationData(PhysicalDisplay::PORT,
365 PhysicalDisplay::GET_IDENTIFICATION_DATA());
366 return info ? std::make_optional(info->id) : std::nullopt;
367 }
368};
369
Marin Shalamanova524a092020-07-27 21:39:55 +0200370template <uint64_t displayId>
371struct DisplayIdGetter<VirtualDisplayIdType<displayId>> {
372 // TODO(b/160679868) Use VirtualDisplayId
373 static std::optional<PhysicalDisplayId> get() { return PhysicalDisplayId{displayId}; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700374};
375
376template <>
377struct DisplayIdGetter<NoDisplayId> {
378 static std::optional<DisplayId> get() { return {}; }
379};
380
Dominik Laskowski55c85402020-01-21 16:25:47 -0800381template <typename>
382struct DisplayConnectionTypeGetter {
383 static constexpr std::optional<DisplayConnectionType> value;
384};
385
386template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200387struct DisplayConnectionTypeGetter<PhysicalDisplayIdType<PhysicalDisplay>> {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800388 static constexpr std::optional<DisplayConnectionType> value = PhysicalDisplay::CONNECTION_TYPE;
389};
390
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100391template <typename>
392struct HwcDisplayIdGetter {
Peiyong Line9d809e2020-04-14 13:10:48 -0700393 static constexpr std::optional<HWDisplayId> value;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100394};
395
Peiyong Line9d809e2020-04-14 13:10:48 -0700396constexpr HWDisplayId HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID = 1010;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100397
Marin Shalamanova524a092020-07-27 21:39:55 +0200398template <uint64_t displayId>
399struct HwcDisplayIdGetter<VirtualDisplayIdType<displayId>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700400 static constexpr std::optional<HWDisplayId> value = HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100401};
402
403template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200404struct HwcDisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700405 static constexpr std::optional<HWDisplayId> value = PhysicalDisplay::HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100406};
407
Dominik Laskowski075d3172018-05-24 15:50:06 -0700408// DisplayIdType can be:
Marin Shalamanova524a092020-07-27 21:39:55 +0200409// 1) PhysicalDisplayIdType<...> for generated ID of physical display backed by HWC.
410// 2) VirtualDisplayIdType<...> for hard-coded ID of virtual display backed by HWC.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700411// 3) NoDisplayId for virtual display without HWC backing.
412template <typename DisplayIdType, int width, int height, Critical critical, Async async,
413 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800414struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700415 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800416 using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100417 using HWC_DISPLAY_ID_OPT = HwcDisplayIdGetter<DisplayIdType>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700418
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800419 // The display width and height
420 static constexpr int WIDTH = width;
421 static constexpr int HEIGHT = height;
422
423 static constexpr int GRALLOC_USAGE = grallocUsage;
424
Dominik Laskowski075d3172018-05-24 15:50:06 -0700425 // Whether the display is virtual or physical
426 static constexpr Virtual VIRTUAL =
427 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800428
429 // When creating native window surfaces for the framebuffer, whether those should be critical
430 static constexpr Critical CRITICAL = critical;
431
432 // When creating native window surfaces for the framebuffer, whether those should be async
433 static constexpr Async ASYNC = async;
434
435 // Whether the display should be treated as secure
436 static constexpr Secure SECURE = secure;
437
Dominik Laskowski075d3172018-05-24 15:50:06 -0700438 // Whether the display is primary
439 static constexpr Primary PRIMARY = primary;
440
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800441 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700442 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder();
443 if (auto displayId = DISPLAY_ID::get()) {
444 ceDisplayArgs.setPhysical({*displayId, DisplayConnectionType::Internal});
445 } else {
446 ceDisplayArgs.setUseHwcVirtualDisplays(false);
447 }
448 ceDisplayArgs.setPixels({WIDTH, HEIGHT}).setPowerAdvisor(&test->mPowerAdvisor).build();
449
450 auto compositionDisplay =
451 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
452 ceDisplayArgs.build());
453
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100454 auto injector = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
455 CONNECTION_TYPE::value, HWC_DISPLAY_ID_OPT::value,
456 static_cast<bool>(PRIMARY));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700457
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800458 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700459 injector.setNativeWindow(test->mNativeWindow);
460
461 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800462 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700463 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
464 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
465 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
466 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800467 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
468 .WillRepeatedly(Return(0));
469 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
470 .WillRepeatedly(Return(0));
471 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
472 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700473 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
474 .WillRepeatedly(Return(0));
475
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800476 return injector;
477 }
478
479 // Called by tests to set up any native window creation call expectations.
480 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
481 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
482 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800483
Alec Mouriba013fa2018-10-16 12:43:11 -0700484 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
485 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
486 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
487 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800488 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
489 .WillRepeatedly(Return(0));
490 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
491 .WillRepeatedly(Return(0));
492 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
493 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700494 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
495 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800496 }
497
498 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
499 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
500 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
501 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
502 .WillRepeatedly(Return(NO_ERROR));
503 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
504 .WillRepeatedly(Return(NO_ERROR));
505 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
506 .WillRepeatedly(Return(NO_ERROR));
507 }
508
509 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
510 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
511 }
512};
513
Peiyong Line9d809e2020-04-14 13:10:48 -0700514template <HWDisplayId hwcDisplayId, DisplayType hwcDisplayType, typename DisplayVariant,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700515 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800516struct HwcDisplayVariant {
517 // The display id supplied by the HWC
Peiyong Line9d809e2020-04-14 13:10:48 -0700518 static constexpr HWDisplayId HWC_DISPLAY_ID = hwcDisplayId;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800519
520 // The HWC display type
Peiyong Line9d809e2020-04-14 13:10:48 -0700521 static constexpr DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800522
523 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700524 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin65248e02020-04-18 21:15:07 -0700525 static constexpr PowerMode INIT_POWER_MODE = PowerMode::ON;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800526
Peiyong Line9d809e2020-04-14 13:10:48 -0700527 static void injectPendingHotplugEvent(DisplayTransactionTest* test, Connection connection) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800528 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
529 HotplugEvent{HWC_DISPLAY_ID, connection});
530 }
531
532 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800533 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700534 const auto displayId = DisplayVariant::DISPLAY_ID::get();
535 ASSERT_TRUE(displayId);
536 FakeHwcDisplayInjector(*displayId, HWC_DISPLAY_TYPE,
537 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800538 .setHwcDisplayId(HWC_DISPLAY_ID)
539 .setWidth(DisplayVariant::WIDTH)
540 .setHeight(DisplayVariant::HEIGHT)
541 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700542 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800543 .inject(&test->mFlinger, test->mComposer);
544 }
545
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800546 // Called by tests to inject a HWC display setup
547 static void injectHwcDisplay(DisplayTransactionTest* test) {
548 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700549 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800550 Return(Error::NONE)));
Peiyong Lin65248e02020-04-18 21:15:07 -0700551 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY_ID, INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700552 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800553 injectHwcDisplayWithNoDefaultCapabilities(test);
554 }
555
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700556 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
557 DisplayTransactionTest* test) {
558 const ::testing::TestInfo* const test_info =
559 ::testing::UnitTest::GetInstance()->current_test_info();
560
561 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
562 .setPhysical({*DisplayVariant::DISPLAY_ID::get(),
563 PhysicalDisplay::CONNECTION_TYPE})
564 .setPixels({DisplayVariant::WIDTH, DisplayVariant::HEIGHT})
565 .setIsSecure(static_cast<bool>(DisplayVariant::SECURE))
566 .setPowerAdvisor(&test->mPowerAdvisor)
567 .setName(std::string("Injected display for ") +
568 test_info->test_case_name() + "." + test_info->name())
569 .build();
570
571 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
572 ceDisplayArgs);
573 }
574
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800575 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800576 constexpr auto CONNECTION_TYPE =
577 PhysicalDisplay::CONNECTION_TYPE == DisplayConnectionType::Internal
578 ? IComposerClient::DisplayConnectionType::INTERNAL
579 : IComposerClient::DisplayConnectionType::EXTERNAL;
580
581 EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700582 .WillOnce(DoAll(SetArgPointee<1>(CONNECTION_TYPE), Return(hal::V2_4::Error::NONE)));
Dominik Laskowski55c85402020-01-21 16:25:47 -0800583
Peiyong Line9d809e2020-04-14 13:10:48 -0700584 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_))
585 .WillOnce(Return(hal::Error::NONE));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800586 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
587 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
588 Return(Error::NONE)));
589 EXPECT_CALL(*test->mComposer,
590 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
591 IComposerClient::Attribute::WIDTH, _))
592 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
593 EXPECT_CALL(*test->mComposer,
594 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
595 IComposerClient::Attribute::HEIGHT, _))
596 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
597 EXPECT_CALL(*test->mComposer,
598 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
599 IComposerClient::Attribute::VSYNC_PERIOD, _))
600 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
601 EXPECT_CALL(*test->mComposer,
602 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
603 IComposerClient::Attribute::DPI_X, _))
604 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
605 EXPECT_CALL(*test->mComposer,
606 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
607 IComposerClient::Attribute::DPI_Y, _))
608 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Ady Abraham7159f572019-10-11 11:10:18 -0700609 EXPECT_CALL(*test->mComposer,
610 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
611 IComposerClient::Attribute::CONFIG_GROUP, _))
612 .WillOnce(DoAll(SetArgPointee<3>(-1), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700613
614 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
615 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200616 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
617 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
618 Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700619 } else {
620 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200621 .WillOnce(Return(Error::UNSUPPORTED));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700622 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800623 }
624
625 // Called by tests to set up HWC call expectations
626 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
627 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700628 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800629 }
630};
631
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800632// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
633constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
634 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
635
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100636template <typename PhysicalDisplay, int width, int height, Critical critical>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800637struct PhysicalDisplayVariant
Marin Shalamanova524a092020-07-27 21:39:55 +0200638 : DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, critical,
639 Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY,
640 GRALLOC_USAGE_PHYSICAL_DISPLAY>,
Peiyong Line9d809e2020-04-14 13:10:48 -0700641 HwcDisplayVariant<PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL,
Marin Shalamanova524a092020-07-27 21:39:55 +0200642 DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700643 critical, Async::FALSE, Secure::TRUE,
644 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
645 PhysicalDisplay> {};
646
647template <bool hasIdentificationData>
648struct PrimaryDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800649 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::Internal;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700650 static constexpr Primary PRIMARY = Primary::TRUE;
651 static constexpr uint8_t PORT = 255;
Peiyong Line9d809e2020-04-14 13:10:48 -0700652 static constexpr HWDisplayId HWC_DISPLAY_ID = 1001;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700653 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
654 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
655};
656
657template <bool hasIdentificationData>
658struct ExternalDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800659 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::External;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700660 static constexpr Primary PRIMARY = Primary::FALSE;
661 static constexpr uint8_t PORT = 254;
Peiyong Line9d809e2020-04-14 13:10:48 -0700662 static constexpr HWDisplayId HWC_DISPLAY_ID = 1002;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700663 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
664 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
665};
666
667struct TertiaryDisplay {
668 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800669 static constexpr uint8_t PORT = 253;
Peiyong Line9d809e2020-04-14 13:10:48 -0700670 static constexpr HWDisplayId HWC_DISPLAY_ID = 1003;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800671 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700672};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800673
674// A primary display is a physical display that is critical
675using PrimaryDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100676 PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800677
678// An external display is physical display that is not critical.
679using ExternalDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100680 PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800681
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100682using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800683
684// A virtual display not supported by the HWC.
685constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
686
687template <int width, int height, Secure secure>
688struct NonHwcVirtualDisplayVariant
Dominik Laskowski075d3172018-05-24 15:50:06 -0700689 : DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
690 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
691 using Base = DisplayVariant<NoDisplayId, width, height, Critical::FALSE, Async::TRUE, secure,
692 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
693
694 static void injectHwcDisplay(DisplayTransactionTest*) {}
695
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700696 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
697 DisplayTransactionTest* test) {
698 const ::testing::TestInfo* const test_info =
699 ::testing::UnitTest::GetInstance()->current_test_info();
700
701 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
702 .setPixels({Base::WIDTH, Base::HEIGHT})
703 .setIsSecure(static_cast<bool>(Base::SECURE))
704 .setPowerAdvisor(&test->mPowerAdvisor)
705 .setName(std::string("Injected display for ") +
706 test_info->test_case_name() + "." + test_info->name())
707 .build();
708
709 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
710 ceDisplayArgs);
711 }
712
Dominik Laskowski075d3172018-05-24 15:50:06 -0700713 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
714 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
715 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800716
717 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
718 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
719 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
720 }
721};
722
723// A virtual display supported by the HWC.
724constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
725
726template <int width, int height, Secure secure>
727struct HwcVirtualDisplayVariant
Marin Shalamanova524a092020-07-27 21:39:55 +0200728 : DisplayVariant<VirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE,
729 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
730 HwcDisplayVariant<HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL,
731 DisplayVariant<VirtualDisplayIdType<42>, width, height, Critical::FALSE,
732 Async::TRUE, secure, Primary::FALSE,
733 GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
734 using Base = DisplayVariant<VirtualDisplayIdType<42>, width, height, Critical::FALSE,
735 Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800736 using Self = HwcVirtualDisplayVariant<width, height, secure>;
737
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700738 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
739 DisplayTransactionTest* test) {
740 const ::testing::TestInfo* const test_info =
741 ::testing::UnitTest::GetInstance()->current_test_info();
742
743 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
744 .setUseHwcVirtualDisplays(false)
745 .setPixels({Base::WIDTH, Base::HEIGHT})
746 .setIsSecure(static_cast<bool>(Base::SECURE))
747 .setPowerAdvisor(&test->mPowerAdvisor)
748 .setName(std::string("Injected display for ") +
749 test_info->test_case_name() + "." + test_info->name())
750 .build();
751
752 auto compositionDisplay =
753 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
754 ceDisplayArgs);
755 compositionDisplay->setDisplayIdForTesting(Base::DISPLAY_ID::get());
756
757 // Insert display data so that the HWC thinks it created the virtual display.
758 if (const auto displayId = Base::DISPLAY_ID::get()) {
759 test->mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
760 }
761
762 return compositionDisplay;
763 }
764
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800765 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
766 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
767 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
768 }
769
770 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
771 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
772 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
773 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
774 }
775};
776
777// For this variant, SurfaceFlinger should not configure itself with wide
778// display support, so the display should not be configured for wide-color
779// support.
780struct WideColorSupportNotConfiguredVariant {
781 static constexpr bool WIDE_COLOR_SUPPORTED = false;
782
783 static void injectConfigChange(DisplayTransactionTest* test) {
784 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700785 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800786 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800787 }
788
789 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
790 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
791 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
792 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
793 }
794};
795
796// For this variant, SurfaceFlinger should configure itself with wide display
797// support, and the display should respond with an non-empty list of supported
798// color modes. Wide-color support should be configured.
799template <typename Display>
800struct WideColorP3ColorimetricSupportedVariant {
801 static constexpr bool WIDE_COLOR_SUPPORTED = true;
802
803 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700804 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800805 test->mFlinger.mutableHasWideColorDisplay() = true;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800806 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800807 }
808
809 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800810 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
811
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800812 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
813 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
814 Return(Error::NONE)));
815 EXPECT_CALL(*test->mComposer,
816 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
817 .WillOnce(DoAll(SetArgPointee<2>(
818 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
819 Return(Error::NONE)));
820 EXPECT_CALL(*test->mComposer,
821 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
822 RenderIntent::COLORIMETRIC))
823 .WillOnce(Return(Error::NONE));
824 }
825};
826
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800827// For this variant, SurfaceFlinger should configure itself with wide display
828// support, but the display should respond with an empty list of supported color
829// modes. Wide-color support for the display should not be configured.
830template <typename Display>
831struct WideColorNotSupportedVariant {
832 static constexpr bool WIDE_COLOR_SUPPORTED = false;
833
834 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700835 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800836 test->mFlinger.mutableHasWideColorDisplay() = true;
837 }
838
839 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
840 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
841 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700842 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800843 }
844};
845
846// For this variant, the display is not a HWC display, so no HDR support should
847// be configured.
848struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800849 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800850 static constexpr bool HDR10_SUPPORTED = false;
851 static constexpr bool HDR_HLG_SUPPORTED = false;
852 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
853 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
854 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
855 }
856};
857
Valerie Haue9e843a2018-12-18 13:39:23 -0800858template <typename Display>
859struct Hdr10PlusSupportedVariant {
860 static constexpr bool HDR10_PLUS_SUPPORTED = true;
861 static constexpr bool HDR10_SUPPORTED = true;
862 static constexpr bool HDR_HLG_SUPPORTED = false;
863 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
864 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
865 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
866 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
867 Hdr::HDR10_PLUS,
868 Hdr::HDR10,
869 })),
870 Return(Error::NONE)));
871 }
872};
873
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800874// For this variant, the composer should respond with a non-empty list of HDR
875// modes containing HDR10, so HDR10 support should be configured.
876template <typename Display>
877struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800878 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800879 static constexpr bool HDR10_SUPPORTED = true;
880 static constexpr bool HDR_HLG_SUPPORTED = false;
881 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
882 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
883 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
884 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
885 Return(Error::NONE)));
886 }
887};
888
889// For this variant, the composer should respond with a non-empty list of HDR
890// modes containing HLG, so HLG support should be configured.
891template <typename Display>
892struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800893 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800894 static constexpr bool HDR10_SUPPORTED = false;
895 static constexpr bool HDR_HLG_SUPPORTED = true;
896 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
897 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
898 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
899 .WillOnce(
900 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
901 }
902};
903
904// For this variant, the composer should respond with a non-empty list of HDR
905// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
906template <typename Display>
907struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800908 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800909 static constexpr bool HDR10_SUPPORTED = false;
910 static constexpr bool HDR_HLG_SUPPORTED = false;
911 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
912 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
913 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
914 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
915 Return(Error::NONE)));
916 }
917};
918
919// For this variant, the composer should respond with am empty list of HDR
920// modes, so no HDR support should be configured.
921template <typename Display>
922struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800923 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800924 static constexpr bool HDR10_SUPPORTED = false;
925 static constexpr bool HDR_HLG_SUPPORTED = false;
926 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
927 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
928 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
929 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
930 }
931};
932
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700933struct NonHwcPerFrameMetadataSupportVariant {
934 static constexpr int PER_FRAME_METADATA_KEYS = 0;
935 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800936 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700937 }
938};
939
940template <typename Display>
941struct NoPerFrameMetadataSupportVariant {
942 static constexpr int PER_FRAME_METADATA_KEYS = 0;
943 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800944 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
945 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700946 }
947};
948
949template <typename Display>
950struct Smpte2086PerFrameMetadataSupportVariant {
951 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
952 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800953 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
954 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800955 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
956 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
957 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
958 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
959 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
960 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
961 PerFrameMetadataKey::WHITE_POINT_X,
962 PerFrameMetadataKey::WHITE_POINT_Y,
963 PerFrameMetadataKey::MAX_LUMINANCE,
964 PerFrameMetadataKey::MIN_LUMINANCE,
965 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700966 }
967};
968
969template <typename Display>
970struct Cta861_3_PerFrameMetadataSupportVariant {
971 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
972 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800973 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
974 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800975 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
976 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
977 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700978 }
979};
980
Valerie Haue9e843a2018-12-18 13:39:23 -0800981template <typename Display>
982struct Hdr10_Plus_PerFrameMetadataSupportVariant {
983 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
984 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
985 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
986 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
987 PerFrameMetadataKey::HDR10_PLUS_SEI,
988 })));
989 }
990};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800991/* ------------------------------------------------------------------------
992 * Typical display configurations to test
993 */
994
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700995template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
996 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800997struct Case {
998 using Display = DisplayPolicy;
999 using WideColorSupport = WideColorSupportPolicy;
1000 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001001 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001002};
1003
1004using SimplePrimaryDisplayCase =
1005 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001006 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1007 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001008using SimpleExternalDisplayCase =
1009 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001010 HdrNotSupportedVariant<ExternalDisplayVariant>,
1011 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001012using SimpleTertiaryDisplayCase =
1013 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001014 HdrNotSupportedVariant<TertiaryDisplayVariant>,
1015 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001016using NonHwcVirtualDisplayCase =
1017 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001018 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
1019 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001020using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
1021using HwcVirtualDisplayCase =
1022 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -07001023 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +08001024 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001025using WideColorP3ColorimetricDisplayCase =
1026 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001027 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1028 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -08001029using Hdr10PlusDisplayCase =
1030 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1031 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1032 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001033using Hdr10DisplayCase =
1034 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001035 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1036 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001037using HdrHlgDisplayCase =
1038 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001039 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
1040 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001041using HdrDolbyVisionDisplayCase =
1042 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001043 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
1044 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1045using HdrSmpte2086DisplayCase =
1046 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1047 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1048 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1049using HdrCta861_3_DisplayCase =
1050 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1051 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1052 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -07001053
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001054/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -08001055 *
1056 * SurfaceFlinger::onHotplugReceived
1057 */
1058
1059TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
1060 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001061 constexpr HWDisplayId hwcDisplayId1 = 456;
1062 constexpr HWDisplayId hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001063
1064 // --------------------------------------------------------------------
1065 // Preconditions
1066
1067 // Set the current sequence id for accepted events
1068 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1069
1070 // Set the main thread id so that the current thread does not appear to be
1071 // the main thread.
1072 mFlinger.mutableMainThreadId() = std::thread::id();
1073
1074 // --------------------------------------------------------------------
1075 // Call Expectations
1076
1077 // We expect invalidate() to be invoked once to trigger display transaction
1078 // processing.
1079 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1080
1081 // --------------------------------------------------------------------
1082 // Invocation
1083
1084 // Simulate two hotplug events (a connect and a disconnect)
Peiyong Line9d809e2020-04-14 13:10:48 -07001085 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, Connection::CONNECTED);
1086 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001087
1088 // --------------------------------------------------------------------
1089 // Postconditions
1090
1091 // The display transaction needed flag should be set.
1092 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1093
1094 // All events should be in the pending event queue.
1095 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
1096 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001097 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001098 EXPECT_EQ(Connection::CONNECTED, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001099 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001100 EXPECT_EQ(Connection::DISCONNECTED, pendingEvents[1].connection);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001101}
1102
1103TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
1104 constexpr int currentSequenceId = 123;
1105 constexpr int otherSequenceId = 321;
Peiyong Line9d809e2020-04-14 13:10:48 -07001106 constexpr HWDisplayId displayId = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001107
1108 // --------------------------------------------------------------------
1109 // Preconditions
1110
1111 // Set the current sequence id for accepted events
1112 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1113
1114 // Set the main thread id so that the current thread does not appear to be
1115 // the main thread.
1116 mFlinger.mutableMainThreadId() = std::thread::id();
1117
1118 // --------------------------------------------------------------------
1119 // Call Expectations
1120
1121 // We do not expect any calls to invalidate().
1122 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
1123
1124 // --------------------------------------------------------------------
1125 // Invocation
1126
1127 // Call with an unexpected sequence id
Peiyong Line9d809e2020-04-14 13:10:48 -07001128 mFlinger.onHotplugReceived(otherSequenceId, displayId, Connection::INVALID);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001129
1130 // --------------------------------------------------------------------
1131 // Postconditions
1132
1133 // The display transaction needed flag should not be set
1134 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1135
1136 // There should be no pending events
1137 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1138}
1139
1140TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
1141 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001142 constexpr HWDisplayId displayId1 = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001143
1144 // --------------------------------------------------------------------
1145 // Note:
1146 // --------------------------------------------------------------------
1147 // This test case is a bit tricky. We want to verify that
1148 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
1149 // don't really want to provide coverage for everything the later function
1150 // does as there are specific tests for it.
1151 // --------------------------------------------------------------------
1152
1153 // --------------------------------------------------------------------
1154 // Preconditions
1155
1156 // Set the current sequence id for accepted events
1157 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1158
1159 // Set the main thread id so that the current thread does appear to be the
1160 // main thread.
1161 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
1162
1163 // --------------------------------------------------------------------
1164 // Call Expectations
1165
1166 // We expect invalidate() to be invoked once to trigger display transaction
1167 // processing.
1168 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1169
1170 // --------------------------------------------------------------------
1171 // Invocation
1172
1173 // Simulate a disconnect on a display id that is not connected. This should
1174 // be enqueued by onHotplugReceived(), and dequeued by
1175 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
Peiyong Line9d809e2020-04-14 13:10:48 -07001176 mFlinger.onHotplugReceived(currentSequenceId, displayId1, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001177
1178 // --------------------------------------------------------------------
1179 // Postconditions
1180
1181 // The display transaction needed flag should be set.
1182 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1183
1184 // There should be no event queued on return, as it should have been
1185 // processed.
1186 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1187}
1188
1189/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001190 * SurfaceFlinger::createDisplay
1191 */
1192
1193TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1194 const String8 name("virtual.test");
1195
1196 // --------------------------------------------------------------------
1197 // Call Expectations
1198
1199 // The call should notify the interceptor that a display was created.
1200 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1201
1202 // --------------------------------------------------------------------
1203 // Invocation
1204
1205 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1206
1207 // --------------------------------------------------------------------
1208 // Postconditions
1209
1210 // The display should have been added to the current state
1211 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1212 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001213 EXPECT_TRUE(display.isVirtual());
1214 EXPECT_FALSE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001215 EXPECT_EQ(name.string(), display.displayName);
1216
1217 // --------------------------------------------------------------------
1218 // Cleanup conditions
1219
1220 // Destroying the display invalidates the display state.
1221 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1222}
1223
1224TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1225 const String8 name("virtual.test");
1226
1227 // --------------------------------------------------------------------
1228 // Call Expectations
1229
1230 // The call should notify the interceptor that a display was created.
1231 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1232
1233 // --------------------------------------------------------------------
1234 // Invocation
chaviwd4a61642020-09-01 14:53:46 -07001235 int64_t oldId = IPCThreadState::self()->clearCallingIdentity();
1236 // Set the calling identity to graphics so captureDisplay with secure is allowed.
1237 IPCThreadState::self()->restoreCallingIdentity(static_cast<int64_t>(AID_GRAPHICS) << 32 |
1238 AID_GRAPHICS);
Lloyd Piquea482f992018-01-22 19:00:34 -08001239 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
chaviwd4a61642020-09-01 14:53:46 -07001240 IPCThreadState::self()->restoreCallingIdentity(oldId);
Lloyd Piquea482f992018-01-22 19:00:34 -08001241
1242 // --------------------------------------------------------------------
1243 // Postconditions
1244
1245 // The display should have been added to the current state
1246 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1247 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001248 EXPECT_TRUE(display.isVirtual());
1249 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001250 EXPECT_EQ(name.string(), display.displayName);
1251
1252 // --------------------------------------------------------------------
1253 // Cleanup conditions
1254
1255 // Destroying the display invalidates the display state.
1256 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1257}
1258
1259/* ------------------------------------------------------------------------
1260 * SurfaceFlinger::destroyDisplay
1261 */
1262
1263TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1264 using Case = NonHwcVirtualDisplayCase;
1265
1266 // --------------------------------------------------------------------
1267 // Preconditions
1268
1269 // A virtual display exists
1270 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1271 existing.inject();
1272
1273 // --------------------------------------------------------------------
1274 // Call Expectations
1275
1276 // The call should notify the interceptor that a display was created.
1277 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1278
1279 // Destroying the display invalidates the display state.
1280 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1281
1282 // --------------------------------------------------------------------
1283 // Invocation
1284
1285 mFlinger.destroyDisplay(existing.token());
1286
1287 // --------------------------------------------------------------------
1288 // Postconditions
1289
1290 // The display should have been removed from the current state
1291 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1292
1293 // Ths display should still exist in the drawing state
1294 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1295
1296 // The display transaction needed flasg should be set
1297 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1298}
1299
1300TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1301 // --------------------------------------------------------------------
1302 // Preconditions
1303
1304 sp<BBinder> displayToken = new BBinder();
1305
1306 // --------------------------------------------------------------------
1307 // Invocation
1308
1309 mFlinger.destroyDisplay(displayToken);
1310}
1311
1312/* ------------------------------------------------------------------------
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001313 * SurfaceFlinger::notifyPowerBoost
1314 */
1315
1316TEST_F(DisplayTransactionTest, notifyPowerBoostNotifiesTouchEvent) {
1317 mFlinger.scheduler()->replaceTouchTimer(100);
1318 std::this_thread::sleep_for(10ms); // wait for callback to be triggered
1319 EXPECT_TRUE(mFlinger.scheduler()->isTouchActive()); // Starting timer activates touch
1320
1321 std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback
1322 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1323
1324 EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::CAMERA_SHOT)));
1325 std::this_thread::sleep_for(10ms); // wait for callback to maybe be triggered
1326 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1327
1328 std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback
1329 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1330
1331 EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::INTERACTION)));
1332 std::this_thread::sleep_for(10ms); // wait for callback to be triggered.
1333 EXPECT_TRUE(mFlinger.scheduler()->isTouchActive());
1334}
1335
1336/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001337 * DisplayDevice::GetBestColorMode
1338 */
1339class GetBestColorModeTest : public DisplayTransactionTest {
1340public:
Valerie Hau9758ae02018-10-09 16:05:09 -07001341 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1342
1343 void addHwcColorModesMapping(ui::ColorMode colorMode,
1344 std::vector<ui::RenderIntent> renderIntents) {
1345 mHwcColorModes[colorMode] = renderIntents;
1346 }
1347
1348 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1349
1350 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1351
1352 void getBestColorMode() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001353 auto displayDevice =
1354 injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1355 injector.setHwcColorModes(mHwcColorModes);
1356 injector.setHasWideColorGamut(mHasWideColorGamut);
1357 injector.setNativeWindow(mNativeWindow);
1358 });
Valerie Hau9758ae02018-10-09 16:05:09 -07001359
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001360 displayDevice->getCompositionDisplay()
1361 ->getDisplayColorProfile()
1362 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1363 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001364 }
1365
1366 ui::Dataspace mOutDataspace;
1367 ui::ColorMode mOutColorMode;
1368 ui::RenderIntent mOutRenderIntent;
1369
1370private:
1371 ui::Dataspace mInputDataspace;
1372 ui::RenderIntent mInputRenderIntent;
1373 bool mHasWideColorGamut = false;
1374 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
Valerie Hau9758ae02018-10-09 16:05:09 -07001375};
1376
1377TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1378 addHwcColorModesMapping(ui::ColorMode::SRGB,
1379 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1380 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1381 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1382 setHasWideColorGamut(true);
1383
1384 getBestColorMode();
1385
Peiyong Lin14724e62018-12-05 07:27:30 -08001386 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001387 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1388 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1389}
1390
1391TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1392 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1393 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1394 addHwcColorModesMapping(ui::ColorMode::SRGB,
1395 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1396 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1397 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1398 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1399 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1400 setHasWideColorGamut(true);
1401
1402 getBestColorMode();
1403
1404 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1405 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1406 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1407}
1408
1409TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1410 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1411 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1412 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1413 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1414 setHasWideColorGamut(true);
1415
1416 getBestColorMode();
1417
1418 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1419 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1420 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1421}
1422
1423/* ------------------------------------------------------------------------
Lloyd Pique33050472019-12-19 17:12:44 -08001424 * DisplayDevice::setProjection
1425 */
1426
1427class DisplayDeviceSetProjectionTest : public DisplayTransactionTest {
1428public:
Lloyd Pique33050472019-12-19 17:12:44 -08001429 static constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1080; // arbitrary
1430 static constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1920; // arbitrary
1431
1432 static constexpr int32_t TRANSFORM_FLAGS_ROT_0 = 0;
1433 static constexpr int32_t TRANSFORM_FLAGS_ROT_90 = HAL_TRANSFORM_ROT_90;
1434 static constexpr int32_t TRANSFORM_FLAGS_ROT_180 = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V;
1435 static constexpr int32_t TRANSFORM_FLAGS_ROT_270 =
1436 HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
1437
1438 DisplayDeviceSetProjectionTest(ui::Size flingerDisplaySize, ui::Size hardwareDisplaySize,
1439 ui::Rotation physicalOrientation)
1440 : mFlingerDisplaySize(flingerDisplaySize),
1441 mHardwareDisplaySize(hardwareDisplaySize),
1442 mPhysicalOrientation(physicalOrientation),
1443 mDisplayDevice(createDisplayDevice()) {}
1444
1445 sp<DisplayDevice> createDisplayDevice() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001446 return injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1447 injector.setPhysicalOrientation(mPhysicalOrientation);
1448 });
Lloyd Pique33050472019-12-19 17:12:44 -08001449 }
1450
Marin Shalamanov209ae612020-10-01 00:17:39 +02001451 ui::Size swapWH(const ui::Size size) const { return ui::Size(size.height, size.width); }
Lloyd Pique33050472019-12-19 17:12:44 -08001452
1453 void setProjectionForRotation0() {
1454 // A logical rotation of 0 uses the SurfaceFlinger display size
1455 mDisplayDevice->setProjection(ui::ROTATION_0, Rect(mFlingerDisplaySize),
1456 Rect(mFlingerDisplaySize));
1457 }
1458
1459 void setProjectionForRotation90() {
1460 // A logical rotation of 90 uses the SurfaceFlinger display size with
1461 // the width/height swapped.
Marin Shalamanov209ae612020-10-01 00:17:39 +02001462 mDisplayDevice->setProjection(ui::ROTATION_90, Rect(swapWH(mFlingerDisplaySize)),
1463 Rect(swapWH(mFlingerDisplaySize)));
Lloyd Pique33050472019-12-19 17:12:44 -08001464 }
1465
1466 void setProjectionForRotation180() {
1467 // A logical rotation of 180 uses the SurfaceFlinger display size
1468 mDisplayDevice->setProjection(ui::ROTATION_180, Rect(mFlingerDisplaySize),
1469 Rect(mFlingerDisplaySize));
1470 }
1471
1472 void setProjectionForRotation270() {
1473 // A logical rotation of 270 uses the SurfaceFlinger display size with
1474 // the width/height swapped.
Marin Shalamanov209ae612020-10-01 00:17:39 +02001475 mDisplayDevice->setProjection(ui::ROTATION_270, Rect(swapWH(mFlingerDisplaySize)),
1476 Rect(swapWH(mFlingerDisplaySize)));
Lloyd Pique33050472019-12-19 17:12:44 -08001477 }
1478
1479 void expectStateForHardwareTransform0() {
1480 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1481 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_0, mHardwareDisplaySize.width,
1482 mHardwareDisplaySize.height),
1483 compositionState.transform);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02001484 EXPECT_EQ(ui::ROTATION_0, compositionState.displaySpace.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001485 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content);
1486 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.orientedDisplaySpace.content);
1487 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001488 EXPECT_EQ(false, compositionState.needsFiltering);
1489 }
1490
1491 void expectStateForHardwareTransform90() {
1492 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1493 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width,
1494 mHardwareDisplaySize.height),
1495 compositionState.transform);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02001496 EXPECT_EQ(ui::ROTATION_90, compositionState.displaySpace.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001497 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content);
1498 // For 90, the orientedDisplaySpaceRect and layerStackSpaceRect have the hardware display
1499 // size width and height swapped
Marin Shalamanov209ae612020-10-01 00:17:39 +02001500 EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)),
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001501 compositionState.orientedDisplaySpace.content);
Marin Shalamanov209ae612020-10-01 00:17:39 +02001502 EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001503 EXPECT_EQ(false, compositionState.needsFiltering);
1504 }
1505
1506 void expectStateForHardwareTransform180() {
1507 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1508 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width,
1509 mHardwareDisplaySize.height),
1510 compositionState.transform);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02001511 EXPECT_EQ(ui::ROTATION_180, compositionState.displaySpace.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001512 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.orientedDisplaySpace.content);
1513 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001514 EXPECT_EQ(false, compositionState.needsFiltering);
1515 }
1516
1517 void expectStateForHardwareTransform270() {
1518 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1519 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width,
1520 mHardwareDisplaySize.height),
1521 compositionState.transform);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02001522 EXPECT_EQ(ui::ROTATION_270, compositionState.displaySpace.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001523 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content);
1524 // For 270, the orientedDisplaySpaceRect and layerStackSpaceRect have the hardware display
1525 // size width and height swapped
Marin Shalamanov209ae612020-10-01 00:17:39 +02001526 EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)),
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001527 compositionState.orientedDisplaySpace.content);
Marin Shalamanov209ae612020-10-01 00:17:39 +02001528 EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001529 EXPECT_EQ(false, compositionState.needsFiltering);
1530 }
1531
1532 const ui::Size mFlingerDisplaySize;
1533 const ui::Size mHardwareDisplaySize;
1534 const ui::Rotation mPhysicalOrientation;
1535 const sp<DisplayDevice> mDisplayDevice;
1536};
1537
1538struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest {
1539 DisplayDeviceSetProjectionTest_Installed0()
1540 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1541 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1542 ui::ROTATION_0) {}
1543};
1544
1545TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) {
1546 setProjectionForRotation0();
1547 expectStateForHardwareTransform0();
1548}
1549
1550TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) {
1551 setProjectionForRotation90();
1552 expectStateForHardwareTransform90();
1553}
1554
1555TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) {
1556 setProjectionForRotation180();
1557 expectStateForHardwareTransform180();
1558}
1559
1560TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) {
1561 setProjectionForRotation270();
1562 expectStateForHardwareTransform270();
1563}
1564
1565struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest {
1566 DisplayDeviceSetProjectionTest_Installed90()
1567 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1568 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1569 ui::ROTATION_90) {}
1570};
1571
1572TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) {
1573 setProjectionForRotation0();
1574 expectStateForHardwareTransform90();
1575}
1576
1577TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) {
1578 setProjectionForRotation90();
1579 expectStateForHardwareTransform180();
1580}
1581
1582TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) {
1583 setProjectionForRotation180();
1584 expectStateForHardwareTransform270();
1585}
1586
1587TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) {
1588 setProjectionForRotation270();
1589 expectStateForHardwareTransform0();
1590}
1591
1592struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest {
1593 DisplayDeviceSetProjectionTest_Installed180()
1594 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1595 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1596 ui::ROTATION_180) {}
1597};
1598
1599TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) {
1600 setProjectionForRotation0();
1601 expectStateForHardwareTransform180();
1602}
1603
1604TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) {
1605 setProjectionForRotation90();
1606 expectStateForHardwareTransform270();
1607}
1608
1609TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) {
1610 setProjectionForRotation180();
1611 expectStateForHardwareTransform0();
1612}
1613
1614TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) {
1615 setProjectionForRotation270();
1616 expectStateForHardwareTransform90();
1617}
1618
1619struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest {
1620 DisplayDeviceSetProjectionTest_Installed270()
1621 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1622 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1623 ui::ROTATION_270) {}
1624};
1625
1626TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) {
1627 setProjectionForRotation0();
1628 expectStateForHardwareTransform270();
1629}
1630
1631TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) {
1632 setProjectionForRotation90();
1633 expectStateForHardwareTransform0();
1634}
1635
1636TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) {
1637 setProjectionForRotation180();
1638 expectStateForHardwareTransform90();
1639}
1640
1641TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) {
1642 setProjectionForRotation270();
1643 expectStateForHardwareTransform180();
1644}
1645
1646/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001647 * SurfaceFlinger::getDisplayNativePrimaries
1648 */
1649
1650class GetDisplayNativePrimaries : public DisplayTransactionTest {
1651public:
1652 GetDisplayNativePrimaries();
1653 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1654 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1655
1656private:
1657 static constexpr float mStartingTestValue = 1.0f;
1658};
1659
1660GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1661 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1662 injectFakeNativeWindowSurfaceFactory();
1663}
1664
1665void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1666 ui::DisplayPrimaries& primaries) {
1667 float startingVal = mStartingTestValue;
1668 primaries.red.X = startingVal++;
1669 primaries.red.Y = startingVal++;
1670 primaries.red.Z = startingVal++;
1671 primaries.green.X = startingVal++;
1672 primaries.green.Y = startingVal++;
1673 primaries.green.Z = startingVal++;
1674 primaries.blue.X = startingVal++;
1675 primaries.blue.Y = startingVal++;
1676 primaries.blue.Z = startingVal++;
1677 primaries.white.X = startingVal++;
1678 primaries.white.Y = startingVal++;
1679 primaries.white.Z = startingVal++;
1680}
1681
1682void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1683 const ui::DisplayPrimaries& primaries) {
1684 float startingVal = mStartingTestValue;
1685 EXPECT_EQ(primaries.red.X, startingVal++);
1686 EXPECT_EQ(primaries.red.Y, startingVal++);
1687 EXPECT_EQ(primaries.red.Z, startingVal++);
1688 EXPECT_EQ(primaries.green.X, startingVal++);
1689 EXPECT_EQ(primaries.green.Y, startingVal++);
1690 EXPECT_EQ(primaries.green.Z, startingVal++);
1691 EXPECT_EQ(primaries.blue.X, startingVal++);
1692 EXPECT_EQ(primaries.blue.Y, startingVal++);
1693 EXPECT_EQ(primaries.blue.Z, startingVal++);
1694 EXPECT_EQ(primaries.white.X, startingVal++);
1695 EXPECT_EQ(primaries.white.Y, startingVal++);
1696 EXPECT_EQ(primaries.white.Z, startingVal++);
1697}
1698
1699TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1700 ui::DisplayPrimaries primaries;
1701 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1702}
1703
Daniel Solomon42d04562019-01-20 21:03:19 -08001704TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1705 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1706 injector.inject();
1707 auto internalDisplayToken = injector.token();
1708
1709 ui::DisplayPrimaries expectedPrimaries;
1710 populateDummyDisplayNativePrimaries(expectedPrimaries);
1711 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1712
1713 ui::DisplayPrimaries primaries;
1714 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1715
1716 checkDummyDisplayNativePrimaries(primaries);
1717}
1718
1719TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1720 sp<BBinder> notInternalDisplayToken = new BBinder();
1721
1722 ui::DisplayPrimaries primaries;
1723 populateDummyDisplayNativePrimaries(primaries);
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001724 EXPECT_EQ(NAME_NOT_FOUND,
1725 mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
Daniel Solomon42d04562019-01-20 21:03:19 -08001726
1727 // Check primaries argument wasn't modified in case of failure
1728 checkDummyDisplayNativePrimaries(primaries);
1729}
1730
1731/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001732 * SurfaceFlinger::setupNewDisplayDeviceInternal
1733 */
1734
1735class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1736public:
1737 template <typename T>
1738 void setupNewDisplayDeviceInternalTest();
1739};
1740
1741template <typename Case>
1742void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1743 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001744 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1745 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001746 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001747
1748 // --------------------------------------------------------------------
1749 // Preconditions
1750
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001751 // Wide color displays support is configured appropriately
1752 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001753
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001754 // The display is setup with the HWC.
1755 Case::Display::injectHwcDisplay(this);
1756
1757 // SurfaceFlinger will use a test-controlled factory for native window
1758 // surfaces.
1759 injectFakeNativeWindowSurfaceFactory();
1760
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001761 // A compositionengine::Display has already been created
1762 auto compositionDisplay = Case::Display::injectCompositionDisplay(this);
1763
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001764 // --------------------------------------------------------------------
1765 // Call Expectations
1766
1767 // Various native window calls will be made.
1768 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001769 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001770 Case::WideColorSupport::setupComposerCallExpectations(this);
1771 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001772 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001773
1774 // --------------------------------------------------------------------
1775 // Invocation
1776
1777 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -08001778 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1779 const auto displayId = Case::Display::DISPLAY_ID::get();
1780 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001781 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1782 ASSERT_TRUE(hwcDisplayId);
Marin Shalamanova524a092020-07-27 21:39:55 +02001783 state.physical = {.id = static_cast<PhysicalDisplayId>(*displayId),
1784 .type = *connectionType,
1785 .hwcDisplayId = *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001786 }
1787
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001788 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1789
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001790 auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state,
1791 displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001792
1793 // --------------------------------------------------------------------
1794 // Postconditions
1795
1796 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001797 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001798 EXPECT_EQ(Case::Display::CONNECTION_TYPE::value, device->getConnectionType());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001799 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001800 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001801 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001802 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1803 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1804 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001805 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001806 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1807 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1808 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001809 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1810 // remapped, and the test only ever sets up one config. If there were an error
1811 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
Ady Abraham2139f732019-11-13 18:56:40 -08001812 EXPECT_EQ(0, device->getActiveConfig().value());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001813 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1814 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001815}
1816
1817TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1818 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1819}
1820
1821TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1822 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1823}
1824
1825TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1826 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1827}
1828
1829TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001830 setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001831}
1832
1833TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1834 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1835}
1836
Valerie Haue9e843a2018-12-18 13:39:23 -08001837TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1838 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1839}
1840
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001841TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1842 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1843}
1844
1845TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1846 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1847}
1848
1849TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1850 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1851}
1852
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001853TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1854 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1855}
1856
1857TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1858 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1859}
1860
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001861/* ------------------------------------------------------------------------
1862 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1863 */
1864
1865class HandleTransactionLockedTest : public DisplayTransactionTest {
1866public:
1867 template <typename Case>
1868 void setupCommonPreconditions();
1869
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001870 template <typename Case, bool connected>
1871 static void expectHotplugReceived(mock::EventThread*);
1872
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001873 template <typename Case>
1874 void setupCommonCallExpectationsForConnectProcessing();
1875
1876 template <typename Case>
1877 void setupCommonCallExpectationsForDisconnectProcessing();
1878
1879 template <typename Case>
1880 void processesHotplugConnectCommon();
1881
1882 template <typename Case>
1883 void ignoresHotplugConnectCommon();
1884
1885 template <typename Case>
1886 void processesHotplugDisconnectCommon();
1887
1888 template <typename Case>
1889 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1890
1891 template <typename Case>
1892 void verifyPhysicalDisplayIsConnected();
1893
1894 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1895};
1896
1897template <typename Case>
1898void HandleTransactionLockedTest::setupCommonPreconditions() {
1899 // Wide color displays support is configured appropriately
1900 Case::WideColorSupport::injectConfigChange(this);
1901
1902 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1903 injectFakeBufferQueueFactory();
1904
1905 // SurfaceFlinger will use a test-controlled factory for native window
1906 // surfaces.
1907 injectFakeNativeWindowSurfaceFactory();
1908}
1909
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001910template <typename Case, bool connected>
1911void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1912 const auto convert = [](auto physicalDisplayId) {
1913 return std::make_optional(DisplayId{physicalDisplayId});
1914 };
1915
1916 EXPECT_CALL(*eventThread,
1917 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1918 .Times(1);
1919}
1920
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001921template <typename Case>
1922void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1923 Case::Display::setupHwcHotplugCallExpectations(this);
1924
1925 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1926 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1927 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1928 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1929
1930 Case::WideColorSupport::setupComposerCallExpectations(this);
1931 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001932 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001933
1934 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001935 expectHotplugReceived<Case, true>(mEventThread);
1936 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001937}
1938
1939template <typename Case>
1940void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1941 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001942
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001943 expectHotplugReceived<Case, false>(mEventThread);
1944 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001945}
1946
1947template <typename Case>
1948void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1949 // The display device should have been set up in the list of displays.
1950 ASSERT_TRUE(hasDisplayDevice(displayToken));
1951 const auto& device = getDisplayDevice(displayToken);
1952 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001953 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001954
Dominik Laskowski55c85402020-01-21 16:25:47 -08001955 std::optional<DisplayDeviceState::Physical> expectedPhysical;
1956 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
1957 const auto displayId = Case::Display::DISPLAY_ID::get();
1958 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001959 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1960 ASSERT_TRUE(hwcDisplayId);
Marin Shalamanova524a092020-07-27 21:39:55 +02001961 expectedPhysical = {.id = static_cast<PhysicalDisplayId>(*displayId),
Marin Shalamanov7ce87642020-05-06 13:45:58 +02001962 .type = *connectionType,
1963 .hwcDisplayId = *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001964 }
1965
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001966 // The display should have been set up in the current display state
1967 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1968 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001969 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001970 EXPECT_EQ(expectedPhysical, current.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001971
1972 // The display should have been set up in the drawing display state
1973 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
1974 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001975 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001976 EXPECT_EQ(expectedPhysical, draw.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001977}
1978
1979template <typename Case>
1980void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
1981 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07001982 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001983
Dominik Laskowski075d3172018-05-24 15:50:06 -07001984 // SF should have a display token.
1985 const auto displayId = Case::Display::DISPLAY_ID::get();
1986 ASSERT_TRUE(displayId);
1987 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
1988 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[*displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001989
1990 verifyDisplayIsConnected<Case>(displayToken);
1991}
1992
1993void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
1994 EXPECT_FALSE(hasDisplayDevice(displayToken));
1995 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
1996 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
1997}
1998
1999template <typename Case>
2000void HandleTransactionLockedTest::processesHotplugConnectCommon() {
2001 // --------------------------------------------------------------------
2002 // Preconditions
2003
2004 setupCommonPreconditions<Case>();
2005
2006 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002007 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002008
2009 // --------------------------------------------------------------------
2010 // Call Expectations
2011
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002012 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002013
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002014 // --------------------------------------------------------------------
2015 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08002016
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002017 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08002018
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002019 // --------------------------------------------------------------------
2020 // Postconditions
2021
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002022 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002023
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002024 // --------------------------------------------------------------------
2025 // Cleanup conditions
2026
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002027 EXPECT_CALL(*mComposer,
2028 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002029 .WillOnce(Return(Error::NONE));
2030 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08002031}
2032
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002033template <typename Case>
2034void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
2035 // --------------------------------------------------------------------
2036 // Preconditions
2037
2038 setupCommonPreconditions<Case>();
2039
2040 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002041 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002042
2043 // --------------------------------------------------------------------
2044 // Invocation
2045
2046 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2047
2048 // --------------------------------------------------------------------
2049 // Postconditions
2050
2051 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002052 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002053}
2054
2055template <typename Case>
2056void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
2057 // --------------------------------------------------------------------
2058 // Preconditions
2059
2060 setupCommonPreconditions<Case>();
2061
2062 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002063 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002064
2065 // The display is already completely set up.
2066 Case::Display::injectHwcDisplay(this);
2067 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2068 existing.inject();
2069
2070 // --------------------------------------------------------------------
2071 // Call Expectations
2072
Lloyd Pique438e9e72018-09-04 18:06:08 -07002073 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
2074 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002075
2076 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2077
2078 // --------------------------------------------------------------------
2079 // Invocation
2080
2081 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2082
2083 // --------------------------------------------------------------------
2084 // Postconditions
2085
2086 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002087 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002088
Dominik Laskowski075d3172018-05-24 15:50:06 -07002089 // SF should not have a display token.
2090 const auto displayId = Case::Display::DISPLAY_ID::get();
2091 ASSERT_TRUE(displayId);
2092 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002093
2094 // The existing token should have been removed
2095 verifyDisplayIsNotConnected(existing.token());
2096}
2097
2098TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
2099 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2100}
2101
2102TEST_F(HandleTransactionLockedTest,
2103 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
2104 // Inject an external display.
2105 ExternalDisplayVariant::injectHwcDisplay(this);
2106
2107 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2108}
2109
2110TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
2111 // Inject a primary display.
2112 PrimaryDisplayVariant::injectHwcDisplay(this);
2113
2114 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
2115}
2116
2117TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
2118 // Inject both a primary and external display.
2119 PrimaryDisplayVariant::injectHwcDisplay(this);
2120 ExternalDisplayVariant::injectHwcDisplay(this);
2121
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002122 // TODO: This is an unnecessary call.
2123 EXPECT_CALL(*mComposer,
2124 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
2125 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
2126 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
2127 Return(Error::NONE)));
2128
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002129 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
2130}
2131
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002132TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectPrimaryDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002133 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
2134}
2135
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002136TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectExternalDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002137 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
2138}
2139
2140TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
2141 using Case = SimplePrimaryDisplayCase;
2142
2143 // --------------------------------------------------------------------
2144 // Preconditions
2145
2146 setupCommonPreconditions<Case>();
2147
2148 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002149 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002150 // A hotplug disconnect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002151 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002152
2153 // --------------------------------------------------------------------
2154 // Call Expectations
2155
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002156 setupCommonCallExpectationsForConnectProcessing<Case>();
2157 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2158
2159 EXPECT_CALL(*mComposer,
2160 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2161 .WillOnce(Return(Error::NONE));
2162 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2163
2164 // --------------------------------------------------------------------
2165 // Invocation
2166
2167 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2168
2169 // --------------------------------------------------------------------
2170 // Postconditions
2171
2172 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002173 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002174
Dominik Laskowski075d3172018-05-24 15:50:06 -07002175 // SF should not have a display token.
2176 const auto displayId = Case::Display::DISPLAY_ID::get();
2177 ASSERT_TRUE(displayId);
2178 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002179}
2180
2181TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
2182 using Case = SimplePrimaryDisplayCase;
2183
2184 // --------------------------------------------------------------------
2185 // Preconditions
2186
2187 setupCommonPreconditions<Case>();
2188
2189 // The display is already completely set up.
2190 Case::Display::injectHwcDisplay(this);
2191 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2192 existing.inject();
2193
2194 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002195 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002196 // A hotplug connect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002197 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002198
2199 // --------------------------------------------------------------------
2200 // Call Expectations
2201
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002202 setupCommonCallExpectationsForConnectProcessing<Case>();
2203 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2204
2205 // --------------------------------------------------------------------
2206 // Invocation
2207
2208 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2209
2210 // --------------------------------------------------------------------
2211 // Postconditions
2212
2213 // The existing token should have been removed
2214 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07002215 const auto displayId = Case::Display::DISPLAY_ID::get();
2216 ASSERT_TRUE(displayId);
2217 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(*displayId) == 1);
2218 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[*displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002219
2220 // A new display should be connected in its place
2221
2222 verifyPhysicalDisplayIsConnected<Case>();
2223
2224 // --------------------------------------------------------------------
2225 // Cleanup conditions
2226
2227 EXPECT_CALL(*mComposer,
2228 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2229 .WillOnce(Return(Error::NONE));
2230 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2231}
2232
2233TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
2234 using Case = HwcVirtualDisplayCase;
2235
2236 // --------------------------------------------------------------------
2237 // Preconditions
2238
2239 // The HWC supports at least one virtual display
2240 injectMockComposer(1);
2241
2242 setupCommonPreconditions<Case>();
2243
2244 // A virtual display was added to the current state, and it has a
2245 // surface(producer)
2246 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07002247
Dominik Laskowski075d3172018-05-24 15:50:06 -07002248 DisplayDeviceState state;
2249 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002250
2251 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07002252 state.surface = surface;
2253 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002254
2255 // --------------------------------------------------------------------
2256 // Call Expectations
2257
2258 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
2259 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
2260
2261 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
2262 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
2263 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
2264 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
2265 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
2266 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
2267 Return(NO_ERROR)));
2268 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
2269 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
2270
2271 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
2272
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002273 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002274 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
2275
2276 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
2277 Case::WideColorSupport::setupComposerCallExpectations(this);
2278 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07002279 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002280
2281 // --------------------------------------------------------------------
2282 // Invocation
2283
2284 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2285
2286 // --------------------------------------------------------------------
2287 // Postconditions
2288
2289 // The display device should have been set up in the list of displays.
2290 verifyDisplayIsConnected<Case>(displayToken);
2291
2292 // --------------------------------------------------------------------
2293 // Cleanup conditions
2294
2295 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
2296 .WillOnce(Return(Error::NONE));
2297 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08002298
2299 // Cleanup
2300 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
2301 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002302}
2303
2304TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
2305 using Case = HwcVirtualDisplayCase;
2306
2307 // --------------------------------------------------------------------
2308 // Preconditions
2309
2310 // The HWC supports at least one virtual display
2311 injectMockComposer(1);
2312
2313 setupCommonPreconditions<Case>();
2314
2315 // A virtual display was added to the current state, but it does not have a
2316 // surface.
2317 sp<BBinder> displayToken = new BBinder();
2318
Dominik Laskowski075d3172018-05-24 15:50:06 -07002319 DisplayDeviceState state;
2320 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002321
Dominik Laskowski075d3172018-05-24 15:50:06 -07002322 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002323
2324 // --------------------------------------------------------------------
2325 // Call Expectations
2326
2327 // --------------------------------------------------------------------
2328 // Invocation
2329
2330 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2331
2332 // --------------------------------------------------------------------
2333 // Postconditions
2334
2335 // There will not be a display device set up.
2336 EXPECT_FALSE(hasDisplayDevice(displayToken));
2337
2338 // The drawing display state will be set from the current display state.
2339 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2340 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002341 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002342}
2343
2344TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
2345 using Case = HwcVirtualDisplayCase;
2346
2347 // --------------------------------------------------------------------
2348 // Preconditions
2349
2350 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002351 const auto displayId = Case::Display::DISPLAY_ID::get();
2352 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08002353 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002354 Case::Display::injectHwcDisplay(this);
2355 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2356 existing.inject();
2357 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2358
2359 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002360 // Invocation
2361
2362 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2363
2364 // --------------------------------------------------------------------
2365 // Postconditions
2366
2367 // The existing token should have been removed
2368 verifyDisplayIsNotConnected(existing.token());
2369}
2370
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002371TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2372 using Case = NonHwcVirtualDisplayCase;
2373
2374 constexpr uint32_t oldLayerStack = 0u;
2375 constexpr uint32_t newLayerStack = 123u;
2376
2377 // --------------------------------------------------------------------
2378 // Preconditions
2379
2380 // A display is set up
2381 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2382 display.inject();
2383
2384 // There is a change to the layerStack state
2385 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2386 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2387
2388 // --------------------------------------------------------------------
2389 // Invocation
2390
2391 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2392
2393 // --------------------------------------------------------------------
2394 // Postconditions
2395
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002396 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002397}
2398
2399TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2400 using Case = NonHwcVirtualDisplayCase;
2401
Dominik Laskowski718f9602019-11-09 20:01:35 -08002402 constexpr ui::Rotation oldTransform = ui::ROTATION_0;
2403 constexpr ui::Rotation newTransform = ui::ROTATION_180;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002404
2405 // --------------------------------------------------------------------
2406 // Preconditions
2407
2408 // A display is set up
2409 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2410 display.inject();
2411
2412 // There is a change to the orientation state
2413 display.mutableDrawingDisplayState().orientation = oldTransform;
2414 display.mutableCurrentDisplayState().orientation = newTransform;
2415
2416 // --------------------------------------------------------------------
2417 // Invocation
2418
2419 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2420
2421 // --------------------------------------------------------------------
2422 // Postconditions
2423
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002424 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002425}
2426
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002427TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackRectChanges) {
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002428 using Case = NonHwcVirtualDisplayCase;
2429
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002430 const Rect oldLayerStackRect(0, 0, 0, 0);
2431 const Rect newLayerStackRect(0, 0, 123, 456);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002432
2433 // --------------------------------------------------------------------
2434 // Preconditions
2435
2436 // A display is set up
2437 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2438 display.inject();
2439
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002440 // There is a change to the layerStackSpaceRect state
2441 display.mutableDrawingDisplayState().layerStackSpaceRect = oldLayerStackRect;
2442 display.mutableCurrentDisplayState().layerStackSpaceRect = newLayerStackRect;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002443
2444 // --------------------------------------------------------------------
2445 // Invocation
2446
2447 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2448
2449 // --------------------------------------------------------------------
2450 // Postconditions
2451
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002452 EXPECT_EQ(newLayerStackRect, display.mutableDisplayDevice()->getLayerStackSpaceRect());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002453}
2454
2455TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2456 using Case = NonHwcVirtualDisplayCase;
2457
2458 const Rect oldFrame(0, 0, 0, 0);
2459 const Rect newFrame(0, 0, 123, 456);
2460
2461 // --------------------------------------------------------------------
2462 // Preconditions
2463
2464 // A display is set up
2465 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2466 display.inject();
2467
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002468 // There is a change to the layerStackSpaceRect state
2469 display.mutableDrawingDisplayState().orientedDisplaySpaceRect = oldFrame;
2470 display.mutableCurrentDisplayState().orientedDisplaySpaceRect = newFrame;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002471
2472 // --------------------------------------------------------------------
2473 // Invocation
2474
2475 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2476
2477 // --------------------------------------------------------------------
2478 // Postconditions
2479
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002480 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getOrientedDisplaySpaceRect());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002481}
2482
2483TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2484 using Case = NonHwcVirtualDisplayCase;
2485
2486 constexpr int oldWidth = 0;
2487 constexpr int oldHeight = 10;
2488 constexpr int newWidth = 123;
2489
2490 // --------------------------------------------------------------------
2491 // Preconditions
2492
2493 // A display is set up
2494 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002495 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002496 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002497 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2498 display.setNativeWindow(nativeWindow);
2499 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002500 // Setup injection expections
2501 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2502 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2503 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2504 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002505 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2506 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2507 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002508 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002509 display.inject();
2510
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002511 // There is a change to the layerStackSpaceRect state
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002512 display.mutableDrawingDisplayState().width = oldWidth;
2513 display.mutableDrawingDisplayState().height = oldHeight;
2514 display.mutableCurrentDisplayState().width = newWidth;
2515 display.mutableCurrentDisplayState().height = oldHeight;
2516
2517 // --------------------------------------------------------------------
2518 // Call Expectations
2519
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002520 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002521
2522 // --------------------------------------------------------------------
2523 // Invocation
2524
2525 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2526}
2527
2528TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2529 using Case = NonHwcVirtualDisplayCase;
2530
2531 constexpr int oldWidth = 0;
2532 constexpr int oldHeight = 10;
2533 constexpr int newHeight = 123;
2534
2535 // --------------------------------------------------------------------
2536 // Preconditions
2537
2538 // A display is set up
2539 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002540 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002541 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002542 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2543 display.setNativeWindow(nativeWindow);
2544 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002545 // Setup injection expections
2546 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2547 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2548 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2549 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002550 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2551 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2552 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002553 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002554 display.inject();
2555
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002556 // There is a change to the layerStackSpaceRect state
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002557 display.mutableDrawingDisplayState().width = oldWidth;
2558 display.mutableDrawingDisplayState().height = oldHeight;
2559 display.mutableCurrentDisplayState().width = oldWidth;
2560 display.mutableCurrentDisplayState().height = newHeight;
2561
2562 // --------------------------------------------------------------------
2563 // Call Expectations
2564
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002565 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002566
2567 // --------------------------------------------------------------------
2568 // Invocation
2569
2570 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2571}
2572
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002573/* ------------------------------------------------------------------------
2574 * SurfaceFlinger::setDisplayStateLocked
2575 */
2576
2577TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2578 // --------------------------------------------------------------------
2579 // Preconditions
2580
2581 // We have an unknown display token not associated with a known display
2582 sp<BBinder> displayToken = new BBinder();
2583
2584 // The requested display state references the unknown display.
2585 DisplayState state;
2586 state.what = DisplayState::eLayerStackChanged;
2587 state.token = displayToken;
2588 state.layerStack = 456;
2589
2590 // --------------------------------------------------------------------
2591 // Invocation
2592
2593 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2594
2595 // --------------------------------------------------------------------
2596 // Postconditions
2597
2598 // The returned flags are empty
2599 EXPECT_EQ(0u, flags);
2600
2601 // The display token still doesn't match anything known.
2602 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2603}
2604
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002605TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2606 using Case = SimplePrimaryDisplayCase;
2607
2608 // --------------------------------------------------------------------
2609 // Preconditions
2610
2611 // A display is already set up
2612 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2613 display.inject();
2614
2615 // No changes are made to the display
2616 DisplayState state;
2617 state.what = 0;
2618 state.token = display.token();
2619
2620 // --------------------------------------------------------------------
2621 // Invocation
2622
2623 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2624
2625 // --------------------------------------------------------------------
2626 // Postconditions
2627
2628 // The returned flags are empty
2629 EXPECT_EQ(0u, flags);
2630}
2631
2632TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2633 using Case = SimplePrimaryDisplayCase;
2634
2635 // --------------------------------------------------------------------
2636 // Preconditions
2637
2638 // A display is already set up
2639 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2640 display.inject();
2641
2642 // There is a surface that can be set.
2643 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2644
2645 // The current display state has the surface set
2646 display.mutableCurrentDisplayState().surface = surface;
2647
2648 // The incoming request sets the same surface
2649 DisplayState state;
2650 state.what = DisplayState::eSurfaceChanged;
2651 state.token = display.token();
2652 state.surface = surface;
2653
2654 // --------------------------------------------------------------------
2655 // Invocation
2656
2657 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2658
2659 // --------------------------------------------------------------------
2660 // Postconditions
2661
2662 // The returned flags are empty
2663 EXPECT_EQ(0u, flags);
2664
2665 // The current display state is unchanged.
2666 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2667}
2668
2669TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2670 using Case = SimplePrimaryDisplayCase;
2671
2672 // --------------------------------------------------------------------
2673 // Preconditions
2674
2675 // A display is already set up
2676 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2677 display.inject();
2678
2679 // There is a surface that can be set.
2680 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2681
2682 // The current display state does not have a surface
2683 display.mutableCurrentDisplayState().surface = nullptr;
2684
2685 // The incoming request sets a surface
2686 DisplayState state;
2687 state.what = DisplayState::eSurfaceChanged;
2688 state.token = display.token();
2689 state.surface = surface;
2690
2691 // --------------------------------------------------------------------
2692 // Invocation
2693
2694 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2695
2696 // --------------------------------------------------------------------
2697 // Postconditions
2698
2699 // The returned flags indicate a transaction is needed
2700 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2701
2702 // The current display layer stack state is set to the new value
2703 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2704}
2705
2706TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2707 using Case = SimplePrimaryDisplayCase;
2708
2709 // --------------------------------------------------------------------
2710 // Preconditions
2711
2712 // A display is already set up
2713 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2714 display.inject();
2715
2716 // The display has a layer stack set
2717 display.mutableCurrentDisplayState().layerStack = 456u;
2718
2719 // The incoming request sets the same layer stack
2720 DisplayState state;
2721 state.what = DisplayState::eLayerStackChanged;
2722 state.token = display.token();
2723 state.layerStack = 456u;
2724
2725 // --------------------------------------------------------------------
2726 // Invocation
2727
2728 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2729
2730 // --------------------------------------------------------------------
2731 // Postconditions
2732
2733 // The returned flags are empty
2734 EXPECT_EQ(0u, flags);
2735
2736 // The current display state is unchanged
2737 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2738}
2739
2740TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2741 using Case = SimplePrimaryDisplayCase;
2742
2743 // --------------------------------------------------------------------
2744 // Preconditions
2745
2746 // A display is set up
2747 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2748 display.inject();
2749
2750 // The display has a layer stack set
2751 display.mutableCurrentDisplayState().layerStack = 654u;
2752
2753 // The incoming request sets a different layer stack
2754 DisplayState state;
2755 state.what = DisplayState::eLayerStackChanged;
2756 state.token = display.token();
2757 state.layerStack = 456u;
2758
2759 // --------------------------------------------------------------------
2760 // Invocation
2761
2762 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2763
2764 // --------------------------------------------------------------------
2765 // Postconditions
2766
2767 // The returned flags indicate a transaction is needed
2768 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2769
2770 // The desired display state has been set to the new value.
2771 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2772}
2773
2774TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2775 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002776 constexpr ui::Rotation initialOrientation = ui::ROTATION_180;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002777 const Rect initialOrientedDisplayRect = {1, 2, 3, 4};
2778 const Rect initialLayerStackRect = {5, 6, 7, 8};
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002779
2780 // --------------------------------------------------------------------
2781 // Preconditions
2782
2783 // A display is set up
2784 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2785 display.inject();
2786
2787 // The current display state projection state is all set
2788 display.mutableCurrentDisplayState().orientation = initialOrientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002789 display.mutableCurrentDisplayState().orientedDisplaySpaceRect = initialOrientedDisplayRect;
2790 display.mutableCurrentDisplayState().layerStackSpaceRect = initialLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002791
2792 // The incoming request sets the same projection state
2793 DisplayState state;
2794 state.what = DisplayState::eDisplayProjectionChanged;
2795 state.token = display.token();
2796 state.orientation = initialOrientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002797 state.orientedDisplaySpaceRect = initialOrientedDisplayRect;
2798 state.layerStackSpaceRect = initialLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002799
2800 // --------------------------------------------------------------------
2801 // Invocation
2802
2803 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2804
2805 // --------------------------------------------------------------------
2806 // Postconditions
2807
2808 // The returned flags are empty
2809 EXPECT_EQ(0u, flags);
2810
2811 // The current display state is unchanged
2812 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2813
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002814 EXPECT_EQ(initialOrientedDisplayRect,
2815 display.getCurrentDisplayState().orientedDisplaySpaceRect);
2816 EXPECT_EQ(initialLayerStackRect, display.getCurrentDisplayState().layerStackSpaceRect);
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002817}
2818
2819TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2820 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002821 constexpr ui::Rotation initialOrientation = ui::ROTATION_90;
2822 constexpr ui::Rotation desiredOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002823
2824 // --------------------------------------------------------------------
2825 // Preconditions
2826
2827 // A display is set up
2828 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2829 display.inject();
2830
2831 // The current display state has an orientation set
2832 display.mutableCurrentDisplayState().orientation = initialOrientation;
2833
2834 // The incoming request sets a different orientation
2835 DisplayState state;
2836 state.what = DisplayState::eDisplayProjectionChanged;
2837 state.token = display.token();
2838 state.orientation = desiredOrientation;
2839
2840 // --------------------------------------------------------------------
2841 // Invocation
2842
2843 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2844
2845 // --------------------------------------------------------------------
2846 // Postconditions
2847
2848 // The returned flags indicate a transaction is needed
2849 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2850
2851 // The current display state has the new value.
2852 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2853}
2854
2855TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2856 using Case = SimplePrimaryDisplayCase;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002857 const Rect initialOrientedDisplayRect = {0, 0, 0, 0};
2858 const Rect desiredOrientedDisplayRect = {5, 6, 7, 8};
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002859
2860 // --------------------------------------------------------------------
2861 // Preconditions
2862
2863 // A display is set up
2864 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2865 display.inject();
2866
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002867 // The current display state does not have a orientedDisplaySpaceRect
2868 display.mutableCurrentDisplayState().orientedDisplaySpaceRect = initialOrientedDisplayRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002869
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002870 // The incoming request sets a orientedDisplaySpaceRect
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002871 DisplayState state;
2872 state.what = DisplayState::eDisplayProjectionChanged;
2873 state.token = display.token();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002874 state.orientedDisplaySpaceRect = desiredOrientedDisplayRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002875
2876 // --------------------------------------------------------------------
2877 // Invocation
2878
2879 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2880
2881 // --------------------------------------------------------------------
2882 // Postconditions
2883
2884 // The returned flags indicate a transaction is needed
2885 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2886
2887 // The current display state has the new value.
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002888 EXPECT_EQ(desiredOrientedDisplayRect,
2889 display.getCurrentDisplayState().orientedDisplaySpaceRect);
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002890}
2891
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002892TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackRectChanged) {
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002893 using Case = SimplePrimaryDisplayCase;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002894 const Rect initialLayerStackRect = {0, 0, 0, 0};
2895 const Rect desiredLayerStackRect = {5, 6, 7, 8};
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002896
2897 // --------------------------------------------------------------------
2898 // Preconditions
2899
2900 // A display is set up
2901 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2902 display.inject();
2903
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002904 // The current display state does not have a layerStackSpaceRect
2905 display.mutableCurrentDisplayState().layerStackSpaceRect = initialLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002906
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002907 // The incoming request sets a layerStackSpaceRect
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002908 DisplayState state;
2909 state.what = DisplayState::eDisplayProjectionChanged;
2910 state.token = display.token();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002911 state.layerStackSpaceRect = desiredLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002912
2913 // --------------------------------------------------------------------
2914 // Invocation
2915
2916 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2917
2918 // --------------------------------------------------------------------
2919 // Postconditions
2920
2921 // The returned flags indicate a transaction is needed
2922 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2923
2924 // The current display state has the new value.
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002925 EXPECT_EQ(desiredLayerStackRect, display.getCurrentDisplayState().layerStackSpaceRect);
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002926}
2927
2928TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2929 using Case = SimplePrimaryDisplayCase;
2930 constexpr uint32_t initialWidth = 1024;
2931 constexpr uint32_t initialHeight = 768;
2932
2933 // --------------------------------------------------------------------
2934 // Preconditions
2935
2936 // A display is set up
2937 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2938 display.inject();
2939
2940 // The current display state has a size set
2941 display.mutableCurrentDisplayState().width = initialWidth;
2942 display.mutableCurrentDisplayState().height = initialHeight;
2943
2944 // The incoming request sets the same display size
2945 DisplayState state;
2946 state.what = DisplayState::eDisplaySizeChanged;
2947 state.token = display.token();
2948 state.width = initialWidth;
2949 state.height = initialHeight;
2950
2951 // --------------------------------------------------------------------
2952 // Invocation
2953
2954 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2955
2956 // --------------------------------------------------------------------
2957 // Postconditions
2958
2959 // The returned flags are empty
2960 EXPECT_EQ(0u, flags);
2961
2962 // The current display state is unchanged
2963 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2964 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2965}
2966
2967TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
2968 using Case = SimplePrimaryDisplayCase;
2969 constexpr uint32_t initialWidth = 0;
2970 constexpr uint32_t desiredWidth = 1024;
2971
2972 // --------------------------------------------------------------------
2973 // Preconditions
2974
2975 // A display is set up
2976 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2977 display.inject();
2978
2979 // The display does not yet have a width
2980 display.mutableCurrentDisplayState().width = initialWidth;
2981
2982 // The incoming request sets a display width
2983 DisplayState state;
2984 state.what = DisplayState::eDisplaySizeChanged;
2985 state.token = display.token();
2986 state.width = desiredWidth;
2987
2988 // --------------------------------------------------------------------
2989 // Invocation
2990
2991 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2992
2993 // --------------------------------------------------------------------
2994 // Postconditions
2995
2996 // The returned flags indicate a transaction is needed
2997 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2998
2999 // The current display state has the new value.
3000 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
3001}
3002
3003TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
3004 using Case = SimplePrimaryDisplayCase;
3005 constexpr uint32_t initialHeight = 0;
3006 constexpr uint32_t desiredHeight = 768;
3007
3008 // --------------------------------------------------------------------
3009 // Preconditions
3010
3011 // A display is set up
3012 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3013 display.inject();
3014
3015 // The display does not yet have a height
3016 display.mutableCurrentDisplayState().height = initialHeight;
3017
3018 // The incoming request sets a display height
3019 DisplayState state;
3020 state.what = DisplayState::eDisplaySizeChanged;
3021 state.token = display.token();
3022 state.height = desiredHeight;
3023
3024 // --------------------------------------------------------------------
3025 // Invocation
3026
3027 uint32_t flags = mFlinger.setDisplayStateLocked(state);
3028
3029 // --------------------------------------------------------------------
3030 // Postconditions
3031
3032 // The returned flags indicate a transaction is needed
3033 EXPECT_EQ(eDisplayTransactionNeeded, flags);
3034
3035 // The current display state has the new value.
3036 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
3037}
3038
Lloyd Pique86016da2018-03-01 16:09:38 -08003039/* ------------------------------------------------------------------------
3040 * SurfaceFlinger::onInitializeDisplays
3041 */
3042
3043TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
3044 using Case = SimplePrimaryDisplayCase;
3045
3046 // --------------------------------------------------------------------
3047 // Preconditions
3048
3049 // A primary display is set up
3050 Case::Display::injectHwcDisplay(this);
3051 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
3052 primaryDisplay.inject();
3053
3054 // --------------------------------------------------------------------
3055 // Call Expectations
3056
3057 // We expect the surface interceptor to possibly be used, but we treat it as
3058 // disabled since it is called as a side effect rather than directly by this
3059 // function.
3060 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
3061
3062 // We expect a call to get the active display config.
3063 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
3064
3065 // We expect invalidate() to be invoked once to trigger display transaction
3066 // processing.
3067 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
3068
Ady Abraham8cb21882020-08-26 18:22:05 -07003069 EXPECT_CALL(*mVSyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003070
Lloyd Pique86016da2018-03-01 16:09:38 -08003071 // --------------------------------------------------------------------
3072 // Invocation
3073
3074 mFlinger.onInitializeDisplays();
3075
3076 // --------------------------------------------------------------------
3077 // Postconditions
3078
3079 // The primary display should have a current state
3080 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
3081 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
3082 // The layer stack state should be set to zero
3083 EXPECT_EQ(0u, primaryDisplayState.layerStack);
3084 // The orientation state should be set to zero
Dominik Laskowski718f9602019-11-09 20:01:35 -08003085 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
Lloyd Pique86016da2018-03-01 16:09:38 -08003086
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003087 // The orientedDisplaySpaceRect state should be set to INVALID
3088 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.orientedDisplaySpaceRect);
Lloyd Pique86016da2018-03-01 16:09:38 -08003089
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003090 // The layerStackSpaceRect state should be set to INVALID
3091 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.layerStackSpaceRect);
Lloyd Pique86016da2018-03-01 16:09:38 -08003092
3093 // The width and height should both be zero
3094 EXPECT_EQ(0u, primaryDisplayState.width);
3095 EXPECT_EQ(0u, primaryDisplayState.height);
3096
Peiyong Lin65248e02020-04-18 21:15:07 -07003097 // The display should be set to PowerMode::ON
Lloyd Pique86016da2018-03-01 16:09:38 -08003098 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
3099 auto displayDevice = primaryDisplay.mutableDisplayDevice();
Peiyong Lin65248e02020-04-18 21:15:07 -07003100 EXPECT_EQ(PowerMode::ON, displayDevice->getPowerMode());
Lloyd Pique86016da2018-03-01 16:09:38 -08003101
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003102 // The display refresh period should be set in the orientedDisplaySpaceRect tracker.
Lloyd Pique86016da2018-03-01 16:09:38 -08003103 FrameStats stats;
3104 mFlinger.getAnimFrameTracker().getStats(&stats);
3105 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
3106
3107 // The display transaction needed flag should be set.
3108 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
3109
3110 // The compositor timing should be set to default values
3111 const auto& compositorTiming = mFlinger.getCompositorTiming();
3112 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
3113 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
3114 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
3115}
3116
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003117/* ------------------------------------------------------------------------
3118 * SurfaceFlinger::setPowerModeInternal
3119 */
3120
3121// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07003122template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003123struct DozeIsSupportedVariant {
3124 static constexpr bool DOZE_SUPPORTED = true;
3125 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3126 IComposerClient::PowerMode::DOZE;
3127 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3128 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07003129
3130 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3131 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003132 .WillOnce(DoAll(SetArgPointee<1>(
3133 std::vector<DisplayCapability>({DisplayCapability::DOZE})),
Peiyong Lined531a32018-10-26 18:27:56 -07003134 Return(Error::NONE)));
3135 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003136};
3137
Peiyong Lined531a32018-10-26 18:27:56 -07003138template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003139// Used when we simulate a display that does not support doze.
3140struct DozeNotSupportedVariant {
3141 static constexpr bool DOZE_SUPPORTED = false;
3142 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3143 IComposerClient::PowerMode::ON;
3144 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3145 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07003146
3147 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3148 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003149 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Peiyong Lined531a32018-10-26 18:27:56 -07003150 Return(Error::NONE)));
3151 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003152};
3153
3154struct EventThreadBaseSupportedVariant {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003155 static void setupVsyncAndEventThreadNoCallExpectations(DisplayTransactionTest* test) {
3156 // The callback should not be notified to toggle VSYNC.
3157 EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(_)).Times(0);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003158
3159 // The event thread should not be notified.
3160 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
3161 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
3162 }
3163};
3164
3165struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
3166 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3167 // These calls are only expected for the primary display.
3168
3169 // Instead expect no calls.
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003170 setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003171 }
3172
3173 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3174 // These calls are only expected for the primary display.
3175
3176 // Instead expect no calls.
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003177 setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003178 }
3179};
3180
3181struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
3182 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003183 // The callback should be notified to enable VSYNC.
3184 EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(true)).Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003185
3186 // The event thread should be notified that the screen was acquired.
3187 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
3188 }
3189
3190 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003191 // The callback should be notified to disable VSYNC.
3192 EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(false)).Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003193
3194 // The event thread should not be notified that the screen was released.
3195 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
3196 }
3197};
3198
Lloyd Pique41be5d22018-06-21 13:11:48 -07003199struct DispSyncIsSupportedVariant {
Ady Abraham8cb21882020-08-26 18:22:05 -07003200 static void setupResetModelCallExpectations(DisplayTransactionTest* test) {
3201 EXPECT_CALL(*test->mVsyncController, startPeriodTransition(DEFAULT_REFRESH_RATE)).Times(1);
3202 EXPECT_CALL(*test->mVSyncTracker, resetModel()).Times(1);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003203 }
Lloyd Pique41be5d22018-06-21 13:11:48 -07003204};
3205
3206struct DispSyncNotSupportedVariant {
Ady Abraham8cb21882020-08-26 18:22:05 -07003207 static void setupResetModelCallExpectations(DisplayTransactionTest* /* test */) {}
Lloyd Pique41be5d22018-06-21 13:11:48 -07003208};
3209
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003210// --------------------------------------------------------------------
3211// Note:
3212//
3213// There are a large number of transitions we could test, however we only test a
3214// selected subset which provides complete test coverage of the implementation.
3215// --------------------------------------------------------------------
3216
Peiyong Lin65248e02020-04-18 21:15:07 -07003217template <PowerMode initialPowerMode, PowerMode targetPowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003218struct TransitionVariantCommon {
3219 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
3220 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
3221
3222 static void verifyPostconditions(DisplayTransactionTest*) {}
3223};
3224
Peiyong Lin65248e02020-04-18 21:15:07 -07003225struct TransitionOffToOnVariant : public TransitionVariantCommon<PowerMode::OFF, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003226 template <typename Case>
3227 static void setupCallExpectations(DisplayTransactionTest* test) {
3228 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3229 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Ady Abraham8cb21882020-08-26 18:22:05 -07003230 Case::DispSync::setupResetModelCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003231 Case::setupRepaintEverythingCallExpectations(test);
3232 }
3233
3234 static void verifyPostconditions(DisplayTransactionTest* test) {
3235 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3236 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3237 }
3238};
3239
3240struct TransitionOffToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003241 : public TransitionVariantCommon<PowerMode::OFF, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003242 template <typename Case>
3243 static void setupCallExpectations(DisplayTransactionTest* test) {
3244 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003245 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003246 Case::setupRepaintEverythingCallExpectations(test);
3247 }
3248
3249 static void verifyPostconditions(DisplayTransactionTest* test) {
3250 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3251 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3252 }
3253};
3254
Peiyong Lin65248e02020-04-18 21:15:07 -07003255struct TransitionOnToOffVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003256 template <typename Case>
3257 static void setupCallExpectations(DisplayTransactionTest* test) {
3258 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
3259 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3260 }
3261
3262 static void verifyPostconditions(DisplayTransactionTest* test) {
3263 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3264 }
3265};
3266
3267struct TransitionDozeSuspendToOffVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003268 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003269 template <typename Case>
3270 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003271 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003272 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3273 }
3274
3275 static void verifyPostconditions(DisplayTransactionTest* test) {
3276 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3277 }
3278};
3279
Peiyong Lin65248e02020-04-18 21:15:07 -07003280struct TransitionOnToDozeVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003281 template <typename Case>
3282 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003283 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003284 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3285 }
3286};
3287
3288struct TransitionDozeSuspendToDozeVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003289 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003290 template <typename Case>
3291 static void setupCallExpectations(DisplayTransactionTest* test) {
3292 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Ady Abraham8cb21882020-08-26 18:22:05 -07003293 Case::DispSync::setupResetModelCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003294 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3295 }
3296};
3297
Peiyong Lin65248e02020-04-18 21:15:07 -07003298struct TransitionDozeToOnVariant : public TransitionVariantCommon<PowerMode::DOZE, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003299 template <typename Case>
3300 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003301 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003302 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3303 }
3304};
3305
3306struct TransitionDozeSuspendToOnVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003307 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003308 template <typename Case>
3309 static void setupCallExpectations(DisplayTransactionTest* test) {
3310 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Ady Abraham8cb21882020-08-26 18:22:05 -07003311 Case::DispSync::setupResetModelCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003312 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3313 }
3314};
3315
3316struct TransitionOnToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003317 : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003318 template <typename Case>
3319 static void setupCallExpectations(DisplayTransactionTest* test) {
3320 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
3321 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3322 }
3323};
3324
3325struct TransitionOnToUnknownVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003326 : public TransitionVariantCommon<PowerMode::ON, static_cast<PowerMode>(POWER_MODE_LEET)> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003327 template <typename Case>
3328 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003329 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003330 Case::setupNoComposerPowerModeCallExpectations(test);
3331 }
3332};
3333
3334// --------------------------------------------------------------------
3335// Note:
3336//
3337// Rather than testing the cartesian product of of
3338// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3339// display type, and the other for another display type.
3340// --------------------------------------------------------------------
3341
3342template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003343 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003344struct DisplayPowerCase {
3345 using Display = DisplayVariant;
3346 using Doze = DozeVariant;
3347 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003348 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003349 using Transition = TransitionVariant;
3350
Peiyong Lin65248e02020-04-18 21:15:07 -07003351 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003352 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003353 auto display = Display::makeFakeExistingDisplayInjector(test);
3354 display.inject();
3355 display.mutableDisplayDevice()->setPowerMode(mode);
3356 return display;
3357 }
3358
3359 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003360 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003361 }
3362
3363 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3364 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3365 }
3366
Peiyong Lin65248e02020-04-18 21:15:07 -07003367 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test,
3368 PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003369 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
Peiyong Lin65248e02020-04-18 21:15:07 -07003370 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, static_cast<int32_t>(mode)))
3371 .Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003372 }
3373
Peiyong Lin65248e02020-04-18 21:15:07 -07003374 static void setupComposerCallExpectations(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003375 // Any calls to get the active config will return a default value.
3376 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3377 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3378 Return(Error::NONE)));
3379
3380 // Any calls to get whether the display supports dozing will return the value set by the
3381 // policy variant.
3382 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3383 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3384
3385 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3386 }
3387
3388 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3389 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3390 }
3391};
3392
3393// A sample configuration for the primary display.
3394// In addition to having event thread support, we emulate doze support.
3395template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003396using PrimaryDisplayPowerCase =
3397 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3398 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3399 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003400
3401// A sample configuration for the external display.
3402// In addition to not having event thread support, we emulate not having doze
3403// support.
3404template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003405using ExternalDisplayPowerCase =
3406 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3407 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3408 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003409
3410class SetPowerModeInternalTest : public DisplayTransactionTest {
3411public:
3412 template <typename Case>
3413 void transitionDisplayCommon();
3414};
3415
Peiyong Lin65248e02020-04-18 21:15:07 -07003416template <PowerMode PowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003417struct PowerModeInitialVSyncEnabled : public std::false_type {};
3418
3419template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003420struct PowerModeInitialVSyncEnabled<PowerMode::ON> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003421
3422template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003423struct PowerModeInitialVSyncEnabled<PowerMode::DOZE> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003424
3425template <typename Case>
3426void SetPowerModeInternalTest::transitionDisplayCommon() {
3427 // --------------------------------------------------------------------
3428 // Preconditions
3429
Peiyong Lined531a32018-10-26 18:27:56 -07003430 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003431 auto display =
3432 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3433 Case::setInitialPrimaryHWVsyncEnabled(this,
3434 PowerModeInitialVSyncEnabled<
3435 Case::Transition::INITIAL_POWER_MODE>::value);
3436
3437 // --------------------------------------------------------------------
3438 // Call Expectations
3439
3440 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3441 Case::Transition::template setupCallExpectations<Case>(this);
3442
3443 // --------------------------------------------------------------------
3444 // Invocation
3445
3446 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3447 Case::Transition::TARGET_POWER_MODE);
3448
3449 // --------------------------------------------------------------------
3450 // Postconditions
3451
3452 Case::Transition::verifyPostconditions(this);
3453}
3454
3455TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3456 using Case = SimplePrimaryDisplayCase;
3457
3458 // --------------------------------------------------------------------
3459 // Preconditions
3460
3461 // A primary display device is set up
3462 Case::Display::injectHwcDisplay(this);
3463 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3464 display.inject();
3465
Peiyong Lin65248e02020-04-18 21:15:07 -07003466 // The display is already set to PowerMode::ON
3467 display.mutableDisplayDevice()->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003468
3469 // --------------------------------------------------------------------
3470 // Invocation
3471
Peiyong Lin65248e02020-04-18 21:15:07 -07003472 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003473
3474 // --------------------------------------------------------------------
3475 // Postconditions
3476
Peiyong Lin65248e02020-04-18 21:15:07 -07003477 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003478}
3479
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003480TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003481 using Case = HwcVirtualDisplayCase;
3482
3483 // --------------------------------------------------------------------
3484 // Preconditions
3485
Dominik Laskowski075d3172018-05-24 15:50:06 -07003486 // Insert display data so that the HWC thinks it created the virtual display.
3487 const auto displayId = Case::Display::DISPLAY_ID::get();
3488 ASSERT_TRUE(displayId);
Dominik Laskowski1af47932018-11-12 10:20:46 -08003489 mFlinger.mutableHwcDisplayData().try_emplace(*displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003490
3491 // A virtual display device is set up
3492 Case::Display::injectHwcDisplay(this);
3493 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3494 display.inject();
3495
Peiyong Lin65248e02020-04-18 21:15:07 -07003496 // The display is set to PowerMode::ON
3497 getDisplayDevice(display.token())->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003498
3499 // --------------------------------------------------------------------
3500 // Invocation
3501
Peiyong Lin65248e02020-04-18 21:15:07 -07003502 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003503
3504 // --------------------------------------------------------------------
3505 // Postconditions
3506
Peiyong Lin65248e02020-04-18 21:15:07 -07003507 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003508}
3509
3510TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3511 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3512}
3513
3514TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3515 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3516}
3517
3518TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3519 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3520}
3521
3522TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3523 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3524}
3525
3526TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3527 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3528}
3529
3530TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3531 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3532}
3533
3534TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3535 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3536}
3537
3538TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3539 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3540}
3541
3542TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3543 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3544}
3545
3546TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3547 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3548}
3549
3550TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3551 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3552}
3553
3554TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3555 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3556}
3557
3558TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3559 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3560}
3561
3562TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3563 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3564}
3565
3566TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3567 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3568}
3569
3570TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3571 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3572}
3573
3574TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3575 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3576}
3577
3578TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3579 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3580}
3581
3582TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3583 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3584}
3585
3586TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3587 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3588}
3589
Lloyd Piquef58625d2017-12-19 13:22:33 -08003590} // namespace
3591} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08003592
3593// TODO(b/129481165): remove the #pragma below and fix conversion issues
3594#pragma clang diagnostic pop // ignored "-Wconversion"