blob: e055e959715e9d735f5888dfe3337d1f12ae9e35 [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>
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200341using HalVirtualDisplayIdType = std::integral_constant<uint64_t, displayId>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700342
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200343struct GpuVirtualDisplayIdType {};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700344
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>> {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200356 static 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());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200366 return info ? info->id : PhysicalDisplayId::fromPort(PhysicalDisplay::PORT);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700367 }
368};
369
Marin Shalamanova524a092020-07-27 21:39:55 +0200370template <uint64_t displayId>
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200371struct DisplayIdGetter<HalVirtualDisplayIdType<displayId>> {
372 static HalVirtualDisplayId get() { return HalVirtualDisplayId(displayId); }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700373};
374
375template <>
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200376struct DisplayIdGetter<GpuVirtualDisplayIdType> {
377 static GpuVirtualDisplayId get() { return GpuVirtualDisplayId(0); }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700378};
379
Dominik Laskowski55c85402020-01-21 16:25:47 -0800380template <typename>
381struct DisplayConnectionTypeGetter {
382 static constexpr std::optional<DisplayConnectionType> value;
383};
384
385template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200386struct DisplayConnectionTypeGetter<PhysicalDisplayIdType<PhysicalDisplay>> {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800387 static constexpr std::optional<DisplayConnectionType> value = PhysicalDisplay::CONNECTION_TYPE;
388};
389
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100390template <typename>
391struct HwcDisplayIdGetter {
Peiyong Line9d809e2020-04-14 13:10:48 -0700392 static constexpr std::optional<HWDisplayId> value;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100393};
394
Peiyong Line9d809e2020-04-14 13:10:48 -0700395constexpr HWDisplayId HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID = 1010;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100396
Marin Shalamanova524a092020-07-27 21:39:55 +0200397template <uint64_t displayId>
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200398struct HwcDisplayIdGetter<HalVirtualDisplayIdType<displayId>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700399 static constexpr std::optional<HWDisplayId> value = HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100400};
401
402template <typename PhysicalDisplay>
Marin Shalamanova524a092020-07-27 21:39:55 +0200403struct HwcDisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> {
Peiyong Line9d809e2020-04-14 13:10:48 -0700404 static constexpr std::optional<HWDisplayId> value = PhysicalDisplay::HWC_DISPLAY_ID;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100405};
406
Dominik Laskowski075d3172018-05-24 15:50:06 -0700407// DisplayIdType can be:
Marin Shalamanova524a092020-07-27 21:39:55 +0200408// 1) PhysicalDisplayIdType<...> for generated ID of physical display backed by HWC.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200409// 2) HalVirtualDisplayIdType<...> for hard-coded ID of virtual display backed by HWC.
410// 3) GpuVirtualDisplayIdType for virtual display without HWC backing.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700411template <typename DisplayIdType, int width, int height, Critical critical, Async async,
412 Secure secure, Primary primary, int grallocUsage>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800413struct DisplayVariant {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700414 using DISPLAY_ID = DisplayIdGetter<DisplayIdType>;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800415 using CONNECTION_TYPE = DisplayConnectionTypeGetter<DisplayIdType>;
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100416 using HWC_DISPLAY_ID_OPT = HwcDisplayIdGetter<DisplayIdType>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700417
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800418 // The display width and height
419 static constexpr int WIDTH = width;
420 static constexpr int HEIGHT = height;
421
422 static constexpr int GRALLOC_USAGE = grallocUsage;
423
Dominik Laskowski075d3172018-05-24 15:50:06 -0700424 // Whether the display is virtual or physical
425 static constexpr Virtual VIRTUAL =
426 IsPhysicalDisplayId<DisplayIdType>{} ? Virtual::FALSE : Virtual::TRUE;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800427
428 // When creating native window surfaces for the framebuffer, whether those should be critical
429 static constexpr Critical CRITICAL = critical;
430
431 // When creating native window surfaces for the framebuffer, whether those should be async
432 static constexpr Async ASYNC = async;
433
434 // Whether the display should be treated as secure
435 static constexpr Secure SECURE = secure;
436
Dominik Laskowski075d3172018-05-24 15:50:06 -0700437 // Whether the display is primary
438 static constexpr Primary PRIMARY = primary;
439
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800440 static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700441 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200442 if (auto displayId = PhysicalDisplayId::tryCast(DISPLAY_ID::get())) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700443 ceDisplayArgs.setPhysical({*displayId, DisplayConnectionType::Internal});
444 } else {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200445 // We turn off the use of HwcVirtualDisplays, to prevent Composition Engine
446 // from calling into HWComposer. This way all virtual displays will get
447 // a GpuVirtualDisplayId, even if we are in the HwcVirtualDisplayVariant.
448 // In this case we later override it by calling display.setDisplayIdForTesting().
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700449 ceDisplayArgs.setUseHwcVirtualDisplays(false);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200450
451 GpuVirtualDisplayId desiredDisplayId = GpuVirtualDisplayId::tryCast(DISPLAY_ID::get())
452 .value_or(GpuVirtualDisplayId(0));
453
454 ON_CALL(test->mFlinger.gpuVirtualDisplayIdGenerator(), nextId())
455 .WillByDefault(Return(desiredDisplayId));
456
457 auto& generator = test->mFlinger.gpuVirtualDisplayIdGenerator();
458 ceDisplayArgs.setGpuVirtualDisplayIdGenerator(generator);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700459 }
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200460 ceDisplayArgs.setPixels({WIDTH, HEIGHT}).setPowerAdvisor(&test->mPowerAdvisor);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700461
462 auto compositionDisplay =
463 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
464 ceDisplayArgs.build());
465
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200466 if (HalVirtualDisplayId::tryCast(DISPLAY_ID::get())) {
467 // CompositionEngine has assigned a placeholder GpuVirtualDisplayId and we need to
468 // override it with the correct HalVirtualDisplayId.
469 compositionDisplay->setDisplayIdForTesting(DISPLAY_ID::get());
470 }
471
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100472 auto injector = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
473 CONNECTION_TYPE::value, HWC_DISPLAY_ID_OPT::value,
474 static_cast<bool>(PRIMARY));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700475
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800476 injector.setSecure(static_cast<bool>(SECURE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700477 injector.setNativeWindow(test->mNativeWindow);
478
479 // Creating a DisplayDevice requires getting default dimensions from the
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800480 // native window along with some other initial setup.
Alec Mouriba013fa2018-10-16 12:43:11 -0700481 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
482 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
483 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
484 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800485 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
486 .WillRepeatedly(Return(0));
487 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
488 .WillRepeatedly(Return(0));
489 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
490 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700491 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
492 .WillRepeatedly(Return(0));
493
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800494 return injector;
495 }
496
497 // Called by tests to set up any native window creation call expectations.
498 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
499 EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow())
500 .WillOnce(Return(test->mNativeWindow));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800501
Alec Mouriba013fa2018-10-16 12:43:11 -0700502 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
503 .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
504 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
505 .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800506 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT))
507 .WillRepeatedly(Return(0));
508 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT))
509 .WillRepeatedly(Return(0));
510 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64))
511 .WillRepeatedly(Return(0));
chaviw8beb4142019-04-11 13:09:05 -0700512 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT))
513 .WillRepeatedly(Return(0));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800514 }
515
516 static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
517 EXPECT_CALL(*test->mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
518 EXPECT_CALL(*test->mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
519 EXPECT_CALL(*test->mConsumer, setConsumerUsageBits(GRALLOC_USAGE))
520 .WillRepeatedly(Return(NO_ERROR));
521 EXPECT_CALL(*test->mConsumer, setDefaultBufferSize(WIDTH, HEIGHT))
522 .WillRepeatedly(Return(NO_ERROR));
523 EXPECT_CALL(*test->mConsumer, setMaxAcquiredBufferCount(_))
524 .WillRepeatedly(Return(NO_ERROR));
525 }
526
527 static void setupFramebufferProducerBufferQueueCallExpectations(DisplayTransactionTest* test) {
528 EXPECT_CALL(*test->mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
529 }
530};
531
Peiyong Line9d809e2020-04-14 13:10:48 -0700532template <HWDisplayId hwcDisplayId, DisplayType hwcDisplayType, typename DisplayVariant,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700533 typename PhysicalDisplay = void>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800534struct HwcDisplayVariant {
535 // The display id supplied by the HWC
Peiyong Line9d809e2020-04-14 13:10:48 -0700536 static constexpr HWDisplayId HWC_DISPLAY_ID = hwcDisplayId;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800537
538 // The HWC display type
Peiyong Line9d809e2020-04-14 13:10:48 -0700539 static constexpr DisplayType HWC_DISPLAY_TYPE = hwcDisplayType;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800540
541 // The HWC active configuration id
Lloyd Pique3c085a02018-05-09 19:38:32 -0700542 static constexpr int HWC_ACTIVE_CONFIG_ID = 2001;
Peiyong Lin65248e02020-04-18 21:15:07 -0700543 static constexpr PowerMode INIT_POWER_MODE = PowerMode::ON;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800544
Peiyong Line9d809e2020-04-14 13:10:48 -0700545 static void injectPendingHotplugEvent(DisplayTransactionTest* test, Connection connection) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800546 test->mFlinger.mutablePendingHotplugEvents().emplace_back(
547 HotplugEvent{HWC_DISPLAY_ID, connection});
548 }
549
550 // Called by tests to inject a HWC display setup
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800551 static void injectHwcDisplayWithNoDefaultCapabilities(DisplayTransactionTest* test) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700552 const auto displayId = DisplayVariant::DISPLAY_ID::get();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200553 ASSERT_FALSE(GpuVirtualDisplayId::tryCast(displayId));
554 FakeHwcDisplayInjector(displayId, HWC_DISPLAY_TYPE,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700555 static_cast<bool>(DisplayVariant::PRIMARY))
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800556 .setHwcDisplayId(HWC_DISPLAY_ID)
557 .setWidth(DisplayVariant::WIDTH)
558 .setHeight(DisplayVariant::HEIGHT)
559 .setActiveConfig(HWC_ACTIVE_CONFIG_ID)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700560 .setPowerMode(INIT_POWER_MODE)
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800561 .inject(&test->mFlinger, test->mComposer);
562 }
563
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800564 // Called by tests to inject a HWC display setup
565 static void injectHwcDisplay(DisplayTransactionTest* test) {
566 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700567 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800568 Return(Error::NONE)));
Peiyong Lin65248e02020-04-18 21:15:07 -0700569 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY_ID, INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700570 .WillOnce(Return(Error::NONE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800571 injectHwcDisplayWithNoDefaultCapabilities(test);
572 }
573
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700574 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
575 DisplayTransactionTest* test) {
576 const ::testing::TestInfo* const test_info =
577 ::testing::UnitTest::GetInstance()->current_test_info();
578
579 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200580 .setPhysical({DisplayVariant::DISPLAY_ID::get(),
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700581 PhysicalDisplay::CONNECTION_TYPE})
582 .setPixels({DisplayVariant::WIDTH, DisplayVariant::HEIGHT})
583 .setIsSecure(static_cast<bool>(DisplayVariant::SECURE))
584 .setPowerAdvisor(&test->mPowerAdvisor)
585 .setName(std::string("Injected display for ") +
586 test_info->test_case_name() + "." + test_info->name())
587 .build();
588
589 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
590 ceDisplayArgs);
591 }
592
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800593 static void setupHwcHotplugCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800594 constexpr auto CONNECTION_TYPE =
595 PhysicalDisplay::CONNECTION_TYPE == DisplayConnectionType::Internal
596 ? IComposerClient::DisplayConnectionType::INTERNAL
597 : IComposerClient::DisplayConnectionType::EXTERNAL;
598
599 EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -0700600 .WillOnce(DoAll(SetArgPointee<1>(CONNECTION_TYPE), Return(hal::V2_4::Error::NONE)));
Dominik Laskowski55c85402020-01-21 16:25:47 -0800601
Peiyong Line9d809e2020-04-14 13:10:48 -0700602 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_))
603 .WillOnce(Return(hal::Error::NONE));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800604 EXPECT_CALL(*test->mComposer, getDisplayConfigs(HWC_DISPLAY_ID, _))
605 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{HWC_ACTIVE_CONFIG_ID}),
606 Return(Error::NONE)));
607 EXPECT_CALL(*test->mComposer,
608 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
609 IComposerClient::Attribute::WIDTH, _))
610 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::WIDTH), Return(Error::NONE)));
611 EXPECT_CALL(*test->mComposer,
612 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
613 IComposerClient::Attribute::HEIGHT, _))
614 .WillOnce(DoAll(SetArgPointee<3>(DisplayVariant::HEIGHT), Return(Error::NONE)));
615 EXPECT_CALL(*test->mComposer,
616 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
617 IComposerClient::Attribute::VSYNC_PERIOD, _))
618 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
619 EXPECT_CALL(*test->mComposer,
620 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
621 IComposerClient::Attribute::DPI_X, _))
622 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
623 EXPECT_CALL(*test->mComposer,
624 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
625 IComposerClient::Attribute::DPI_Y, _))
626 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
Ady Abraham7159f572019-10-11 11:10:18 -0700627 EXPECT_CALL(*test->mComposer,
628 getDisplayAttribute(HWC_DISPLAY_ID, HWC_ACTIVE_CONFIG_ID,
629 IComposerClient::Attribute::CONFIG_GROUP, _))
630 .WillOnce(DoAll(SetArgPointee<3>(-1), Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700631
632 if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
633 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200634 .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
635 SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
636 Return(Error::NONE)));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700637 } else {
638 EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _))
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200639 .WillOnce(Return(Error::UNSUPPORTED));
Dominik Laskowski075d3172018-05-24 15:50:06 -0700640 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800641 }
642
643 // Called by tests to set up HWC call expectations
644 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
645 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY_ID, _))
Lloyd Pique3c085a02018-05-09 19:38:32 -0700646 .WillRepeatedly(DoAll(SetArgPointee<1>(HWC_ACTIVE_CONFIG_ID), Return(Error::NONE)));
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800647 }
648};
649
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800650// Physical displays are expected to be synchronous, secure, and have a HWC display for output.
651constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =
652 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
653
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100654template <typename PhysicalDisplay, int width, int height, Critical critical>
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800655struct PhysicalDisplayVariant
Marin Shalamanova524a092020-07-27 21:39:55 +0200656 : DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, critical,
657 Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY,
658 GRALLOC_USAGE_PHYSICAL_DISPLAY>,
Peiyong Line9d809e2020-04-14 13:10:48 -0700659 HwcDisplayVariant<PhysicalDisplay::HWC_DISPLAY_ID, DisplayType::PHYSICAL,
Marin Shalamanova524a092020-07-27 21:39:55 +0200660 DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700661 critical, Async::FALSE, Secure::TRUE,
662 PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>,
663 PhysicalDisplay> {};
664
665template <bool hasIdentificationData>
666struct PrimaryDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800667 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::Internal;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700668 static constexpr Primary PRIMARY = Primary::TRUE;
669 static constexpr uint8_t PORT = 255;
Peiyong Line9d809e2020-04-14 13:10:48 -0700670 static constexpr HWDisplayId HWC_DISPLAY_ID = 1001;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700671 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
672 static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
673};
674
675template <bool hasIdentificationData>
676struct ExternalDisplay {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800677 static constexpr auto CONNECTION_TYPE = DisplayConnectionType::External;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700678 static constexpr Primary PRIMARY = Primary::FALSE;
679 static constexpr uint8_t PORT = 254;
Peiyong Line9d809e2020-04-14 13:10:48 -0700680 static constexpr HWDisplayId HWC_DISPLAY_ID = 1002;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700681 static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
682 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
683};
684
685struct TertiaryDisplay {
686 static constexpr Primary PRIMARY = Primary::FALSE;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800687 static constexpr uint8_t PORT = 253;
Peiyong Line9d809e2020-04-14 13:10:48 -0700688 static constexpr HWDisplayId HWC_DISPLAY_ID = 1003;
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800689 static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700690};
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800691
692// A primary display is a physical display that is critical
693using PrimaryDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100694 PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160, Critical::TRUE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800695
696// An external display is physical display that is not critical.
697using ExternalDisplayVariant =
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100698 PhysicalDisplayVariant<ExternalDisplay<false>, 1920, 1280, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800699
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100700using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay, 1600, 1200, Critical::FALSE>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800701
702// A virtual display not supported by the HWC.
703constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
704
705template <int width, int height, Secure secure>
706struct NonHwcVirtualDisplayVariant
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200707 : DisplayVariant<GpuVirtualDisplayIdType, width, height, Critical::FALSE, Async::TRUE, secure,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700708 Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY> {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200709 using Base =
710 DisplayVariant<GpuVirtualDisplayIdType, width, height, Critical::FALSE, Async::TRUE,
711 secure, Primary::FALSE, GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY>;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700712
713 static void injectHwcDisplay(DisplayTransactionTest*) {}
714
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700715 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
716 DisplayTransactionTest* test) {
717 const ::testing::TestInfo* const test_info =
718 ::testing::UnitTest::GetInstance()->current_test_info();
719
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200720 ON_CALL(test->mFlinger.gpuVirtualDisplayIdGenerator(), nextId())
721 .WillByDefault(Return(Base::DISPLAY_ID::get()));
722
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700723 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
724 .setPixels({Base::WIDTH, Base::HEIGHT})
725 .setIsSecure(static_cast<bool>(Base::SECURE))
726 .setPowerAdvisor(&test->mPowerAdvisor)
727 .setName(std::string("Injected display for ") +
728 test_info->test_case_name() + "." + test_info->name())
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200729 .setGpuVirtualDisplayIdGenerator(
730 test->mFlinger.gpuVirtualDisplayIdGenerator())
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700731 .build();
732
733 return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
734 ceDisplayArgs);
735 }
736
Dominik Laskowski075d3172018-05-24 15:50:06 -0700737 static void setupHwcGetActiveConfigCallExpectations(DisplayTransactionTest* test) {
738 EXPECT_CALL(*test->mComposer, getActiveConfig(_, _)).Times(0);
739 }
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800740
741 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
742 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
743 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
744 }
745};
746
747// A virtual display supported by the HWC.
748constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER;
749
750template <int width, int height, Secure secure>
751struct HwcVirtualDisplayVariant
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200752 : DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE, Async::TRUE,
Marin Shalamanova524a092020-07-27 21:39:55 +0200753 secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>,
754 HwcDisplayVariant<HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200755 DisplayVariant<HalVirtualDisplayIdType<42>, width, height,
756 Critical::FALSE, Async::TRUE, secure, Primary::FALSE,
Marin Shalamanova524a092020-07-27 21:39:55 +0200757 GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200758 using Base = DisplayVariant<HalVirtualDisplayIdType<42>, width, height, Critical::FALSE,
Marin Shalamanova524a092020-07-27 21:39:55 +0200759 Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800760 using Self = HwcVirtualDisplayVariant<width, height, secure>;
761
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700762 static std::shared_ptr<compositionengine::Display> injectCompositionDisplay(
763 DisplayTransactionTest* test) {
764 const ::testing::TestInfo* const test_info =
765 ::testing::UnitTest::GetInstance()->current_test_info();
766
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200767 // In order to prevent compostition engine calling into HWComposer, we
768 // 1. turn off the use of HWC virtual displays,
769 // 2. provide a GpuVirtualDisplayIdGenerator which always returns some fake ID
770 // 3. override the ID by calling setDisplayIdForTesting()
771
772 ON_CALL(test->mFlinger.gpuVirtualDisplayIdGenerator(), nextId())
773 .WillByDefault(Return(GpuVirtualDisplayId(0)));
774
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700775 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
776 .setUseHwcVirtualDisplays(false)
777 .setPixels({Base::WIDTH, Base::HEIGHT})
778 .setIsSecure(static_cast<bool>(Base::SECURE))
779 .setPowerAdvisor(&test->mPowerAdvisor)
780 .setName(std::string("Injected display for ") +
781 test_info->test_case_name() + "." + test_info->name())
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200782 .setGpuVirtualDisplayIdGenerator(
783 test->mFlinger.gpuVirtualDisplayIdGenerator())
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700784 .build();
785
786 auto compositionDisplay =
787 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
788 ceDisplayArgs);
789 compositionDisplay->setDisplayIdForTesting(Base::DISPLAY_ID::get());
790
791 // Insert display data so that the HWC thinks it created the virtual display.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200792 if (const auto displayId = Base::DISPLAY_ID::get();
793 HalVirtualDisplayId::tryCast(displayId)) {
794 test->mFlinger.mutableHwcDisplayData().try_emplace(displayId);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700795 }
796
797 return compositionDisplay;
798 }
799
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800800 static void setupNativeWindowSurfaceCreationCallExpectations(DisplayTransactionTest* test) {
801 Base::setupNativeWindowSurfaceCreationCallExpectations(test);
802 EXPECT_CALL(*test->mNativeWindow, setSwapInterval(0)).Times(1);
803 }
804
805 static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) {
806 EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _))
807 .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE)));
808 EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
809 }
810};
811
812// For this variant, SurfaceFlinger should not configure itself with wide
813// display support, so the display should not be configured for wide-color
814// support.
815struct WideColorSupportNotConfiguredVariant {
816 static constexpr bool WIDE_COLOR_SUPPORTED = false;
817
818 static void injectConfigChange(DisplayTransactionTest* test) {
819 test->mFlinger.mutableHasWideColorDisplay() = false;
Peiyong Lin13effd12018-07-24 17:01:47 -0700820 test->mFlinger.mutableUseColorManagement() = false;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800821 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800822 }
823
824 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
825 EXPECT_CALL(*test->mComposer, getColorModes(_, _)).Times(0);
826 EXPECT_CALL(*test->mComposer, getRenderIntents(_, _, _)).Times(0);
827 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
828 }
829};
830
831// For this variant, SurfaceFlinger should configure itself with wide display
832// support, and the display should respond with an non-empty list of supported
833// color modes. Wide-color support should be configured.
834template <typename Display>
835struct WideColorP3ColorimetricSupportedVariant {
836 static constexpr bool WIDE_COLOR_SUPPORTED = true;
837
838 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700839 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800840 test->mFlinger.mutableHasWideColorDisplay() = true;
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800841 test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800842 }
843
844 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800845 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_DATASPACE)).Times(1);
846
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800847 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
848 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>({ColorMode::DISPLAY_P3})),
849 Return(Error::NONE)));
850 EXPECT_CALL(*test->mComposer,
851 getRenderIntents(Display::HWC_DISPLAY_ID, ColorMode::DISPLAY_P3, _))
852 .WillOnce(DoAll(SetArgPointee<2>(
853 std::vector<RenderIntent>({RenderIntent::COLORIMETRIC})),
854 Return(Error::NONE)));
855 EXPECT_CALL(*test->mComposer,
856 setColorMode(Display::HWC_DISPLAY_ID, ColorMode::SRGB,
857 RenderIntent::COLORIMETRIC))
858 .WillOnce(Return(Error::NONE));
859 }
860};
861
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800862// For this variant, SurfaceFlinger should configure itself with wide display
863// support, but the display should respond with an empty list of supported color
864// modes. Wide-color support for the display should not be configured.
865template <typename Display>
866struct WideColorNotSupportedVariant {
867 static constexpr bool WIDE_COLOR_SUPPORTED = false;
868
869 static void injectConfigChange(DisplayTransactionTest* test) {
Peiyong Lin13effd12018-07-24 17:01:47 -0700870 test->mFlinger.mutableUseColorManagement() = true;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800871 test->mFlinger.mutableHasWideColorDisplay() = true;
872 }
873
874 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
875 EXPECT_CALL(*test->mComposer, getColorModes(Display::HWC_DISPLAY_ID, _))
876 .WillOnce(DoAll(SetArgPointee<1>(std::vector<ColorMode>()), Return(Error::NONE)));
Chia-I Wu614e1422018-05-23 02:17:03 -0700877 EXPECT_CALL(*test->mComposer, setColorMode(_, _, _)).Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800878 }
879};
880
881// For this variant, the display is not a HWC display, so no HDR support should
882// be configured.
883struct NonHwcDisplayHdrSupportVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800884 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800885 static constexpr bool HDR10_SUPPORTED = false;
886 static constexpr bool HDR_HLG_SUPPORTED = false;
887 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
888 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
889 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _)).Times(0);
890 }
891};
892
Valerie Haue9e843a2018-12-18 13:39:23 -0800893template <typename Display>
894struct Hdr10PlusSupportedVariant {
895 static constexpr bool HDR10_PLUS_SUPPORTED = true;
896 static constexpr bool HDR10_SUPPORTED = true;
897 static constexpr bool HDR_HLG_SUPPORTED = false;
898 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
899 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
900 EXPECT_CALL(*test->mComposer, getHdrCapabilities(_, _, _, _, _))
901 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({
902 Hdr::HDR10_PLUS,
903 Hdr::HDR10,
904 })),
905 Return(Error::NONE)));
906 }
907};
908
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800909// For this variant, the composer should respond with a non-empty list of HDR
910// modes containing HDR10, so HDR10 support should be configured.
911template <typename Display>
912struct Hdr10SupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800913 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800914 static constexpr bool HDR10_SUPPORTED = true;
915 static constexpr bool HDR_HLG_SUPPORTED = false;
916 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
917 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
918 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
919 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HDR10})),
920 Return(Error::NONE)));
921 }
922};
923
924// For this variant, the composer should respond with a non-empty list of HDR
925// modes containing HLG, so HLG support should be configured.
926template <typename Display>
927struct HdrHlgSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800928 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800929 static constexpr bool HDR10_SUPPORTED = false;
930 static constexpr bool HDR_HLG_SUPPORTED = true;
931 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
932 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
933 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
934 .WillOnce(
935 DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::HLG})), Return(Error::NONE)));
936 }
937};
938
939// For this variant, the composer should respond with a non-empty list of HDR
940// modes containing DOLBY_VISION, so DOLBY_VISION support should be configured.
941template <typename Display>
942struct HdrDolbyVisionSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800943 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800944 static constexpr bool HDR10_SUPPORTED = false;
945 static constexpr bool HDR_HLG_SUPPORTED = false;
946 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = true;
947 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
948 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
949 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>({Hdr::DOLBY_VISION})),
950 Return(Error::NONE)));
951 }
952};
953
954// For this variant, the composer should respond with am empty list of HDR
955// modes, so no HDR support should be configured.
956template <typename Display>
957struct HdrNotSupportedVariant {
Valerie Haue9e843a2018-12-18 13:39:23 -0800958 static constexpr bool HDR10_PLUS_SUPPORTED = false;
Lloyd Piquec11e0d32018-01-22 18:44:59 -0800959 static constexpr bool HDR10_SUPPORTED = false;
960 static constexpr bool HDR_HLG_SUPPORTED = false;
961 static constexpr bool HDR_DOLBY_VISION_SUPPORTED = false;
962 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
963 EXPECT_CALL(*test->mComposer, getHdrCapabilities(Display::HWC_DISPLAY_ID, _, _, _, _))
964 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
965 }
966};
967
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700968struct NonHwcPerFrameMetadataSupportVariant {
969 static constexpr int PER_FRAME_METADATA_KEYS = 0;
970 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800971 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(_)).Times(0);
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700972 }
973};
974
975template <typename Display>
976struct NoPerFrameMetadataSupportVariant {
977 static constexpr int PER_FRAME_METADATA_KEYS = 0;
978 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800979 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
980 .WillOnce(Return(std::vector<PerFrameMetadataKey>()));
Lloyd Piqued883d5a2018-04-27 19:32:30 -0700981 }
982};
983
984template <typename Display>
985struct Smpte2086PerFrameMetadataSupportVariant {
986 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::SMPTE2086;
987 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +0800988 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
989 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -0800990 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X,
991 PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y,
992 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X,
993 PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y,
994 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X,
995 PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y,
996 PerFrameMetadataKey::WHITE_POINT_X,
997 PerFrameMetadataKey::WHITE_POINT_Y,
998 PerFrameMetadataKey::MAX_LUMINANCE,
999 PerFrameMetadataKey::MIN_LUMINANCE,
1000 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001001 }
1002};
1003
1004template <typename Display>
1005struct Cta861_3_PerFrameMetadataSupportVariant {
1006 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::CTA861_3;
1007 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
Chia-I Wud7e01d72018-06-21 13:39:09 +08001008 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
1009 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
Valerie Haue9e843a2018-12-18 13:39:23 -08001010 PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL,
1011 PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL,
1012 })));
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001013 }
1014};
1015
Valerie Haue9e843a2018-12-18 13:39:23 -08001016template <typename Display>
1017struct Hdr10_Plus_PerFrameMetadataSupportVariant {
1018 static constexpr int PER_FRAME_METADATA_KEYS = HdrMetadata::Type::HDR10PLUS;
1019 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
1020 EXPECT_CALL(*test->mComposer, getPerFrameMetadataKeys(Display::HWC_DISPLAY_ID))
1021 .WillOnce(Return(std::vector<PerFrameMetadataKey>({
1022 PerFrameMetadataKey::HDR10_PLUS_SEI,
1023 })));
1024 }
1025};
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001026/* ------------------------------------------------------------------------
1027 * Typical display configurations to test
1028 */
1029
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001030template <typename DisplayPolicy, typename WideColorSupportPolicy, typename HdrSupportPolicy,
1031 typename PerFrameMetadataSupportPolicy>
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001032struct Case {
1033 using Display = DisplayPolicy;
1034 using WideColorSupport = WideColorSupportPolicy;
1035 using HdrSupport = HdrSupportPolicy;
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001036 using PerFrameMetadataSupport = PerFrameMetadataSupportPolicy;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001037};
1038
1039using SimplePrimaryDisplayCase =
1040 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001041 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1042 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001043using SimpleExternalDisplayCase =
1044 Case<ExternalDisplayVariant, WideColorNotSupportedVariant<ExternalDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001045 HdrNotSupportedVariant<ExternalDisplayVariant>,
1046 NoPerFrameMetadataSupportVariant<ExternalDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001047using SimpleTertiaryDisplayCase =
1048 Case<TertiaryDisplayVariant, WideColorNotSupportedVariant<TertiaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001049 HdrNotSupportedVariant<TertiaryDisplayVariant>,
1050 NoPerFrameMetadataSupportVariant<TertiaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001051using NonHwcVirtualDisplayCase =
1052 Case<NonHwcVirtualDisplayVariant<1024, 768, Secure::FALSE>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001053 WideColorSupportNotConfiguredVariant, NonHwcDisplayHdrSupportVariant,
1054 NonHwcPerFrameMetadataSupportVariant>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001055using SimpleHwcVirtualDisplayVariant = HwcVirtualDisplayVariant<1024, 768, Secure::TRUE>;
1056using HwcVirtualDisplayCase =
1057 Case<SimpleHwcVirtualDisplayVariant, WideColorSupportNotConfiguredVariant,
Lloyd Pique438e9e72018-09-04 18:06:08 -07001058 HdrNotSupportedVariant<SimpleHwcVirtualDisplayVariant>,
tangrobin6753a022018-08-10 10:58:54 +08001059 NoPerFrameMetadataSupportVariant<SimpleHwcVirtualDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001060using WideColorP3ColorimetricDisplayCase =
1061 Case<PrimaryDisplayVariant, WideColorP3ColorimetricSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001062 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1063 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Valerie Haue9e843a2018-12-18 13:39:23 -08001064using Hdr10PlusDisplayCase =
1065 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1066 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1067 Hdr10_Plus_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001068using Hdr10DisplayCase =
1069 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001070 Hdr10SupportedVariant<PrimaryDisplayVariant>,
1071 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001072using HdrHlgDisplayCase =
1073 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001074 HdrHlgSupportedVariant<PrimaryDisplayVariant>,
1075 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001076using HdrDolbyVisionDisplayCase =
1077 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001078 HdrDolbyVisionSupportedVariant<PrimaryDisplayVariant>,
1079 NoPerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1080using HdrSmpte2086DisplayCase =
1081 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1082 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1083 Smpte2086PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
1084using HdrCta861_3_DisplayCase =
1085 Case<PrimaryDisplayVariant, WideColorNotSupportedVariant<PrimaryDisplayVariant>,
1086 HdrNotSupportedVariant<PrimaryDisplayVariant>,
1087 Cta861_3_PerFrameMetadataSupportVariant<PrimaryDisplayVariant>>;
Dominik Laskowskif07b85b2018-06-11 12:49:15 -07001088
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001089/* ------------------------------------------------------------------------
Lloyd Pique6cf11032018-01-22 18:57:44 -08001090 *
1091 * SurfaceFlinger::onHotplugReceived
1092 */
1093
1094TEST_F(DisplayTransactionTest, hotplugEnqueuesEventsForDisplayTransaction) {
1095 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001096 constexpr HWDisplayId hwcDisplayId1 = 456;
1097 constexpr HWDisplayId hwcDisplayId2 = 654;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001098
1099 // --------------------------------------------------------------------
1100 // Preconditions
1101
1102 // Set the current sequence id for accepted events
1103 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1104
1105 // Set the main thread id so that the current thread does not appear to be
1106 // the main thread.
1107 mFlinger.mutableMainThreadId() = std::thread::id();
1108
1109 // --------------------------------------------------------------------
1110 // Call Expectations
1111
1112 // We expect invalidate() to be invoked once to trigger display transaction
1113 // processing.
1114 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1115
1116 // --------------------------------------------------------------------
1117 // Invocation
1118
1119 // Simulate two hotplug events (a connect and a disconnect)
Peiyong Line9d809e2020-04-14 13:10:48 -07001120 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, Connection::CONNECTED);
1121 mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001122
1123 // --------------------------------------------------------------------
1124 // Postconditions
1125
1126 // The display transaction needed flag should be set.
1127 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1128
1129 // All events should be in the pending event queue.
1130 const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents();
1131 ASSERT_EQ(2u, pendingEvents.size());
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001132 EXPECT_EQ(hwcDisplayId1, pendingEvents[0].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001133 EXPECT_EQ(Connection::CONNECTED, pendingEvents[0].connection);
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001134 EXPECT_EQ(hwcDisplayId2, pendingEvents[1].hwcDisplayId);
Peiyong Line9d809e2020-04-14 13:10:48 -07001135 EXPECT_EQ(Connection::DISCONNECTED, pendingEvents[1].connection);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001136}
1137
1138TEST_F(DisplayTransactionTest, hotplugDiscardsUnexpectedEvents) {
1139 constexpr int currentSequenceId = 123;
1140 constexpr int otherSequenceId = 321;
Peiyong Line9d809e2020-04-14 13:10:48 -07001141 constexpr HWDisplayId displayId = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001142
1143 // --------------------------------------------------------------------
1144 // Preconditions
1145
1146 // Set the current sequence id for accepted events
1147 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1148
1149 // Set the main thread id so that the current thread does not appear to be
1150 // the main thread.
1151 mFlinger.mutableMainThreadId() = std::thread::id();
1152
1153 // --------------------------------------------------------------------
1154 // Call Expectations
1155
1156 // We do not expect any calls to invalidate().
1157 EXPECT_CALL(*mMessageQueue, invalidate()).Times(0);
1158
1159 // --------------------------------------------------------------------
1160 // Invocation
1161
1162 // Call with an unexpected sequence id
Peiyong Line9d809e2020-04-14 13:10:48 -07001163 mFlinger.onHotplugReceived(otherSequenceId, displayId, Connection::INVALID);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001164
1165 // --------------------------------------------------------------------
1166 // Postconditions
1167
1168 // The display transaction needed flag should not be set
1169 EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1170
1171 // There should be no pending events
1172 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1173}
1174
1175TEST_F(DisplayTransactionTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) {
1176 constexpr int currentSequenceId = 123;
Peiyong Line9d809e2020-04-14 13:10:48 -07001177 constexpr HWDisplayId displayId1 = 456;
Lloyd Pique6cf11032018-01-22 18:57:44 -08001178
1179 // --------------------------------------------------------------------
1180 // Note:
1181 // --------------------------------------------------------------------
1182 // This test case is a bit tricky. We want to verify that
1183 // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we
1184 // don't really want to provide coverage for everything the later function
1185 // does as there are specific tests for it.
1186 // --------------------------------------------------------------------
1187
1188 // --------------------------------------------------------------------
1189 // Preconditions
1190
1191 // Set the current sequence id for accepted events
1192 mFlinger.mutableComposerSequenceId() = currentSequenceId;
1193
1194 // Set the main thread id so that the current thread does appear to be the
1195 // main thread.
1196 mFlinger.mutableMainThreadId() = std::this_thread::get_id();
1197
1198 // --------------------------------------------------------------------
1199 // Call Expectations
1200
1201 // We expect invalidate() to be invoked once to trigger display transaction
1202 // processing.
1203 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1204
1205 // --------------------------------------------------------------------
1206 // Invocation
1207
1208 // Simulate a disconnect on a display id that is not connected. This should
1209 // be enqueued by onHotplugReceived(), and dequeued by
1210 // processDisplayHotplugEventsLocked(), but then ignored as invalid.
Peiyong Line9d809e2020-04-14 13:10:48 -07001211 mFlinger.onHotplugReceived(currentSequenceId, displayId1, Connection::DISCONNECTED);
Lloyd Pique6cf11032018-01-22 18:57:44 -08001212
1213 // --------------------------------------------------------------------
1214 // Postconditions
1215
1216 // The display transaction needed flag should be set.
1217 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1218
1219 // There should be no event queued on return, as it should have been
1220 // processed.
1221 EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty());
1222}
1223
1224/* ------------------------------------------------------------------------
Lloyd Piquea482f992018-01-22 19:00:34 -08001225 * SurfaceFlinger::createDisplay
1226 */
1227
1228TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
1229 const String8 name("virtual.test");
1230
1231 // --------------------------------------------------------------------
1232 // Call Expectations
1233
1234 // The call should notify the interceptor that a display was created.
1235 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1236
1237 // --------------------------------------------------------------------
1238 // Invocation
1239
1240 sp<IBinder> displayToken = mFlinger.createDisplay(name, false);
1241
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_FALSE(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
1259TEST_F(DisplayTransactionTest, createDisplaySetsCurrentStateForSecureDisplay) {
1260 const String8 name("virtual.test");
1261
1262 // --------------------------------------------------------------------
1263 // Call Expectations
1264
1265 // The call should notify the interceptor that a display was created.
1266 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
1267
1268 // --------------------------------------------------------------------
1269 // Invocation
chaviwd4a61642020-09-01 14:53:46 -07001270 int64_t oldId = IPCThreadState::self()->clearCallingIdentity();
1271 // Set the calling identity to graphics so captureDisplay with secure is allowed.
1272 IPCThreadState::self()->restoreCallingIdentity(static_cast<int64_t>(AID_GRAPHICS) << 32 |
1273 AID_GRAPHICS);
Lloyd Piquea482f992018-01-22 19:00:34 -08001274 sp<IBinder> displayToken = mFlinger.createDisplay(name, true);
chaviwd4a61642020-09-01 14:53:46 -07001275 IPCThreadState::self()->restoreCallingIdentity(oldId);
Lloyd Piquea482f992018-01-22 19:00:34 -08001276
1277 // --------------------------------------------------------------------
1278 // Postconditions
1279
1280 // The display should have been added to the current state
1281 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
1282 const auto& display = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001283 EXPECT_TRUE(display.isVirtual());
1284 EXPECT_TRUE(display.isSecure);
Lloyd Piquea482f992018-01-22 19:00:34 -08001285 EXPECT_EQ(name.string(), display.displayName);
1286
1287 // --------------------------------------------------------------------
1288 // Cleanup conditions
1289
1290 // Destroying the display invalidates the display state.
1291 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1292}
1293
1294/* ------------------------------------------------------------------------
1295 * SurfaceFlinger::destroyDisplay
1296 */
1297
1298TEST_F(DisplayTransactionTest, destroyDisplayClearsCurrentStateForDisplay) {
1299 using Case = NonHwcVirtualDisplayCase;
1300
1301 // --------------------------------------------------------------------
1302 // Preconditions
1303
1304 // A virtual display exists
1305 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
1306 existing.inject();
1307
1308 // --------------------------------------------------------------------
1309 // Call Expectations
1310
1311 // The call should notify the interceptor that a display was created.
1312 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
1313
1314 // Destroying the display invalidates the display state.
1315 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
1316
1317 // --------------------------------------------------------------------
1318 // Invocation
1319
1320 mFlinger.destroyDisplay(existing.token());
1321
1322 // --------------------------------------------------------------------
1323 // Postconditions
1324
1325 // The display should have been removed from the current state
1326 EXPECT_FALSE(hasCurrentDisplayState(existing.token()));
1327
1328 // Ths display should still exist in the drawing state
1329 EXPECT_TRUE(hasDrawingDisplayState(existing.token()));
1330
1331 // The display transaction needed flasg should be set
1332 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
1333}
1334
1335TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
1336 // --------------------------------------------------------------------
1337 // Preconditions
1338
1339 sp<BBinder> displayToken = new BBinder();
1340
1341 // --------------------------------------------------------------------
1342 // Invocation
1343
1344 mFlinger.destroyDisplay(displayToken);
1345}
1346
1347/* ------------------------------------------------------------------------
Lais Andrade3a6e47d2020-04-02 11:20:16 +01001348 * SurfaceFlinger::notifyPowerBoost
1349 */
1350
1351TEST_F(DisplayTransactionTest, notifyPowerBoostNotifiesTouchEvent) {
1352 mFlinger.scheduler()->replaceTouchTimer(100);
1353 std::this_thread::sleep_for(10ms); // wait for callback to be triggered
1354 EXPECT_TRUE(mFlinger.scheduler()->isTouchActive()); // Starting timer activates touch
1355
1356 std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback
1357 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1358
1359 EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::CAMERA_SHOT)));
1360 std::this_thread::sleep_for(10ms); // wait for callback to maybe be triggered
1361 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1362
1363 std::this_thread::sleep_for(110ms); // wait for reset touch timer to expire and trigger callback
1364 EXPECT_FALSE(mFlinger.scheduler()->isTouchActive());
1365
1366 EXPECT_EQ(NO_ERROR, mFlinger.notifyPowerBoost(static_cast<int32_t>(Boost::INTERACTION)));
1367 std::this_thread::sleep_for(10ms); // wait for callback to be triggered.
1368 EXPECT_TRUE(mFlinger.scheduler()->isTouchActive());
1369}
1370
1371/* ------------------------------------------------------------------------
Valerie Hau9758ae02018-10-09 16:05:09 -07001372 * DisplayDevice::GetBestColorMode
1373 */
1374class GetBestColorModeTest : public DisplayTransactionTest {
1375public:
Valerie Hau9758ae02018-10-09 16:05:09 -07001376 void setHasWideColorGamut(bool hasWideColorGamut) { mHasWideColorGamut = hasWideColorGamut; }
1377
1378 void addHwcColorModesMapping(ui::ColorMode colorMode,
1379 std::vector<ui::RenderIntent> renderIntents) {
1380 mHwcColorModes[colorMode] = renderIntents;
1381 }
1382
1383 void setInputDataspace(ui::Dataspace dataspace) { mInputDataspace = dataspace; }
1384
1385 void setInputRenderIntent(ui::RenderIntent renderIntent) { mInputRenderIntent = renderIntent; }
1386
1387 void getBestColorMode() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001388 auto displayDevice =
1389 injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1390 injector.setHwcColorModes(mHwcColorModes);
1391 injector.setHasWideColorGamut(mHasWideColorGamut);
1392 injector.setNativeWindow(mNativeWindow);
1393 });
Valerie Hau9758ae02018-10-09 16:05:09 -07001394
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001395 displayDevice->getCompositionDisplay()
1396 ->getDisplayColorProfile()
1397 ->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
1398 &mOutColorMode, &mOutRenderIntent);
Valerie Hau9758ae02018-10-09 16:05:09 -07001399 }
1400
1401 ui::Dataspace mOutDataspace;
1402 ui::ColorMode mOutColorMode;
1403 ui::RenderIntent mOutRenderIntent;
1404
1405private:
1406 ui::Dataspace mInputDataspace;
1407 ui::RenderIntent mInputRenderIntent;
1408 bool mHasWideColorGamut = false;
1409 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> mHwcColorModes;
Valerie Hau9758ae02018-10-09 16:05:09 -07001410};
1411
1412TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeSRGB) {
1413 addHwcColorModesMapping(ui::ColorMode::SRGB,
1414 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1415 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1416 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1417 setHasWideColorGamut(true);
1418
1419 getBestColorMode();
1420
Peiyong Lin14724e62018-12-05 07:27:30 -08001421 ASSERT_EQ(ui::Dataspace::V0_SRGB, mOutDataspace);
Valerie Hau9758ae02018-10-09 16:05:09 -07001422 ASSERT_EQ(ui::ColorMode::SRGB, mOutColorMode);
1423 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1424}
1425
1426TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDisplayP3) {
1427 addHwcColorModesMapping(ui::ColorMode::DISPLAY_P3,
1428 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1429 addHwcColorModesMapping(ui::ColorMode::SRGB,
1430 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1431 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1432 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1433 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1434 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1435 setHasWideColorGamut(true);
1436
1437 getBestColorMode();
1438
1439 ASSERT_EQ(ui::Dataspace::DISPLAY_P3, mOutDataspace);
1440 ASSERT_EQ(ui::ColorMode::DISPLAY_P3, mOutColorMode);
1441 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1442}
1443
1444TEST_F(GetBestColorModeTest, DataspaceDisplayP3_ColorModeDISPLAY_BT2020) {
1445 addHwcColorModesMapping(ui::ColorMode::DISPLAY_BT2020,
1446 std::vector<ui::RenderIntent>(1, RenderIntent::COLORIMETRIC));
1447 setInputDataspace(ui::Dataspace::DISPLAY_P3);
1448 setInputRenderIntent(ui::RenderIntent::COLORIMETRIC);
1449 setHasWideColorGamut(true);
1450
1451 getBestColorMode();
1452
1453 ASSERT_EQ(ui::Dataspace::DISPLAY_BT2020, mOutDataspace);
1454 ASSERT_EQ(ui::ColorMode::DISPLAY_BT2020, mOutColorMode);
1455 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mOutRenderIntent);
1456}
1457
1458/* ------------------------------------------------------------------------
Lloyd Pique33050472019-12-19 17:12:44 -08001459 * DisplayDevice::setProjection
1460 */
1461
1462class DisplayDeviceSetProjectionTest : public DisplayTransactionTest {
1463public:
Lloyd Pique33050472019-12-19 17:12:44 -08001464 static constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1080; // arbitrary
1465 static constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1920; // arbitrary
1466
1467 static constexpr int32_t TRANSFORM_FLAGS_ROT_0 = 0;
1468 static constexpr int32_t TRANSFORM_FLAGS_ROT_90 = HAL_TRANSFORM_ROT_90;
1469 static constexpr int32_t TRANSFORM_FLAGS_ROT_180 = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V;
1470 static constexpr int32_t TRANSFORM_FLAGS_ROT_270 =
1471 HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
1472
1473 DisplayDeviceSetProjectionTest(ui::Size flingerDisplaySize, ui::Size hardwareDisplaySize,
1474 ui::Rotation physicalOrientation)
1475 : mFlingerDisplaySize(flingerDisplaySize),
1476 mHardwareDisplaySize(hardwareDisplaySize),
1477 mPhysicalOrientation(physicalOrientation),
1478 mDisplayDevice(createDisplayDevice()) {}
1479
1480 sp<DisplayDevice> createDisplayDevice() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001481 return injectDefaultInternalDisplay([this](FakeDisplayDeviceInjector& injector) {
1482 injector.setPhysicalOrientation(mPhysicalOrientation);
1483 });
Lloyd Pique33050472019-12-19 17:12:44 -08001484 }
1485
Marin Shalamanov209ae612020-10-01 00:17:39 +02001486 ui::Size swapWH(const ui::Size size) const { return ui::Size(size.height, size.width); }
Lloyd Pique33050472019-12-19 17:12:44 -08001487
1488 void setProjectionForRotation0() {
1489 // A logical rotation of 0 uses the SurfaceFlinger display size
1490 mDisplayDevice->setProjection(ui::ROTATION_0, Rect(mFlingerDisplaySize),
1491 Rect(mFlingerDisplaySize));
1492 }
1493
1494 void setProjectionForRotation90() {
1495 // A logical rotation of 90 uses the SurfaceFlinger display size with
1496 // the width/height swapped.
Marin Shalamanov209ae612020-10-01 00:17:39 +02001497 mDisplayDevice->setProjection(ui::ROTATION_90, Rect(swapWH(mFlingerDisplaySize)),
1498 Rect(swapWH(mFlingerDisplaySize)));
Lloyd Pique33050472019-12-19 17:12:44 -08001499 }
1500
1501 void setProjectionForRotation180() {
1502 // A logical rotation of 180 uses the SurfaceFlinger display size
1503 mDisplayDevice->setProjection(ui::ROTATION_180, Rect(mFlingerDisplaySize),
1504 Rect(mFlingerDisplaySize));
1505 }
1506
1507 void setProjectionForRotation270() {
1508 // A logical rotation of 270 uses the SurfaceFlinger display size with
1509 // the width/height swapped.
Marin Shalamanov209ae612020-10-01 00:17:39 +02001510 mDisplayDevice->setProjection(ui::ROTATION_270, Rect(swapWH(mFlingerDisplaySize)),
1511 Rect(swapWH(mFlingerDisplaySize)));
Lloyd Pique33050472019-12-19 17:12:44 -08001512 }
1513
1514 void expectStateForHardwareTransform0() {
1515 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1516 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_0, mHardwareDisplaySize.width,
1517 mHardwareDisplaySize.height),
1518 compositionState.transform);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02001519 EXPECT_EQ(ui::ROTATION_0, compositionState.displaySpace.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001520 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content);
1521 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.orientedDisplaySpace.content);
1522 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001523 EXPECT_EQ(false, compositionState.needsFiltering);
1524 }
1525
1526 void expectStateForHardwareTransform90() {
1527 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1528 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_90, mHardwareDisplaySize.width,
1529 mHardwareDisplaySize.height),
1530 compositionState.transform);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02001531 EXPECT_EQ(ui::ROTATION_90, compositionState.displaySpace.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001532 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content);
1533 // For 90, the orientedDisplaySpaceRect and layerStackSpaceRect have the hardware display
1534 // size width and height swapped
Marin Shalamanov209ae612020-10-01 00:17:39 +02001535 EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)),
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001536 compositionState.orientedDisplaySpace.content);
Marin Shalamanov209ae612020-10-01 00:17:39 +02001537 EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001538 EXPECT_EQ(false, compositionState.needsFiltering);
1539 }
1540
1541 void expectStateForHardwareTransform180() {
1542 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1543 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_180, mHardwareDisplaySize.width,
1544 mHardwareDisplaySize.height),
1545 compositionState.transform);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02001546 EXPECT_EQ(ui::ROTATION_180, compositionState.displaySpace.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001547 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.orientedDisplaySpace.content);
1548 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001549 EXPECT_EQ(false, compositionState.needsFiltering);
1550 }
1551
1552 void expectStateForHardwareTransform270() {
1553 const auto& compositionState = mDisplayDevice->getCompositionDisplay()->getState();
1554 EXPECT_EQ(ui::Transform(TRANSFORM_FLAGS_ROT_270, mHardwareDisplaySize.width,
1555 mHardwareDisplaySize.height),
1556 compositionState.transform);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02001557 EXPECT_EQ(ui::ROTATION_270, compositionState.displaySpace.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001558 EXPECT_EQ(Rect(mHardwareDisplaySize), compositionState.displaySpace.content);
1559 // For 270, the orientedDisplaySpaceRect and layerStackSpaceRect have the hardware display
1560 // size width and height swapped
Marin Shalamanov209ae612020-10-01 00:17:39 +02001561 EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)),
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001562 compositionState.orientedDisplaySpace.content);
Marin Shalamanov209ae612020-10-01 00:17:39 +02001563 EXPECT_EQ(Rect(swapWH(mHardwareDisplaySize)), compositionState.layerStackSpace.content);
Lloyd Pique33050472019-12-19 17:12:44 -08001564 EXPECT_EQ(false, compositionState.needsFiltering);
1565 }
1566
1567 const ui::Size mFlingerDisplaySize;
1568 const ui::Size mHardwareDisplaySize;
1569 const ui::Rotation mPhysicalOrientation;
1570 const sp<DisplayDevice> mDisplayDevice;
1571};
1572
1573struct DisplayDeviceSetProjectionTest_Installed0 : public DisplayDeviceSetProjectionTest {
1574 DisplayDeviceSetProjectionTest_Installed0()
1575 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1576 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1577 ui::ROTATION_0) {}
1578};
1579
1580TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith0OutputRotation) {
1581 setProjectionForRotation0();
1582 expectStateForHardwareTransform0();
1583}
1584
1585TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith90OutputRotation) {
1586 setProjectionForRotation90();
1587 expectStateForHardwareTransform90();
1588}
1589
1590TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith180OutputRotation) {
1591 setProjectionForRotation180();
1592 expectStateForHardwareTransform180();
1593}
1594
1595TEST_F(DisplayDeviceSetProjectionTest_Installed0, checkWith270OutputRotation) {
1596 setProjectionForRotation270();
1597 expectStateForHardwareTransform270();
1598}
1599
1600struct DisplayDeviceSetProjectionTest_Installed90 : public DisplayDeviceSetProjectionTest {
1601 DisplayDeviceSetProjectionTest_Installed90()
1602 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1603 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1604 ui::ROTATION_90) {}
1605};
1606
1607TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith0OutputRotation) {
1608 setProjectionForRotation0();
1609 expectStateForHardwareTransform90();
1610}
1611
1612TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith90OutputRotation) {
1613 setProjectionForRotation90();
1614 expectStateForHardwareTransform180();
1615}
1616
1617TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith180OutputRotation) {
1618 setProjectionForRotation180();
1619 expectStateForHardwareTransform270();
1620}
1621
1622TEST_F(DisplayDeviceSetProjectionTest_Installed90, checkWith270OutputRotation) {
1623 setProjectionForRotation270();
1624 expectStateForHardwareTransform0();
1625}
1626
1627struct DisplayDeviceSetProjectionTest_Installed180 : public DisplayDeviceSetProjectionTest {
1628 DisplayDeviceSetProjectionTest_Installed180()
1629 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1630 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1631 ui::ROTATION_180) {}
1632};
1633
1634TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith0OutputRotation) {
1635 setProjectionForRotation0();
1636 expectStateForHardwareTransform180();
1637}
1638
1639TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith90OutputRotation) {
1640 setProjectionForRotation90();
1641 expectStateForHardwareTransform270();
1642}
1643
1644TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith180OutputRotation) {
1645 setProjectionForRotation180();
1646 expectStateForHardwareTransform0();
1647}
1648
1649TEST_F(DisplayDeviceSetProjectionTest_Installed180, checkWith270OutputRotation) {
1650 setProjectionForRotation270();
1651 expectStateForHardwareTransform90();
1652}
1653
1654struct DisplayDeviceSetProjectionTest_Installed270 : public DisplayDeviceSetProjectionTest {
1655 DisplayDeviceSetProjectionTest_Installed270()
1656 : DisplayDeviceSetProjectionTest(ui::Size(DEFAULT_DISPLAY_HEIGHT, DEFAULT_DISPLAY_WIDTH),
1657 ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
1658 ui::ROTATION_270) {}
1659};
1660
1661TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith0OutputRotation) {
1662 setProjectionForRotation0();
1663 expectStateForHardwareTransform270();
1664}
1665
1666TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith90OutputRotation) {
1667 setProjectionForRotation90();
1668 expectStateForHardwareTransform0();
1669}
1670
1671TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith180OutputRotation) {
1672 setProjectionForRotation180();
1673 expectStateForHardwareTransform90();
1674}
1675
1676TEST_F(DisplayDeviceSetProjectionTest_Installed270, checkWith270OutputRotation) {
1677 setProjectionForRotation270();
1678 expectStateForHardwareTransform180();
1679}
1680
1681/* ------------------------------------------------------------------------
Daniel Solomon42d04562019-01-20 21:03:19 -08001682 * SurfaceFlinger::getDisplayNativePrimaries
1683 */
1684
1685class GetDisplayNativePrimaries : public DisplayTransactionTest {
1686public:
1687 GetDisplayNativePrimaries();
1688 void populateDummyDisplayNativePrimaries(ui::DisplayPrimaries& primaries);
1689 void checkDummyDisplayNativePrimaries(const ui::DisplayPrimaries& primaries);
1690
1691private:
1692 static constexpr float mStartingTestValue = 1.0f;
1693};
1694
1695GetDisplayNativePrimaries::GetDisplayNativePrimaries() {
1696 SimplePrimaryDisplayCase::Display::injectHwcDisplay(this);
1697 injectFakeNativeWindowSurfaceFactory();
1698}
1699
1700void GetDisplayNativePrimaries::populateDummyDisplayNativePrimaries(
1701 ui::DisplayPrimaries& primaries) {
1702 float startingVal = mStartingTestValue;
1703 primaries.red.X = startingVal++;
1704 primaries.red.Y = startingVal++;
1705 primaries.red.Z = startingVal++;
1706 primaries.green.X = startingVal++;
1707 primaries.green.Y = startingVal++;
1708 primaries.green.Z = startingVal++;
1709 primaries.blue.X = startingVal++;
1710 primaries.blue.Y = startingVal++;
1711 primaries.blue.Z = startingVal++;
1712 primaries.white.X = startingVal++;
1713 primaries.white.Y = startingVal++;
1714 primaries.white.Z = startingVal++;
1715}
1716
1717void GetDisplayNativePrimaries::checkDummyDisplayNativePrimaries(
1718 const ui::DisplayPrimaries& primaries) {
1719 float startingVal = mStartingTestValue;
1720 EXPECT_EQ(primaries.red.X, startingVal++);
1721 EXPECT_EQ(primaries.red.Y, startingVal++);
1722 EXPECT_EQ(primaries.red.Z, startingVal++);
1723 EXPECT_EQ(primaries.green.X, startingVal++);
1724 EXPECT_EQ(primaries.green.Y, startingVal++);
1725 EXPECT_EQ(primaries.green.Z, startingVal++);
1726 EXPECT_EQ(primaries.blue.X, startingVal++);
1727 EXPECT_EQ(primaries.blue.Y, startingVal++);
1728 EXPECT_EQ(primaries.blue.Z, startingVal++);
1729 EXPECT_EQ(primaries.white.X, startingVal++);
1730 EXPECT_EQ(primaries.white.Y, startingVal++);
1731 EXPECT_EQ(primaries.white.Z, startingVal++);
1732}
1733
1734TEST_F(GetDisplayNativePrimaries, nullDisplayToken) {
1735 ui::DisplayPrimaries primaries;
1736 EXPECT_EQ(BAD_VALUE, mFlinger.getDisplayNativePrimaries(nullptr, primaries));
1737}
1738
Daniel Solomon42d04562019-01-20 21:03:19 -08001739TEST_F(GetDisplayNativePrimaries, internalDisplayWithPrimariesData) {
1740 auto injector = SimplePrimaryDisplayCase::Display::makeFakeExistingDisplayInjector(this);
1741 injector.inject();
1742 auto internalDisplayToken = injector.token();
1743
1744 ui::DisplayPrimaries expectedPrimaries;
1745 populateDummyDisplayNativePrimaries(expectedPrimaries);
1746 mFlinger.setInternalDisplayPrimaries(expectedPrimaries);
1747
1748 ui::DisplayPrimaries primaries;
1749 EXPECT_EQ(NO_ERROR, mFlinger.getDisplayNativePrimaries(internalDisplayToken, primaries));
1750
1751 checkDummyDisplayNativePrimaries(primaries);
1752}
1753
1754TEST_F(GetDisplayNativePrimaries, notInternalDisplayToken) {
1755 sp<BBinder> notInternalDisplayToken = new BBinder();
1756
1757 ui::DisplayPrimaries primaries;
1758 populateDummyDisplayNativePrimaries(primaries);
Dominik Laskowski470df5f2020-04-02 22:27:42 -07001759 EXPECT_EQ(NAME_NOT_FOUND,
1760 mFlinger.getDisplayNativePrimaries(notInternalDisplayToken, primaries));
Daniel Solomon42d04562019-01-20 21:03:19 -08001761
1762 // Check primaries argument wasn't modified in case of failure
1763 checkDummyDisplayNativePrimaries(primaries);
1764}
1765
1766/* ------------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001767 * SurfaceFlinger::setupNewDisplayDeviceInternal
1768 */
1769
1770class SetupNewDisplayDeviceInternalTest : public DisplayTransactionTest {
1771public:
1772 template <typename T>
1773 void setupNewDisplayDeviceInternalTest();
1774};
1775
1776template <typename Case>
1777void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() {
1778 const sp<BBinder> displayToken = new BBinder();
Lloyd Pique542307f2018-10-19 13:24:08 -07001779 const sp<compositionengine::mock::DisplaySurface> displaySurface =
1780 new compositionengine::mock::DisplaySurface();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001781 const sp<mock::GraphicBufferProducer> producer = new mock::GraphicBufferProducer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001782
1783 // --------------------------------------------------------------------
1784 // Preconditions
1785
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001786 // Wide color displays support is configured appropriately
1787 Case::WideColorSupport::injectConfigChange(this);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08001788
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001789 // The display is setup with the HWC.
1790 Case::Display::injectHwcDisplay(this);
1791
1792 // SurfaceFlinger will use a test-controlled factory for native window
1793 // surfaces.
1794 injectFakeNativeWindowSurfaceFactory();
1795
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001796 // A compositionengine::Display has already been created
1797 auto compositionDisplay = Case::Display::injectCompositionDisplay(this);
1798
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001799 // --------------------------------------------------------------------
1800 // Call Expectations
1801
1802 // Various native window calls will be made.
1803 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
Lloyd Pique3c085a02018-05-09 19:38:32 -07001804 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001805 Case::WideColorSupport::setupComposerCallExpectations(this);
1806 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001807 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001808
1809 // --------------------------------------------------------------------
1810 // Invocation
1811
1812 DisplayDeviceState state;
Dominik Laskowski55c85402020-01-21 16:25:47 -08001813 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02001814 const auto displayId = PhysicalDisplayId::tryCast(Case::Display::DISPLAY_ID::get());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001815 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001816 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1817 ASSERT_TRUE(hwcDisplayId);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02001818 state.physical = {.id = *displayId, .type = *connectionType, .hwcDisplayId = *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001819 }
1820
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001821 state.isSecure = static_cast<bool>(Case::Display::SECURE);
1822
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001823 auto device = mFlinger.setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state,
1824 displaySurface, producer);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001825
1826 // --------------------------------------------------------------------
1827 // Postconditions
1828
1829 ASSERT_TRUE(device != nullptr);
Dominik Laskowski075d3172018-05-24 15:50:06 -07001830 EXPECT_EQ(Case::Display::DISPLAY_ID::get(), device->getId());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001831 EXPECT_EQ(Case::Display::CONNECTION_TYPE::value, device->getConnectionType());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001832 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), device->isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001833 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001834 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001835 EXPECT_EQ(Case::Display::WIDTH, device->getWidth());
1836 EXPECT_EQ(Case::Display::HEIGHT, device->getHeight());
1837 EXPECT_EQ(Case::WideColorSupport::WIDE_COLOR_SUPPORTED, device->hasWideColorGamut());
Valerie Haue9e843a2018-12-18 13:39:23 -08001838 EXPECT_EQ(Case::HdrSupport::HDR10_PLUS_SUPPORTED, device->hasHDR10PlusSupport());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001839 EXPECT_EQ(Case::HdrSupport::HDR10_SUPPORTED, device->hasHDR10Support());
1840 EXPECT_EQ(Case::HdrSupport::HDR_HLG_SUPPORTED, device->hasHLGSupport());
1841 EXPECT_EQ(Case::HdrSupport::HDR_DOLBY_VISION_SUPPORTED, device->hasDolbyVisionSupport());
Lloyd Pique3c085a02018-05-09 19:38:32 -07001842 // Note: This is not Case::Display::HWC_ACTIVE_CONFIG_ID as the ids are
1843 // remapped, and the test only ever sets up one config. If there were an error
1844 // looking up the remapped index, device->getActiveConfig() would be -1 instead.
Ady Abraham2139f732019-11-13 18:56:40 -08001845 EXPECT_EQ(0, device->getActiveConfig().value());
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001846 EXPECT_EQ(Case::PerFrameMetadataSupport::PER_FRAME_METADATA_KEYS,
1847 device->getSupportedPerFrameMetadata());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001848}
1849
1850TEST_F(SetupNewDisplayDeviceInternalTest, createSimplePrimaryDisplay) {
1851 setupNewDisplayDeviceInternalTest<SimplePrimaryDisplayCase>();
1852}
1853
1854TEST_F(SetupNewDisplayDeviceInternalTest, createSimpleExternalDisplay) {
1855 setupNewDisplayDeviceInternalTest<SimpleExternalDisplayCase>();
1856}
1857
1858TEST_F(SetupNewDisplayDeviceInternalTest, createNonHwcVirtualDisplay) {
1859 setupNewDisplayDeviceInternalTest<NonHwcVirtualDisplayCase>();
1860}
1861
1862TEST_F(SetupNewDisplayDeviceInternalTest, createHwcVirtualDisplay) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001863 setupNewDisplayDeviceInternalTest<HwcVirtualDisplayCase>();
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001864}
1865
1866TEST_F(SetupNewDisplayDeviceInternalTest, createWideColorP3Display) {
1867 setupNewDisplayDeviceInternalTest<WideColorP3ColorimetricDisplayCase>();
1868}
1869
Valerie Haue9e843a2018-12-18 13:39:23 -08001870TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10PlusDisplay) {
1871 setupNewDisplayDeviceInternalTest<Hdr10PlusDisplayCase>();
1872}
1873
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001874TEST_F(SetupNewDisplayDeviceInternalTest, createHdr10Display) {
1875 setupNewDisplayDeviceInternalTest<Hdr10DisplayCase>();
1876}
1877
1878TEST_F(SetupNewDisplayDeviceInternalTest, createHdrHlgDisplay) {
1879 setupNewDisplayDeviceInternalTest<HdrHlgDisplayCase>();
1880}
1881
1882TEST_F(SetupNewDisplayDeviceInternalTest, createHdrDolbyVisionDisplay) {
1883 setupNewDisplayDeviceInternalTest<HdrDolbyVisionDisplayCase>();
1884}
1885
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001886TEST_F(SetupNewDisplayDeviceInternalTest, createHdrSmpte2086DisplayCase) {
1887 setupNewDisplayDeviceInternalTest<HdrSmpte2086DisplayCase>();
1888}
1889
1890TEST_F(SetupNewDisplayDeviceInternalTest, createHdrCta816_3_DisplayCase) {
1891 setupNewDisplayDeviceInternalTest<HdrCta861_3_DisplayCase>();
1892}
1893
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001894/* ------------------------------------------------------------------------
1895 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
1896 */
1897
1898class HandleTransactionLockedTest : public DisplayTransactionTest {
1899public:
1900 template <typename Case>
1901 void setupCommonPreconditions();
1902
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001903 template <typename Case, bool connected>
1904 static void expectHotplugReceived(mock::EventThread*);
1905
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001906 template <typename Case>
1907 void setupCommonCallExpectationsForConnectProcessing();
1908
1909 template <typename Case>
1910 void setupCommonCallExpectationsForDisconnectProcessing();
1911
1912 template <typename Case>
1913 void processesHotplugConnectCommon();
1914
1915 template <typename Case>
1916 void ignoresHotplugConnectCommon();
1917
1918 template <typename Case>
1919 void processesHotplugDisconnectCommon();
1920
1921 template <typename Case>
1922 void verifyDisplayIsConnected(const sp<IBinder>& displayToken);
1923
1924 template <typename Case>
1925 void verifyPhysicalDisplayIsConnected();
1926
1927 void verifyDisplayIsNotConnected(const sp<IBinder>& displayToken);
1928};
1929
1930template <typename Case>
1931void HandleTransactionLockedTest::setupCommonPreconditions() {
1932 // Wide color displays support is configured appropriately
1933 Case::WideColorSupport::injectConfigChange(this);
1934
1935 // SurfaceFlinger will use a test-controlled factory for BufferQueues
1936 injectFakeBufferQueueFactory();
1937
1938 // SurfaceFlinger will use a test-controlled factory for native window
1939 // surfaces.
1940 injectFakeNativeWindowSurfaceFactory();
1941}
1942
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001943template <typename Case, bool connected>
1944void HandleTransactionLockedTest::expectHotplugReceived(mock::EventThread* eventThread) {
1945 const auto convert = [](auto physicalDisplayId) {
1946 return std::make_optional(DisplayId{physicalDisplayId});
1947 };
1948
1949 EXPECT_CALL(*eventThread,
1950 onHotplugReceived(ResultOf(convert, Case::Display::DISPLAY_ID::get()), connected))
1951 .Times(1);
1952}
1953
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001954template <typename Case>
1955void HandleTransactionLockedTest::setupCommonCallExpectationsForConnectProcessing() {
1956 Case::Display::setupHwcHotplugCallExpectations(this);
1957
1958 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
1959 Case::Display::setupFramebufferProducerBufferQueueCallExpectations(this);
1960 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
1961 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
1962
1963 Case::WideColorSupport::setupComposerCallExpectations(this);
1964 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07001965 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001966
1967 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001968 expectHotplugReceived<Case, true>(mEventThread);
1969 expectHotplugReceived<Case, true>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001970}
1971
1972template <typename Case>
1973void HandleTransactionLockedTest::setupCommonCallExpectationsForDisconnectProcessing() {
1974 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayDeletion(_)).Times(1);
Dominik Laskowski1eba0202019-01-24 09:14:40 -08001975
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -08001976 expectHotplugReceived<Case, false>(mEventThread);
1977 expectHotplugReceived<Case, false>(mSFEventThread);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001978}
1979
1980template <typename Case>
1981void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp<IBinder>& displayToken) {
1982 // The display device should have been set up in the list of displays.
1983 ASSERT_TRUE(hasDisplayDevice(displayToken));
1984 const auto& device = getDisplayDevice(displayToken);
1985 EXPECT_EQ(static_cast<bool>(Case::Display::SECURE), device->isSecure());
Dominik Laskowski075d3172018-05-24 15:50:06 -07001986 EXPECT_EQ(static_cast<bool>(Case::Display::PRIMARY), device->isPrimary());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001987
Dominik Laskowski55c85402020-01-21 16:25:47 -08001988 std::optional<DisplayDeviceState::Physical> expectedPhysical;
1989 if (const auto connectionType = Case::Display::CONNECTION_TYPE::value) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02001990 const auto displayId = PhysicalDisplayId::tryCast(Case::Display::DISPLAY_ID::get());
Dominik Laskowski55c85402020-01-21 16:25:47 -08001991 ASSERT_TRUE(displayId);
Marin Shalamanov4a42d432020-02-12 20:22:26 +01001992 const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value;
1993 ASSERT_TRUE(hwcDisplayId);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02001994 expectedPhysical = {.id = *displayId,
Marin Shalamanov7ce87642020-05-06 13:45:58 +02001995 .type = *connectionType,
1996 .hwcDisplayId = *hwcDisplayId};
Dominik Laskowski55c85402020-01-21 16:25:47 -08001997 }
1998
Lloyd Piquec11e0d32018-01-22 18:44:59 -08001999 // The display should have been set up in the current display state
2000 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
2001 const auto& current = getCurrentDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002002 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), current.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08002003 EXPECT_EQ(expectedPhysical, current.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002004
2005 // The display should have been set up in the drawing display state
2006 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2007 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002008 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Dominik Laskowski55c85402020-01-21 16:25:47 -08002009 EXPECT_EQ(expectedPhysical, draw.physical);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002010}
2011
2012template <typename Case>
2013void HandleTransactionLockedTest::verifyPhysicalDisplayIsConnected() {
2014 // HWComposer should have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002015 EXPECT_TRUE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002016
Dominik Laskowski075d3172018-05-24 15:50:06 -07002017 // SF should have a display token.
2018 const auto displayId = Case::Display::DISPLAY_ID::get();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02002019 ASSERT_TRUE(PhysicalDisplayId::tryCast(displayId));
2020 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(displayId) == 1);
2021 auto& displayToken = mFlinger.mutablePhysicalDisplayTokens()[displayId];
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002022
2023 verifyDisplayIsConnected<Case>(displayToken);
2024}
2025
2026void HandleTransactionLockedTest::verifyDisplayIsNotConnected(const sp<IBinder>& displayToken) {
2027 EXPECT_FALSE(hasDisplayDevice(displayToken));
2028 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2029 EXPECT_FALSE(hasDrawingDisplayState(displayToken));
2030}
2031
2032template <typename Case>
2033void HandleTransactionLockedTest::processesHotplugConnectCommon() {
2034 // --------------------------------------------------------------------
2035 // Preconditions
2036
2037 setupCommonPreconditions<Case>();
2038
2039 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002040 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002041
2042 // --------------------------------------------------------------------
2043 // Call Expectations
2044
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002045 setupCommonCallExpectationsForConnectProcessing<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002046
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002047 // --------------------------------------------------------------------
2048 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -08002049
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002050 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -08002051
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002052 // --------------------------------------------------------------------
2053 // Postconditions
2054
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002055 verifyPhysicalDisplayIsConnected<Case>();
Lloyd Piquee39cad22017-12-20 17:01:29 -08002056
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002057 // --------------------------------------------------------------------
2058 // Cleanup conditions
2059
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002060 EXPECT_CALL(*mComposer,
2061 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
Lloyd Pique1fa4d462018-01-22 18:03:16 -08002062 .WillOnce(Return(Error::NONE));
2063 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -08002064}
2065
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002066template <typename Case>
2067void HandleTransactionLockedTest::ignoresHotplugConnectCommon() {
2068 // --------------------------------------------------------------------
2069 // Preconditions
2070
2071 setupCommonPreconditions<Case>();
2072
2073 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002074 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002075
2076 // --------------------------------------------------------------------
2077 // Invocation
2078
2079 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2080
2081 // --------------------------------------------------------------------
2082 // Postconditions
2083
2084 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002085 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002086}
2087
2088template <typename Case>
2089void HandleTransactionLockedTest::processesHotplugDisconnectCommon() {
2090 // --------------------------------------------------------------------
2091 // Preconditions
2092
2093 setupCommonPreconditions<Case>();
2094
2095 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002096 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002097
2098 // The display is already completely set up.
2099 Case::Display::injectHwcDisplay(this);
2100 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2101 existing.inject();
2102
2103 // --------------------------------------------------------------------
2104 // Call Expectations
2105
Lloyd Pique438e9e72018-09-04 18:06:08 -07002106 EXPECT_CALL(*mComposer, getDisplayIdentificationData(Case::Display::HWC_DISPLAY_ID, _, _))
2107 .Times(0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002108
2109 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2110
2111 // --------------------------------------------------------------------
2112 // Invocation
2113
2114 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2115
2116 // --------------------------------------------------------------------
2117 // Postconditions
2118
2119 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002120 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002121
Dominik Laskowski075d3172018-05-24 15:50:06 -07002122 // SF should not have a display token.
2123 const auto displayId = Case::Display::DISPLAY_ID::get();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02002124 ASSERT_TRUE(PhysicalDisplayId::tryCast(displayId));
2125 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002126
2127 // The existing token should have been removed
2128 verifyDisplayIsNotConnected(existing.token());
2129}
2130
2131TEST_F(HandleTransactionLockedTest, processesHotplugConnectPrimaryDisplay) {
2132 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2133}
2134
2135TEST_F(HandleTransactionLockedTest,
2136 processesHotplugConnectPrimaryDisplayWithExternalAlreadyConnected) {
2137 // Inject an external display.
2138 ExternalDisplayVariant::injectHwcDisplay(this);
2139
2140 processesHotplugConnectCommon<SimplePrimaryDisplayCase>();
2141}
2142
2143TEST_F(HandleTransactionLockedTest, processesHotplugConnectExternalDisplay) {
2144 // Inject a primary display.
2145 PrimaryDisplayVariant::injectHwcDisplay(this);
2146
2147 processesHotplugConnectCommon<SimpleExternalDisplayCase>();
2148}
2149
2150TEST_F(HandleTransactionLockedTest, ignoresHotplugConnectIfPrimaryAndExternalAlreadyConnected) {
2151 // Inject both a primary and external display.
2152 PrimaryDisplayVariant::injectHwcDisplay(this);
2153 ExternalDisplayVariant::injectHwcDisplay(this);
2154
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002155 // TODO: This is an unnecessary call.
2156 EXPECT_CALL(*mComposer,
2157 getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _))
2158 .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay::PORT),
2159 SetArgPointee<2>(TertiaryDisplay::GET_IDENTIFICATION_DATA()),
2160 Return(Error::NONE)));
2161
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002162 ignoresHotplugConnectCommon<SimpleTertiaryDisplayCase>();
2163}
2164
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002165TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectPrimaryDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002166 processesHotplugDisconnectCommon<SimplePrimaryDisplayCase>();
2167}
2168
Marin Shalamanov4a42d432020-02-12 20:22:26 +01002169TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectExternalDisplay) {
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002170 processesHotplugDisconnectCommon<SimpleExternalDisplayCase>();
2171}
2172
2173TEST_F(HandleTransactionLockedTest, processesHotplugConnectThenDisconnectPrimary) {
2174 using Case = SimplePrimaryDisplayCase;
2175
2176 // --------------------------------------------------------------------
2177 // Preconditions
2178
2179 setupCommonPreconditions<Case>();
2180
2181 // A hotplug connect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002182 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002183 // A hotplug disconnect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002184 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002185
2186 // --------------------------------------------------------------------
2187 // Call Expectations
2188
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002189 setupCommonCallExpectationsForConnectProcessing<Case>();
2190 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2191
2192 EXPECT_CALL(*mComposer,
2193 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2194 .WillOnce(Return(Error::NONE));
2195 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2196
2197 // --------------------------------------------------------------------
2198 // Invocation
2199
2200 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2201
2202 // --------------------------------------------------------------------
2203 // Postconditions
2204
2205 // HWComposer should not have an entry for the display
Dominik Laskowski075d3172018-05-24 15:50:06 -07002206 EXPECT_FALSE(hasPhysicalHwcDisplay(Case::Display::HWC_DISPLAY_ID));
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002207
Dominik Laskowski075d3172018-05-24 15:50:06 -07002208 // SF should not have a display token.
2209 const auto displayId = Case::Display::DISPLAY_ID::get();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02002210 ASSERT_TRUE(PhysicalDisplayId::tryCast(displayId));
2211 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(displayId) == 0);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002212}
2213
2214TEST_F(HandleTransactionLockedTest, processesHotplugDisconnectThenConnectPrimary) {
2215 using Case = SimplePrimaryDisplayCase;
2216
2217 // --------------------------------------------------------------------
2218 // Preconditions
2219
2220 setupCommonPreconditions<Case>();
2221
2222 // The display is already completely set up.
2223 Case::Display::injectHwcDisplay(this);
2224 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2225 existing.inject();
2226
2227 // A hotplug disconnect event is enqueued for a display
Peiyong Line9d809e2020-04-14 13:10:48 -07002228 Case::Display::injectPendingHotplugEvent(this, Connection::DISCONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002229 // A hotplug connect event is also enqueued for the same display
Peiyong Line9d809e2020-04-14 13:10:48 -07002230 Case::Display::injectPendingHotplugEvent(this, Connection::CONNECTED);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002231
2232 // --------------------------------------------------------------------
2233 // Call Expectations
2234
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002235 setupCommonCallExpectationsForConnectProcessing<Case>();
2236 setupCommonCallExpectationsForDisconnectProcessing<Case>();
2237
2238 // --------------------------------------------------------------------
2239 // Invocation
2240
2241 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2242
2243 // --------------------------------------------------------------------
2244 // Postconditions
2245
2246 // The existing token should have been removed
2247 verifyDisplayIsNotConnected(existing.token());
Dominik Laskowski075d3172018-05-24 15:50:06 -07002248 const auto displayId = Case::Display::DISPLAY_ID::get();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02002249 ASSERT_TRUE(PhysicalDisplayId::tryCast(displayId));
2250 ASSERT_TRUE(mFlinger.mutablePhysicalDisplayTokens().count(displayId) == 1);
2251 EXPECT_NE(existing.token(), mFlinger.mutablePhysicalDisplayTokens()[displayId]);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002252
2253 // A new display should be connected in its place
2254
2255 verifyPhysicalDisplayIsConnected<Case>();
2256
2257 // --------------------------------------------------------------------
2258 // Cleanup conditions
2259
2260 EXPECT_CALL(*mComposer,
2261 setVsyncEnabled(Case::Display::HWC_DISPLAY_ID, IComposerClient::Vsync::DISABLE))
2262 .WillOnce(Return(Error::NONE));
2263 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
2264}
2265
2266TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAdded) {
2267 using Case = HwcVirtualDisplayCase;
2268
2269 // --------------------------------------------------------------------
2270 // Preconditions
2271
2272 // The HWC supports at least one virtual display
2273 injectMockComposer(1);
2274
2275 setupCommonPreconditions<Case>();
2276
2277 // A virtual display was added to the current state, and it has a
2278 // surface(producer)
2279 sp<BBinder> displayToken = new BBinder();
Lloyd Pique4c2ac022018-04-27 12:08:03 -07002280
Dominik Laskowski075d3172018-05-24 15:50:06 -07002281 DisplayDeviceState state;
2282 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002283
2284 sp<mock::GraphicBufferProducer> surface{new mock::GraphicBufferProducer()};
Dominik Laskowski075d3172018-05-24 15:50:06 -07002285 state.surface = surface;
2286 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002287
2288 // --------------------------------------------------------------------
2289 // Call Expectations
2290
2291 Case::Display::setupFramebufferConsumerBufferQueueCallExpectations(this);
2292 Case::Display::setupNativeWindowSurfaceCreationCallExpectations(this);
2293
2294 EXPECT_CALL(*surface, query(NATIVE_WINDOW_WIDTH, _))
2295 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::WIDTH), Return(NO_ERROR)));
2296 EXPECT_CALL(*surface, query(NATIVE_WINDOW_HEIGHT, _))
2297 .WillRepeatedly(DoAll(SetArgPointee<1>(Case::Display::HEIGHT), Return(NO_ERROR)));
2298 EXPECT_CALL(*surface, query(NATIVE_WINDOW_FORMAT, _))
2299 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_VIRTUAL_DISPLAY_SURFACE_FORMAT),
2300 Return(NO_ERROR)));
2301 EXPECT_CALL(*surface, query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, _))
2302 .WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(NO_ERROR)));
2303
2304 EXPECT_CALL(*surface, setAsyncMode(true)).Times(1);
2305
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002306 EXPECT_CALL(*mProducer, connect(_, NATIVE_WINDOW_API_EGL, false, _)).Times(1);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002307 EXPECT_CALL(*mProducer, disconnect(_, _)).Times(1);
2308
2309 Case::Display::setupHwcVirtualDisplayCreationCallExpectations(this);
2310 Case::WideColorSupport::setupComposerCallExpectations(this);
2311 Case::HdrSupport::setupComposerCallExpectations(this);
Lloyd Piqued883d5a2018-04-27 19:32:30 -07002312 Case::PerFrameMetadataSupport::setupComposerCallExpectations(this);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002313
2314 // --------------------------------------------------------------------
2315 // Invocation
2316
2317 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2318
2319 // --------------------------------------------------------------------
2320 // Postconditions
2321
2322 // The display device should have been set up in the list of displays.
2323 verifyDisplayIsConnected<Case>(displayToken);
2324
2325 // --------------------------------------------------------------------
2326 // Cleanup conditions
2327
2328 EXPECT_CALL(*mComposer, destroyVirtualDisplay(Case::Display::HWC_DISPLAY_ID))
2329 .WillOnce(Return(Error::NONE));
2330 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Pique9e9800c2019-02-26 16:26:09 -08002331
2332 // Cleanup
2333 mFlinger.mutableCurrentState().displays.removeItem(displayToken);
2334 mFlinger.mutableDrawingState().displays.removeItem(displayToken);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002335}
2336
2337TEST_F(HandleTransactionLockedTest, processesVirtualDisplayAddedWithNoSurface) {
2338 using Case = HwcVirtualDisplayCase;
2339
2340 // --------------------------------------------------------------------
2341 // Preconditions
2342
2343 // The HWC supports at least one virtual display
2344 injectMockComposer(1);
2345
2346 setupCommonPreconditions<Case>();
2347
2348 // A virtual display was added to the current state, but it does not have a
2349 // surface.
2350 sp<BBinder> displayToken = new BBinder();
2351
Dominik Laskowski075d3172018-05-24 15:50:06 -07002352 DisplayDeviceState state;
2353 state.isSecure = static_cast<bool>(Case::Display::SECURE);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002354
Dominik Laskowski075d3172018-05-24 15:50:06 -07002355 mFlinger.mutableCurrentState().displays.add(displayToken, state);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002356
2357 // --------------------------------------------------------------------
2358 // Call Expectations
2359
2360 // --------------------------------------------------------------------
2361 // Invocation
2362
2363 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2364
2365 // --------------------------------------------------------------------
2366 // Postconditions
2367
2368 // There will not be a display device set up.
2369 EXPECT_FALSE(hasDisplayDevice(displayToken));
2370
2371 // The drawing display state will be set from the current display state.
2372 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
2373 const auto& draw = getDrawingDisplayState(displayToken);
Dominik Laskowski075d3172018-05-24 15:50:06 -07002374 EXPECT_EQ(static_cast<bool>(Case::Display::VIRTUAL), draw.isVirtual());
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002375}
2376
2377TEST_F(HandleTransactionLockedTest, processesVirtualDisplayRemoval) {
2378 using Case = HwcVirtualDisplayCase;
2379
2380 // --------------------------------------------------------------------
2381 // Preconditions
2382
2383 // A virtual display is set up but is removed from the current state.
Dominik Laskowski075d3172018-05-24 15:50:06 -07002384 const auto displayId = Case::Display::DISPLAY_ID::get();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02002385 ASSERT_TRUE(HalVirtualDisplayId::tryCast(displayId));
2386 mFlinger.mutableHwcDisplayData().try_emplace(displayId);
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002387 Case::Display::injectHwcDisplay(this);
2388 auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
2389 existing.inject();
2390 mFlinger.mutableCurrentState().displays.removeItem(existing.token());
2391
2392 // --------------------------------------------------------------------
Lloyd Piquec11e0d32018-01-22 18:44:59 -08002393 // Invocation
2394
2395 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2396
2397 // --------------------------------------------------------------------
2398 // Postconditions
2399
2400 // The existing token should have been removed
2401 verifyDisplayIsNotConnected(existing.token());
2402}
2403
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002404TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackChanges) {
2405 using Case = NonHwcVirtualDisplayCase;
2406
2407 constexpr uint32_t oldLayerStack = 0u;
2408 constexpr uint32_t newLayerStack = 123u;
2409
2410 // --------------------------------------------------------------------
2411 // Preconditions
2412
2413 // A display is set up
2414 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2415 display.inject();
2416
2417 // There is a change to the layerStack state
2418 display.mutableDrawingDisplayState().layerStack = oldLayerStack;
2419 display.mutableCurrentDisplayState().layerStack = newLayerStack;
2420
2421 // --------------------------------------------------------------------
2422 // Invocation
2423
2424 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2425
2426 // --------------------------------------------------------------------
2427 // Postconditions
2428
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002429 EXPECT_EQ(newLayerStack, display.mutableDisplayDevice()->getLayerStack());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002430}
2431
2432TEST_F(HandleTransactionLockedTest, processesDisplayTransformChanges) {
2433 using Case = NonHwcVirtualDisplayCase;
2434
Dominik Laskowski718f9602019-11-09 20:01:35 -08002435 constexpr ui::Rotation oldTransform = ui::ROTATION_0;
2436 constexpr ui::Rotation newTransform = ui::ROTATION_180;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002437
2438 // --------------------------------------------------------------------
2439 // Preconditions
2440
2441 // A display is set up
2442 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2443 display.inject();
2444
2445 // There is a change to the orientation state
2446 display.mutableDrawingDisplayState().orientation = oldTransform;
2447 display.mutableCurrentDisplayState().orientation = newTransform;
2448
2449 // --------------------------------------------------------------------
2450 // Invocation
2451
2452 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2453
2454 // --------------------------------------------------------------------
2455 // Postconditions
2456
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002457 EXPECT_EQ(newTransform, display.mutableDisplayDevice()->getOrientation());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002458}
2459
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002460TEST_F(HandleTransactionLockedTest, processesDisplayLayerStackRectChanges) {
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002461 using Case = NonHwcVirtualDisplayCase;
2462
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002463 const Rect oldLayerStackRect(0, 0, 0, 0);
2464 const Rect newLayerStackRect(0, 0, 123, 456);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002465
2466 // --------------------------------------------------------------------
2467 // Preconditions
2468
2469 // A display is set up
2470 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2471 display.inject();
2472
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002473 // There is a change to the layerStackSpaceRect state
2474 display.mutableDrawingDisplayState().layerStackSpaceRect = oldLayerStackRect;
2475 display.mutableCurrentDisplayState().layerStackSpaceRect = newLayerStackRect;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002476
2477 // --------------------------------------------------------------------
2478 // Invocation
2479
2480 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2481
2482 // --------------------------------------------------------------------
2483 // Postconditions
2484
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002485 EXPECT_EQ(newLayerStackRect, display.mutableDisplayDevice()->getLayerStackSpaceRect());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002486}
2487
2488TEST_F(HandleTransactionLockedTest, processesDisplayFrameChanges) {
2489 using Case = NonHwcVirtualDisplayCase;
2490
2491 const Rect oldFrame(0, 0, 0, 0);
2492 const Rect newFrame(0, 0, 123, 456);
2493
2494 // --------------------------------------------------------------------
2495 // Preconditions
2496
2497 // A display is set up
2498 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2499 display.inject();
2500
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002501 // There is a change to the layerStackSpaceRect state
2502 display.mutableDrawingDisplayState().orientedDisplaySpaceRect = oldFrame;
2503 display.mutableCurrentDisplayState().orientedDisplaySpaceRect = newFrame;
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002504
2505 // --------------------------------------------------------------------
2506 // Invocation
2507
2508 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2509
2510 // --------------------------------------------------------------------
2511 // Postconditions
2512
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002513 EXPECT_EQ(newFrame, display.mutableDisplayDevice()->getOrientedDisplaySpaceRect());
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002514}
2515
2516TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
2517 using Case = NonHwcVirtualDisplayCase;
2518
2519 constexpr int oldWidth = 0;
2520 constexpr int oldHeight = 10;
2521 constexpr int newWidth = 123;
2522
2523 // --------------------------------------------------------------------
2524 // Preconditions
2525
2526 // A display is set up
2527 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002528 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002529 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002530 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2531 display.setNativeWindow(nativeWindow);
2532 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002533 // Setup injection expections
2534 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2535 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2536 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2537 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002538 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2539 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2540 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002541 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002542 display.inject();
2543
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002544 // There is a change to the layerStackSpaceRect state
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002545 display.mutableDrawingDisplayState().width = oldWidth;
2546 display.mutableDrawingDisplayState().height = oldHeight;
2547 display.mutableCurrentDisplayState().width = newWidth;
2548 display.mutableCurrentDisplayState().height = oldHeight;
2549
2550 // --------------------------------------------------------------------
2551 // Call Expectations
2552
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002553 EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002554
2555 // --------------------------------------------------------------------
2556 // Invocation
2557
2558 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2559}
2560
2561TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
2562 using Case = NonHwcVirtualDisplayCase;
2563
2564 constexpr int oldWidth = 0;
2565 constexpr int oldHeight = 10;
2566 constexpr int newHeight = 123;
2567
2568 // --------------------------------------------------------------------
2569 // Preconditions
2570
2571 // A display is set up
2572 auto nativeWindow = new mock::NativeWindow();
Lloyd Pique542307f2018-10-19 13:24:08 -07002573 auto displaySurface = new compositionengine::mock::DisplaySurface();
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002574 sp<GraphicBuffer> buf = new GraphicBuffer();
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002575 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2576 display.setNativeWindow(nativeWindow);
2577 display.setDisplaySurface(displaySurface);
Alec Mouri0a9c7b82018-11-16 13:05:25 -08002578 // Setup injection expections
2579 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _))
2580 .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0)));
2581 EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
2582 .WillOnce(DoAll(SetArgPointee<1>(oldHeight), Return(0)));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08002583 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
2584 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
2585 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
chaviw8beb4142019-04-11 13:09:05 -07002586 EXPECT_CALL(*nativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002587 display.inject();
2588
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002589 // There is a change to the layerStackSpaceRect state
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002590 display.mutableDrawingDisplayState().width = oldWidth;
2591 display.mutableDrawingDisplayState().height = oldHeight;
2592 display.mutableCurrentDisplayState().width = oldWidth;
2593 display.mutableCurrentDisplayState().height = newHeight;
2594
2595 // --------------------------------------------------------------------
2596 // Call Expectations
2597
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002598 EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
Lloyd Pique0fa1d4c2018-01-22 18:54:42 -08002599
2600 // --------------------------------------------------------------------
2601 // Invocation
2602
2603 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
2604}
2605
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002606/* ------------------------------------------------------------------------
2607 * SurfaceFlinger::setDisplayStateLocked
2608 */
2609
2610TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWithUnknownDisplay) {
2611 // --------------------------------------------------------------------
2612 // Preconditions
2613
2614 // We have an unknown display token not associated with a known display
2615 sp<BBinder> displayToken = new BBinder();
2616
2617 // The requested display state references the unknown display.
2618 DisplayState state;
2619 state.what = DisplayState::eLayerStackChanged;
2620 state.token = displayToken;
2621 state.layerStack = 456;
2622
2623 // --------------------------------------------------------------------
2624 // Invocation
2625
2626 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2627
2628 // --------------------------------------------------------------------
2629 // Postconditions
2630
2631 // The returned flags are empty
2632 EXPECT_EQ(0u, flags);
2633
2634 // The display token still doesn't match anything known.
2635 EXPECT_FALSE(hasCurrentDisplayState(displayToken));
2636}
2637
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002638TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingWhenNoChanges) {
2639 using Case = SimplePrimaryDisplayCase;
2640
2641 // --------------------------------------------------------------------
2642 // Preconditions
2643
2644 // A display is already set up
2645 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2646 display.inject();
2647
2648 // No changes are made to the display
2649 DisplayState state;
2650 state.what = 0;
2651 state.token = display.token();
2652
2653 // --------------------------------------------------------------------
2654 // Invocation
2655
2656 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2657
2658 // --------------------------------------------------------------------
2659 // Postconditions
2660
2661 // The returned flags are empty
2662 EXPECT_EQ(0u, flags);
2663}
2664
2665TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSurfaceDidNotChange) {
2666 using Case = SimplePrimaryDisplayCase;
2667
2668 // --------------------------------------------------------------------
2669 // Preconditions
2670
2671 // A display is already set up
2672 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2673 display.inject();
2674
2675 // There is a surface that can be set.
2676 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2677
2678 // The current display state has the surface set
2679 display.mutableCurrentDisplayState().surface = surface;
2680
2681 // The incoming request sets the same surface
2682 DisplayState state;
2683 state.what = DisplayState::eSurfaceChanged;
2684 state.token = display.token();
2685 state.surface = surface;
2686
2687 // --------------------------------------------------------------------
2688 // Invocation
2689
2690 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2691
2692 // --------------------------------------------------------------------
2693 // Postconditions
2694
2695 // The returned flags are empty
2696 EXPECT_EQ(0u, flags);
2697
2698 // The current display state is unchanged.
2699 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2700}
2701
2702TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfSurfaceChanged) {
2703 using Case = SimplePrimaryDisplayCase;
2704
2705 // --------------------------------------------------------------------
2706 // Preconditions
2707
2708 // A display is already set up
2709 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2710 display.inject();
2711
2712 // There is a surface that can be set.
2713 sp<mock::GraphicBufferProducer> surface = new mock::GraphicBufferProducer();
2714
2715 // The current display state does not have a surface
2716 display.mutableCurrentDisplayState().surface = nullptr;
2717
2718 // The incoming request sets a surface
2719 DisplayState state;
2720 state.what = DisplayState::eSurfaceChanged;
2721 state.token = display.token();
2722 state.surface = surface;
2723
2724 // --------------------------------------------------------------------
2725 // Invocation
2726
2727 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2728
2729 // --------------------------------------------------------------------
2730 // Postconditions
2731
2732 // The returned flags indicate a transaction is needed
2733 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2734
2735 // The current display layer stack state is set to the new value
2736 EXPECT_EQ(surface.get(), display.getCurrentDisplayState().surface.get());
2737}
2738
2739TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfLayerStackDidNotChange) {
2740 using Case = SimplePrimaryDisplayCase;
2741
2742 // --------------------------------------------------------------------
2743 // Preconditions
2744
2745 // A display is already set up
2746 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2747 display.inject();
2748
2749 // The display has a layer stack set
2750 display.mutableCurrentDisplayState().layerStack = 456u;
2751
2752 // The incoming request sets the same layer stack
2753 DisplayState state;
2754 state.what = DisplayState::eLayerStackChanged;
2755 state.token = display.token();
2756 state.layerStack = 456u;
2757
2758 // --------------------------------------------------------------------
2759 // Invocation
2760
2761 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2762
2763 // --------------------------------------------------------------------
2764 // Postconditions
2765
2766 // The returned flags are empty
2767 EXPECT_EQ(0u, flags);
2768
2769 // The current display state is unchanged
2770 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2771}
2772
2773TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackChanged) {
2774 using Case = SimplePrimaryDisplayCase;
2775
2776 // --------------------------------------------------------------------
2777 // Preconditions
2778
2779 // A display is set up
2780 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2781 display.inject();
2782
2783 // The display has a layer stack set
2784 display.mutableCurrentDisplayState().layerStack = 654u;
2785
2786 // The incoming request sets a different layer stack
2787 DisplayState state;
2788 state.what = DisplayState::eLayerStackChanged;
2789 state.token = display.token();
2790 state.layerStack = 456u;
2791
2792 // --------------------------------------------------------------------
2793 // Invocation
2794
2795 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2796
2797 // --------------------------------------------------------------------
2798 // Postconditions
2799
2800 // The returned flags indicate a transaction is needed
2801 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2802
2803 // The desired display state has been set to the new value.
2804 EXPECT_EQ(456u, display.getCurrentDisplayState().layerStack);
2805}
2806
2807TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfProjectionDidNotChange) {
2808 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002809 constexpr ui::Rotation initialOrientation = ui::ROTATION_180;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002810 const Rect initialOrientedDisplayRect = {1, 2, 3, 4};
2811 const Rect initialLayerStackRect = {5, 6, 7, 8};
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002812
2813 // --------------------------------------------------------------------
2814 // Preconditions
2815
2816 // A display is set up
2817 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2818 display.inject();
2819
2820 // The current display state projection state is all set
2821 display.mutableCurrentDisplayState().orientation = initialOrientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002822 display.mutableCurrentDisplayState().orientedDisplaySpaceRect = initialOrientedDisplayRect;
2823 display.mutableCurrentDisplayState().layerStackSpaceRect = initialLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002824
2825 // The incoming request sets the same projection state
2826 DisplayState state;
2827 state.what = DisplayState::eDisplayProjectionChanged;
2828 state.token = display.token();
2829 state.orientation = initialOrientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002830 state.orientedDisplaySpaceRect = initialOrientedDisplayRect;
2831 state.layerStackSpaceRect = initialLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002832
2833 // --------------------------------------------------------------------
2834 // Invocation
2835
2836 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2837
2838 // --------------------------------------------------------------------
2839 // Postconditions
2840
2841 // The returned flags are empty
2842 EXPECT_EQ(0u, flags);
2843
2844 // The current display state is unchanged
2845 EXPECT_EQ(initialOrientation, display.getCurrentDisplayState().orientation);
2846
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002847 EXPECT_EQ(initialOrientedDisplayRect,
2848 display.getCurrentDisplayState().orientedDisplaySpaceRect);
2849 EXPECT_EQ(initialLayerStackRect, display.getCurrentDisplayState().layerStackSpaceRect);
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002850}
2851
2852TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfOrientationChanged) {
2853 using Case = SimplePrimaryDisplayCase;
Dominik Laskowski718f9602019-11-09 20:01:35 -08002854 constexpr ui::Rotation initialOrientation = ui::ROTATION_90;
2855 constexpr ui::Rotation desiredOrientation = ui::ROTATION_180;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002856
2857 // --------------------------------------------------------------------
2858 // Preconditions
2859
2860 // A display is set up
2861 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2862 display.inject();
2863
2864 // The current display state has an orientation set
2865 display.mutableCurrentDisplayState().orientation = initialOrientation;
2866
2867 // The incoming request sets a different orientation
2868 DisplayState state;
2869 state.what = DisplayState::eDisplayProjectionChanged;
2870 state.token = display.token();
2871 state.orientation = desiredOrientation;
2872
2873 // --------------------------------------------------------------------
2874 // Invocation
2875
2876 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2877
2878 // --------------------------------------------------------------------
2879 // Postconditions
2880
2881 // The returned flags indicate a transaction is needed
2882 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2883
2884 // The current display state has the new value.
2885 EXPECT_EQ(desiredOrientation, display.getCurrentDisplayState().orientation);
2886}
2887
2888TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfFrameChanged) {
2889 using Case = SimplePrimaryDisplayCase;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002890 const Rect initialOrientedDisplayRect = {0, 0, 0, 0};
2891 const Rect desiredOrientedDisplayRect = {5, 6, 7, 8};
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002892
2893 // --------------------------------------------------------------------
2894 // Preconditions
2895
2896 // A display is set up
2897 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2898 display.inject();
2899
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002900 // The current display state does not have a orientedDisplaySpaceRect
2901 display.mutableCurrentDisplayState().orientedDisplaySpaceRect = initialOrientedDisplayRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002902
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002903 // The incoming request sets a orientedDisplaySpaceRect
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002904 DisplayState state;
2905 state.what = DisplayState::eDisplayProjectionChanged;
2906 state.token = display.token();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002907 state.orientedDisplaySpaceRect = desiredOrientedDisplayRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002908
2909 // --------------------------------------------------------------------
2910 // Invocation
2911
2912 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2913
2914 // --------------------------------------------------------------------
2915 // Postconditions
2916
2917 // The returned flags indicate a transaction is needed
2918 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2919
2920 // The current display state has the new value.
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002921 EXPECT_EQ(desiredOrientedDisplayRect,
2922 display.getCurrentDisplayState().orientedDisplaySpaceRect);
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002923}
2924
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002925TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfLayerStackRectChanged) {
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002926 using Case = SimplePrimaryDisplayCase;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002927 const Rect initialLayerStackRect = {0, 0, 0, 0};
2928 const Rect desiredLayerStackRect = {5, 6, 7, 8};
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002929
2930 // --------------------------------------------------------------------
2931 // Preconditions
2932
2933 // A display is set up
2934 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2935 display.inject();
2936
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002937 // The current display state does not have a layerStackSpaceRect
2938 display.mutableCurrentDisplayState().layerStackSpaceRect = initialLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002939
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002940 // The incoming request sets a layerStackSpaceRect
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002941 DisplayState state;
2942 state.what = DisplayState::eDisplayProjectionChanged;
2943 state.token = display.token();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002944 state.layerStackSpaceRect = desiredLayerStackRect;
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002945
2946 // --------------------------------------------------------------------
2947 // Invocation
2948
2949 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2950
2951 // --------------------------------------------------------------------
2952 // Postconditions
2953
2954 // The returned flags indicate a transaction is needed
2955 EXPECT_EQ(eDisplayTransactionNeeded, flags);
2956
2957 // The current display state has the new value.
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002958 EXPECT_EQ(desiredLayerStackRect, display.getCurrentDisplayState().layerStackSpaceRect);
Lloyd Pique9d9cf402018-02-16 17:47:13 -08002959}
2960
2961TEST_F(DisplayTransactionTest, setDisplayStateLockedDoesNothingIfSizeDidNotChange) {
2962 using Case = SimplePrimaryDisplayCase;
2963 constexpr uint32_t initialWidth = 1024;
2964 constexpr uint32_t initialHeight = 768;
2965
2966 // --------------------------------------------------------------------
2967 // Preconditions
2968
2969 // A display is set up
2970 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
2971 display.inject();
2972
2973 // The current display state has a size set
2974 display.mutableCurrentDisplayState().width = initialWidth;
2975 display.mutableCurrentDisplayState().height = initialHeight;
2976
2977 // The incoming request sets the same display size
2978 DisplayState state;
2979 state.what = DisplayState::eDisplaySizeChanged;
2980 state.token = display.token();
2981 state.width = initialWidth;
2982 state.height = initialHeight;
2983
2984 // --------------------------------------------------------------------
2985 // Invocation
2986
2987 uint32_t flags = mFlinger.setDisplayStateLocked(state);
2988
2989 // --------------------------------------------------------------------
2990 // Postconditions
2991
2992 // The returned flags are empty
2993 EXPECT_EQ(0u, flags);
2994
2995 // The current display state is unchanged
2996 EXPECT_EQ(initialWidth, display.getCurrentDisplayState().width);
2997 EXPECT_EQ(initialHeight, display.getCurrentDisplayState().height);
2998}
2999
3000TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfWidthChanged) {
3001 using Case = SimplePrimaryDisplayCase;
3002 constexpr uint32_t initialWidth = 0;
3003 constexpr uint32_t desiredWidth = 1024;
3004
3005 // --------------------------------------------------------------------
3006 // Preconditions
3007
3008 // A display is set up
3009 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3010 display.inject();
3011
3012 // The display does not yet have a width
3013 display.mutableCurrentDisplayState().width = initialWidth;
3014
3015 // The incoming request sets a display width
3016 DisplayState state;
3017 state.what = DisplayState::eDisplaySizeChanged;
3018 state.token = display.token();
3019 state.width = desiredWidth;
3020
3021 // --------------------------------------------------------------------
3022 // Invocation
3023
3024 uint32_t flags = mFlinger.setDisplayStateLocked(state);
3025
3026 // --------------------------------------------------------------------
3027 // Postconditions
3028
3029 // The returned flags indicate a transaction is needed
3030 EXPECT_EQ(eDisplayTransactionNeeded, flags);
3031
3032 // The current display state has the new value.
3033 EXPECT_EQ(desiredWidth, display.getCurrentDisplayState().width);
3034}
3035
3036TEST_F(DisplayTransactionTest, setDisplayStateLockedRequestsUpdateIfHeightChanged) {
3037 using Case = SimplePrimaryDisplayCase;
3038 constexpr uint32_t initialHeight = 0;
3039 constexpr uint32_t desiredHeight = 768;
3040
3041 // --------------------------------------------------------------------
3042 // Preconditions
3043
3044 // A display is set up
3045 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3046 display.inject();
3047
3048 // The display does not yet have a height
3049 display.mutableCurrentDisplayState().height = initialHeight;
3050
3051 // The incoming request sets a display height
3052 DisplayState state;
3053 state.what = DisplayState::eDisplaySizeChanged;
3054 state.token = display.token();
3055 state.height = desiredHeight;
3056
3057 // --------------------------------------------------------------------
3058 // Invocation
3059
3060 uint32_t flags = mFlinger.setDisplayStateLocked(state);
3061
3062 // --------------------------------------------------------------------
3063 // Postconditions
3064
3065 // The returned flags indicate a transaction is needed
3066 EXPECT_EQ(eDisplayTransactionNeeded, flags);
3067
3068 // The current display state has the new value.
3069 EXPECT_EQ(desiredHeight, display.getCurrentDisplayState().height);
3070}
3071
Lloyd Pique86016da2018-03-01 16:09:38 -08003072/* ------------------------------------------------------------------------
3073 * SurfaceFlinger::onInitializeDisplays
3074 */
3075
3076TEST_F(DisplayTransactionTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
3077 using Case = SimplePrimaryDisplayCase;
3078
3079 // --------------------------------------------------------------------
3080 // Preconditions
3081
3082 // A primary display is set up
3083 Case::Display::injectHwcDisplay(this);
3084 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
3085 primaryDisplay.inject();
3086
3087 // --------------------------------------------------------------------
3088 // Call Expectations
3089
3090 // We expect the surface interceptor to possibly be used, but we treat it as
3091 // disabled since it is called as a side effect rather than directly by this
3092 // function.
3093 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
3094
3095 // We expect a call to get the active display config.
3096 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
3097
3098 // We expect invalidate() to be invoked once to trigger display transaction
3099 // processing.
3100 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
3101
Ady Abraham8cb21882020-08-26 18:22:05 -07003102 EXPECT_CALL(*mVSyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003103
Lloyd Pique86016da2018-03-01 16:09:38 -08003104 // --------------------------------------------------------------------
3105 // Invocation
3106
3107 mFlinger.onInitializeDisplays();
3108
3109 // --------------------------------------------------------------------
3110 // Postconditions
3111
3112 // The primary display should have a current state
3113 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
3114 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
3115 // The layer stack state should be set to zero
3116 EXPECT_EQ(0u, primaryDisplayState.layerStack);
3117 // The orientation state should be set to zero
Dominik Laskowski718f9602019-11-09 20:01:35 -08003118 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
Lloyd Pique86016da2018-03-01 16:09:38 -08003119
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003120 // The orientedDisplaySpaceRect state should be set to INVALID
3121 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.orientedDisplaySpaceRect);
Lloyd Pique86016da2018-03-01 16:09:38 -08003122
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003123 // The layerStackSpaceRect state should be set to INVALID
3124 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.layerStackSpaceRect);
Lloyd Pique86016da2018-03-01 16:09:38 -08003125
3126 // The width and height should both be zero
3127 EXPECT_EQ(0u, primaryDisplayState.width);
3128 EXPECT_EQ(0u, primaryDisplayState.height);
3129
Peiyong Lin65248e02020-04-18 21:15:07 -07003130 // The display should be set to PowerMode::ON
Lloyd Pique86016da2018-03-01 16:09:38 -08003131 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
3132 auto displayDevice = primaryDisplay.mutableDisplayDevice();
Peiyong Lin65248e02020-04-18 21:15:07 -07003133 EXPECT_EQ(PowerMode::ON, displayDevice->getPowerMode());
Lloyd Pique86016da2018-03-01 16:09:38 -08003134
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003135 // The display refresh period should be set in the orientedDisplaySpaceRect tracker.
Lloyd Pique86016da2018-03-01 16:09:38 -08003136 FrameStats stats;
3137 mFlinger.getAnimFrameTracker().getStats(&stats);
3138 EXPECT_EQ(DEFAULT_REFRESH_RATE, stats.refreshPeriodNano);
3139
3140 // The display transaction needed flag should be set.
3141 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
3142
3143 // The compositor timing should be set to default values
3144 const auto& compositorTiming = mFlinger.getCompositorTiming();
3145 EXPECT_EQ(-DEFAULT_REFRESH_RATE, compositorTiming.deadline);
3146 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.interval);
3147 EXPECT_EQ(DEFAULT_REFRESH_RATE, compositorTiming.presentLatency);
3148}
3149
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003150/* ------------------------------------------------------------------------
3151 * SurfaceFlinger::setPowerModeInternal
3152 */
3153
3154// Used when we simulate a display that supports doze.
Peiyong Lined531a32018-10-26 18:27:56 -07003155template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003156struct DozeIsSupportedVariant {
3157 static constexpr bool DOZE_SUPPORTED = true;
3158 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3159 IComposerClient::PowerMode::DOZE;
3160 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3161 IComposerClient::PowerMode::DOZE_SUSPEND;
Peiyong Lined531a32018-10-26 18:27:56 -07003162
3163 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3164 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003165 .WillOnce(DoAll(SetArgPointee<1>(
3166 std::vector<DisplayCapability>({DisplayCapability::DOZE})),
Peiyong Lined531a32018-10-26 18:27:56 -07003167 Return(Error::NONE)));
3168 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003169};
3170
Peiyong Lined531a32018-10-26 18:27:56 -07003171template <typename Display>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003172// Used when we simulate a display that does not support doze.
3173struct DozeNotSupportedVariant {
3174 static constexpr bool DOZE_SUPPORTED = false;
3175 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE =
3176 IComposerClient::PowerMode::ON;
3177 static constexpr IComposerClient::PowerMode ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND =
3178 IComposerClient::PowerMode::ON;
Peiyong Lined531a32018-10-26 18:27:56 -07003179
3180 static void setupComposerCallExpectations(DisplayTransactionTest* test) {
3181 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(Display::HWC_DISPLAY_ID, _))
Peiyong Line9d809e2020-04-14 13:10:48 -07003182 .WillOnce(DoAll(SetArgPointee<1>(std::vector<DisplayCapability>({})),
Peiyong Lined531a32018-10-26 18:27:56 -07003183 Return(Error::NONE)));
3184 }
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003185};
3186
3187struct EventThreadBaseSupportedVariant {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003188 static void setupVsyncAndEventThreadNoCallExpectations(DisplayTransactionTest* test) {
3189 // The callback should not be notified to toggle VSYNC.
3190 EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(_)).Times(0);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003191
3192 // The event thread should not be notified.
3193 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(0);
3194 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(0);
3195 }
3196};
3197
3198struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
3199 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
3200 // These calls are only expected for the primary display.
3201
3202 // Instead expect no calls.
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003203 setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003204 }
3205
3206 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
3207 // These calls are only expected for the primary display.
3208
3209 // Instead expect no calls.
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003210 setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003211 }
3212};
3213
3214struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
3215 static void setupAcquireAndEnableVsyncCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003216 // The callback should be notified to enable VSYNC.
3217 EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(true)).Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003218
3219 // The event thread should be notified that the screen was acquired.
3220 EXPECT_CALL(*test->mEventThread, onScreenAcquired()).Times(1);
3221 }
3222
3223 static void setupReleaseAndDisableVsyncCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003224 // The callback should be notified to disable VSYNC.
3225 EXPECT_CALL(test->mSchedulerCallback, setVsyncEnabled(false)).Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003226
3227 // The event thread should not be notified that the screen was released.
3228 EXPECT_CALL(*test->mEventThread, onScreenReleased()).Times(1);
3229 }
3230};
3231
Lloyd Pique41be5d22018-06-21 13:11:48 -07003232struct DispSyncIsSupportedVariant {
Ady Abraham8cb21882020-08-26 18:22:05 -07003233 static void setupResetModelCallExpectations(DisplayTransactionTest* test) {
3234 EXPECT_CALL(*test->mVsyncController, startPeriodTransition(DEFAULT_REFRESH_RATE)).Times(1);
3235 EXPECT_CALL(*test->mVSyncTracker, resetModel()).Times(1);
Lloyd Pique41be5d22018-06-21 13:11:48 -07003236 }
Lloyd Pique41be5d22018-06-21 13:11:48 -07003237};
3238
3239struct DispSyncNotSupportedVariant {
Ady Abraham8cb21882020-08-26 18:22:05 -07003240 static void setupResetModelCallExpectations(DisplayTransactionTest* /* test */) {}
Lloyd Pique41be5d22018-06-21 13:11:48 -07003241};
3242
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003243// --------------------------------------------------------------------
3244// Note:
3245//
3246// There are a large number of transitions we could test, however we only test a
3247// selected subset which provides complete test coverage of the implementation.
3248// --------------------------------------------------------------------
3249
Peiyong Lin65248e02020-04-18 21:15:07 -07003250template <PowerMode initialPowerMode, PowerMode targetPowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003251struct TransitionVariantCommon {
3252 static constexpr auto INITIAL_POWER_MODE = initialPowerMode;
3253 static constexpr auto TARGET_POWER_MODE = targetPowerMode;
3254
3255 static void verifyPostconditions(DisplayTransactionTest*) {}
3256};
3257
Peiyong Lin65248e02020-04-18 21:15:07 -07003258struct TransitionOffToOnVariant : public TransitionVariantCommon<PowerMode::OFF, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003259 template <typename Case>
3260 static void setupCallExpectations(DisplayTransactionTest* test) {
3261 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3262 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Ady Abraham8cb21882020-08-26 18:22:05 -07003263 Case::DispSync::setupResetModelCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003264 Case::setupRepaintEverythingCallExpectations(test);
3265 }
3266
3267 static void verifyPostconditions(DisplayTransactionTest* test) {
3268 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3269 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3270 }
3271};
3272
3273struct TransitionOffToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003274 : public TransitionVariantCommon<PowerMode::OFF, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003275 template <typename Case>
3276 static void setupCallExpectations(DisplayTransactionTest* test) {
3277 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003278 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003279 Case::setupRepaintEverythingCallExpectations(test);
3280 }
3281
3282 static void verifyPostconditions(DisplayTransactionTest* test) {
3283 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3284 EXPECT_TRUE(test->mFlinger.getHasPoweredOff());
3285 }
3286};
3287
Peiyong Lin65248e02020-04-18 21:15:07 -07003288struct TransitionOnToOffVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003289 template <typename Case>
3290 static void setupCallExpectations(DisplayTransactionTest* test) {
3291 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
3292 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3293 }
3294
3295 static void verifyPostconditions(DisplayTransactionTest* test) {
3296 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3297 }
3298};
3299
3300struct TransitionDozeSuspendToOffVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003301 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::OFF> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003302 template <typename Case>
3303 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003304 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003305 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
3306 }
3307
3308 static void verifyPostconditions(DisplayTransactionTest* test) {
3309 EXPECT_TRUE(test->mFlinger.getVisibleRegionsDirty());
3310 }
3311};
3312
Peiyong Lin65248e02020-04-18 21:15:07 -07003313struct TransitionOnToDozeVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003314 template <typename Case>
3315 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003316 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003317 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3318 }
3319};
3320
3321struct TransitionDozeSuspendToDozeVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003322 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::DOZE> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003323 template <typename Case>
3324 static void setupCallExpectations(DisplayTransactionTest* test) {
3325 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Ady Abraham8cb21882020-08-26 18:22:05 -07003326 Case::DispSync::setupResetModelCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003327 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
3328 }
3329};
3330
Peiyong Lin65248e02020-04-18 21:15:07 -07003331struct TransitionDozeToOnVariant : public TransitionVariantCommon<PowerMode::DOZE, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003332 template <typename Case>
3333 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003334 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003335 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3336 }
3337};
3338
3339struct TransitionDozeSuspendToOnVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003340 : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::ON> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003341 template <typename Case>
3342 static void setupCallExpectations(DisplayTransactionTest* test) {
3343 Case::EventThread::setupAcquireAndEnableVsyncCallExpectations(test);
Ady Abraham8cb21882020-08-26 18:22:05 -07003344 Case::DispSync::setupResetModelCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003345 Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
3346 }
3347};
3348
3349struct TransitionOnToDozeSuspendVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003350 : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE_SUSPEND> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003351 template <typename Case>
3352 static void setupCallExpectations(DisplayTransactionTest* test) {
3353 Case::EventThread::setupReleaseAndDisableVsyncCallExpectations(test);
3354 Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
3355 }
3356};
3357
3358struct TransitionOnToUnknownVariant
Peiyong Lin65248e02020-04-18 21:15:07 -07003359 : public TransitionVariantCommon<PowerMode::ON, static_cast<PowerMode>(POWER_MODE_LEET)> {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003360 template <typename Case>
3361 static void setupCallExpectations(DisplayTransactionTest* test) {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -07003362 Case::EventThread::setupVsyncAndEventThreadNoCallExpectations(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003363 Case::setupNoComposerPowerModeCallExpectations(test);
3364 }
3365};
3366
3367// --------------------------------------------------------------------
3368// Note:
3369//
3370// Rather than testing the cartesian product of of
3371// DozeIsSupported/DozeNotSupported with all other options, we use one for one
3372// display type, and the other for another display type.
3373// --------------------------------------------------------------------
3374
3375template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
Lloyd Pique41be5d22018-06-21 13:11:48 -07003376 typename DispSyncVariant, typename TransitionVariant>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003377struct DisplayPowerCase {
3378 using Display = DisplayVariant;
3379 using Doze = DozeVariant;
3380 using EventThread = EventThreadVariant;
Lloyd Pique41be5d22018-06-21 13:11:48 -07003381 using DispSync = DispSyncVariant;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003382 using Transition = TransitionVariant;
3383
Peiyong Lin65248e02020-04-18 21:15:07 -07003384 static auto injectDisplayWithInitialPowerMode(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -08003385 Display::injectHwcDisplayWithNoDefaultCapabilities(test);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003386 auto display = Display::makeFakeExistingDisplayInjector(test);
3387 display.inject();
3388 display.mutableDisplayDevice()->setPowerMode(mode);
3389 return display;
3390 }
3391
3392 static void setInitialPrimaryHWVsyncEnabled(DisplayTransactionTest* test, bool enabled) {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -07003393 test->mFlinger.scheduler()->mutablePrimaryHWVsyncEnabled() = enabled;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003394 }
3395
3396 static void setupRepaintEverythingCallExpectations(DisplayTransactionTest* test) {
3397 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
3398 }
3399
Peiyong Lin65248e02020-04-18 21:15:07 -07003400 static void setupSurfaceInterceptorCallExpectations(DisplayTransactionTest* test,
3401 PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003402 EXPECT_CALL(*test->mSurfaceInterceptor, isEnabled()).WillOnce(Return(true));
Peiyong Lin65248e02020-04-18 21:15:07 -07003403 EXPECT_CALL(*test->mSurfaceInterceptor, savePowerModeUpdate(_, static_cast<int32_t>(mode)))
3404 .Times(1);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003405 }
3406
Peiyong Lin65248e02020-04-18 21:15:07 -07003407 static void setupComposerCallExpectations(DisplayTransactionTest* test, PowerMode mode) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003408 // Any calls to get the active config will return a default value.
3409 EXPECT_CALL(*test->mComposer, getActiveConfig(Display::HWC_DISPLAY_ID, _))
3410 .WillRepeatedly(DoAll(SetArgPointee<1>(Display::HWC_ACTIVE_CONFIG_ID),
3411 Return(Error::NONE)));
3412
3413 // Any calls to get whether the display supports dozing will return the value set by the
3414 // policy variant.
3415 EXPECT_CALL(*test->mComposer, getDozeSupport(Display::HWC_DISPLAY_ID, _))
3416 .WillRepeatedly(DoAll(SetArgPointee<1>(Doze::DOZE_SUPPORTED), Return(Error::NONE)));
3417
3418 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, mode)).Times(1);
3419 }
3420
3421 static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
3422 EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
3423 }
3424};
3425
3426// A sample configuration for the primary display.
3427// In addition to having event thread support, we emulate doze support.
3428template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003429using PrimaryDisplayPowerCase =
3430 DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
3431 EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
3432 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003433
3434// A sample configuration for the external display.
3435// In addition to not having event thread support, we emulate not having doze
3436// support.
3437template <typename TransitionVariant>
Peiyong Lined531a32018-10-26 18:27:56 -07003438using ExternalDisplayPowerCase =
3439 DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
3440 EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
3441 TransitionVariant>;
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003442
3443class SetPowerModeInternalTest : public DisplayTransactionTest {
3444public:
3445 template <typename Case>
3446 void transitionDisplayCommon();
3447};
3448
Peiyong Lin65248e02020-04-18 21:15:07 -07003449template <PowerMode PowerMode>
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003450struct PowerModeInitialVSyncEnabled : public std::false_type {};
3451
3452template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003453struct PowerModeInitialVSyncEnabled<PowerMode::ON> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003454
3455template <>
Peiyong Lin65248e02020-04-18 21:15:07 -07003456struct PowerModeInitialVSyncEnabled<PowerMode::DOZE> : public std::true_type {};
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003457
3458template <typename Case>
3459void SetPowerModeInternalTest::transitionDisplayCommon() {
3460 // --------------------------------------------------------------------
3461 // Preconditions
3462
Peiyong Lined531a32018-10-26 18:27:56 -07003463 Case::Doze::setupComposerCallExpectations(this);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003464 auto display =
3465 Case::injectDisplayWithInitialPowerMode(this, Case::Transition::INITIAL_POWER_MODE);
3466 Case::setInitialPrimaryHWVsyncEnabled(this,
3467 PowerModeInitialVSyncEnabled<
3468 Case::Transition::INITIAL_POWER_MODE>::value);
3469
3470 // --------------------------------------------------------------------
3471 // Call Expectations
3472
3473 Case::setupSurfaceInterceptorCallExpectations(this, Case::Transition::TARGET_POWER_MODE);
3474 Case::Transition::template setupCallExpectations<Case>(this);
3475
3476 // --------------------------------------------------------------------
3477 // Invocation
3478
3479 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(),
3480 Case::Transition::TARGET_POWER_MODE);
3481
3482 // --------------------------------------------------------------------
3483 // Postconditions
3484
3485 Case::Transition::verifyPostconditions(this);
3486}
3487
3488TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfNoChange) {
3489 using Case = SimplePrimaryDisplayCase;
3490
3491 // --------------------------------------------------------------------
3492 // Preconditions
3493
3494 // A primary display device is set up
3495 Case::Display::injectHwcDisplay(this);
3496 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3497 display.inject();
3498
Peiyong Lin65248e02020-04-18 21:15:07 -07003499 // The display is already set to PowerMode::ON
3500 display.mutableDisplayDevice()->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003501
3502 // --------------------------------------------------------------------
3503 // Invocation
3504
Peiyong Lin65248e02020-04-18 21:15:07 -07003505 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003506
3507 // --------------------------------------------------------------------
3508 // Postconditions
3509
Peiyong Lin65248e02020-04-18 21:15:07 -07003510 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003511}
3512
Dominik Laskowskieecd6592018-05-29 10:25:41 -07003513TEST_F(SetPowerModeInternalTest, setPowerModeInternalDoesNothingIfVirtualDisplay) {
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003514 using Case = HwcVirtualDisplayCase;
3515
3516 // --------------------------------------------------------------------
3517 // Preconditions
3518
Dominik Laskowski075d3172018-05-24 15:50:06 -07003519 // Insert display data so that the HWC thinks it created the virtual display.
3520 const auto displayId = Case::Display::DISPLAY_ID::get();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02003521 ASSERT_TRUE(HalVirtualDisplayId::tryCast(displayId));
3522 mFlinger.mutableHwcDisplayData().try_emplace(displayId);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003523
3524 // A virtual display device is set up
3525 Case::Display::injectHwcDisplay(this);
3526 auto display = Case::Display::makeFakeExistingDisplayInjector(this);
3527 display.inject();
3528
Peiyong Lin65248e02020-04-18 21:15:07 -07003529 // The display is set to PowerMode::ON
3530 getDisplayDevice(display.token())->setPowerMode(PowerMode::ON);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003531
3532 // --------------------------------------------------------------------
3533 // Invocation
3534
Peiyong Lin65248e02020-04-18 21:15:07 -07003535 mFlinger.setPowerModeInternal(display.mutableDisplayDevice(), PowerMode::OFF);
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003536
3537 // --------------------------------------------------------------------
3538 // Postconditions
3539
Peiyong Lin65248e02020-04-18 21:15:07 -07003540 EXPECT_EQ(PowerMode::ON, display.mutableDisplayDevice()->getPowerMode());
Lloyd Pique7d4aa6c2018-03-01 16:36:35 -08003541}
3542
3543TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnPrimaryDisplay) {
3544 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToOnVariant>>();
3545}
3546
3547TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendPrimaryDisplay) {
3548 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3549}
3550
3551TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffPrimaryDisplay) {
3552 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToOffVariant>>();
3553}
3554
3555TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffPrimaryDisplay) {
3556 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3557}
3558
3559TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozePrimaryDisplay) {
3560 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeVariant>>();
3561}
3562
3563TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozePrimaryDisplay) {
3564 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3565}
3566
3567TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnPrimaryDisplay) {
3568 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeToOnVariant>>();
3569}
3570
3571TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnPrimaryDisplay) {
3572 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3573}
3574
3575TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendPrimaryDisplay) {
3576 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3577}
3578
3579TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownPrimaryDisplay) {
3580 transitionDisplayCommon<PrimaryDisplayPowerCase<TransitionOnToUnknownVariant>>();
3581}
3582
3583TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToOnExternalDisplay) {
3584 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToOnVariant>>();
3585}
3586
3587TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOffToDozeSuspendExternalDisplay) {
3588 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOffToDozeSuspendVariant>>();
3589}
3590
3591TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToOffExternalDisplay) {
3592 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToOffVariant>>();
3593}
3594
3595TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOffExternalDisplay) {
3596 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOffVariant>>();
3597}
3598
3599TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeExternalDisplay) {
3600 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeVariant>>();
3601}
3602
3603TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToDozeExternalDisplay) {
3604 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToDozeVariant>>();
3605}
3606
3607TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeToOnExternalDisplay) {
3608 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeToOnVariant>>();
3609}
3610
3611TEST_F(SetPowerModeInternalTest, transitionsDisplayFromDozeSuspendToOnExternalDisplay) {
3612 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionDozeSuspendToOnVariant>>();
3613}
3614
3615TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToDozeSuspendExternalDisplay) {
3616 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToDozeSuspendVariant>>();
3617}
3618
3619TEST_F(SetPowerModeInternalTest, transitionsDisplayFromOnToUnknownExternalDisplay) {
3620 transitionDisplayCommon<ExternalDisplayPowerCase<TransitionOnToUnknownVariant>>();
3621}
3622
Lloyd Piquef58625d2017-12-19 13:22:33 -08003623} // namespace
3624} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08003625
3626// TODO(b/129481165): remove the #pragma below and fix conversion issues
3627#pragma clang diagnostic pop // ignored "-Wconversion"