blob: e546c2f8c90c470d668afe86d6f575a64a31329d [file] [log] [blame]
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001/*
2 * Copyright 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
Alec Mouria90a5702021-04-16 16:36:21 +000018#include "renderengine/ExternalTexture.h"
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080019#pragma clang diagnostic push
20#pragma clang diagnostic ignored "-Wconversion"
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010021#pragma clang diagnostic ignored "-Wextra"
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080022
Lloyd Piqued6b579f2018-04-06 15:29:10 -070023#undef LOG_TAG
24#define LOG_TAG "CompositionTest"
25
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080026#include <compositionengine/Display.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070027#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070028#include <gmock/gmock.h>
29#include <gtest/gtest.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070030#include <gui/IProducerListener.h>
Evan Roskya1f1e152019-01-24 16:17:46 -080031#include <gui/LayerMetadata.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070032#include <log/log.h>
Vishnu Nairdbbe3852022-01-12 20:22:11 -080033#include <renderengine/mock/FakeExternalTexture.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070034#include <renderengine/mock/Framebuffer.h>
35#include <renderengine/mock/Image.h>
36#include <renderengine/mock/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070037#include <system/window.h>
38#include <utils/String8.h>
39
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020040#include "DisplayRenderArea.h"
Vishnu Nairfa247b12020-02-11 08:58:26 -080041#include "EffectLayer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070042#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070043#include "TestableSurfaceFlinger.h"
44#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique9370a482019-10-03 17:58:30 -070045#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070046#include "mock/MockEventThread.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080047#include "mock/MockTimeStats.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070048#include "mock/MockVsyncController.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070049#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070050
51namespace android {
52namespace {
53
Peiyong Line9d809e2020-04-14 13:10:48 -070054namespace hal = android::hardware::graphics::composer::hal;
55
Peiyong Lin65248e02020-04-18 21:15:07 -070056using hal::Error;
57using hal::IComposer;
58using hal::IComposerClient;
59using hal::PowerMode;
60using hal::Transform;
61
Ady Abrahamde549d42022-01-26 19:19:17 -080062using aidl::android::hardware::graphics::composer3::Capability;
63
Lloyd Piqued6b579f2018-04-06 15:29:10 -070064using testing::_;
David Sodman15094112018-10-11 09:39:37 -070065using testing::AtLeast;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070066using testing::DoAll;
67using testing::IsNull;
68using testing::Mock;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070069using testing::Return;
70using testing::ReturnRef;
71using testing::SetArgPointee;
72
Lloyd Piqued6b579f2018-04-06 15:29:10 -070073using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
74using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
75
Peiyong Line9d809e2020-04-14 13:10:48 -070076constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
77constexpr hal::HWLayerId HWC_LAYER = 5000;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070078constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
79
Dominik Laskowskif1833852021-03-23 15:06:50 -070080constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
Lloyd Piqued6b579f2018-04-06 15:29:10 -070081constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
82constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
83
Lloyd Piqued6b579f2018-04-06 15:29:10 -070084constexpr int DEFAULT_TEXTURE_ID = 6000;
Dominik Laskowski29fa1462021-04-27 15:51:50 -070085constexpr ui::LayerStack LAYER_STACK{7000u};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070086
87constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
88
89constexpr int DEFAULT_SIDEBAND_STREAM = 51;
90
Ady Abrahamdc011a92021-12-21 14:06:44 -080091MATCHER(IsIdentityMatrix, "") {
92 constexpr auto kIdentity = mat4();
93 return (mat4(arg) == kIdentity);
94}
95
Lloyd Piqued6b579f2018-04-06 15:29:10 -070096class CompositionTest : public testing::Test {
97public:
98 CompositionTest() {
99 const ::testing::TestInfo* const test_info =
100 ::testing::UnitTest::GetInstance()->current_test_info();
101 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
102
Ana Krulecafb45842019-02-13 13:33:03 -0800103 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700104
Alec Mourif6fd29e2018-11-17 04:56:41 +0000105 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
106 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
107 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
108 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700109
110 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800111 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800112
113 mComposer = new Hwc2::mock::Composer();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000114 mPowerAdvisor = new Hwc2::mock::PowerAdvisor();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800115 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Xiang Wang839fe5b2022-04-04 17:39:38 +0000116 mFlinger.setupPowerAdvisor(std::unique_ptr<Hwc2::PowerAdvisor>(mPowerAdvisor));
Garfield Tan9c9c1912021-07-19 12:02:16 -0700117 mFlinger.mutableMaxRenderTargetSize() = 16384;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700118 }
119
120 ~CompositionTest() {
121 const ::testing::TestInfo* const test_info =
122 ::testing::UnitTest::GetInstance()->current_test_info();
123 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
124 }
125
Ana Krulecafb45842019-02-13 13:33:03 -0800126 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700127 auto eventThread = std::make_unique<mock::EventThread>();
128 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800129
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700130 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700131 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abrahamd11bade2022-08-01 16:18:03 -0700132 .WillOnce(Return(sp<EventThreadConnection>::make(eventThread.get(),
133 mock::EventThread::kCallingUid,
134 ResyncCallback())));
Dominik Laskowski98041832019-08-01 18:35:59 -0700135
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700136 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700137 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abrahamd11bade2022-08-01 16:18:03 -0700138 .WillOnce(Return(sp<EventThreadConnection>::make(sfEventThread.get(),
139 mock::EventThread::kCallingUid,
140 ResyncCallback())));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700141
Ady Abraham8cb21882020-08-26 18:22:05 -0700142 auto vsyncController = std::make_unique<mock::VsyncController>();
143 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700144
Ady Abraham8cb21882020-08-26 18:22:05 -0700145 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
146 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100147 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700148 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700149
Ady Abraham8cb21882020-08-26 18:22:05 -0700150 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
Dominik Laskowski83bd7712022-01-07 14:30:53 -0800151 std::move(eventThread), std::move(sfEventThread),
152 TestableSurfaceFlinger::SchedulerCallbackImpl::kNoOp,
153 TestableSurfaceFlinger::kTwoDisplayModes);
Ana Krulecafb45842019-02-13 13:33:03 -0800154 }
155
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700156 void setupForceGeometryDirty() {
157 // TODO: This requires the visible region and other related
158 // state to be set, and is problematic for BufferLayers since they are
159 // not visible without a buffer (and setting up a buffer looks like a
160 // pain)
161 // mFlinger.mutableVisibleRegionsDirty() = true;
162
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700163 mFlinger.mutableGeometryDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700164 }
165
166 template <typename Case>
167 void displayRefreshCompositionDirtyGeometry();
168
169 template <typename Case>
170 void displayRefreshCompositionDirtyFrame();
171
172 template <typename Case>
173 void captureScreenComposition();
174
Ady Abrahamde549d42022-01-26 19:19:17 -0800175 std::unordered_set<Capability> mDefaultCapabilities = {Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700176
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800177 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700178 TestableSurfaceFlinger mFlinger;
179 sp<DisplayDevice> mDisplay;
180 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700181 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700182 sp<compositionengine::mock::DisplaySurface>::make();
183 sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make();
Garfield Tande619fa2020-10-02 17:13:53 -0700184 std::vector<sp<Layer>> mAuxiliaryLayers;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700185
Ady Abrahamd11bade2022-08-01 16:18:03 -0700186 sp<GraphicBuffer> mBuffer = sp<GraphicBuffer>::make();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800187 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
188
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700189 Hwc2::mock::Composer* mComposer = nullptr;
190 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800191 mock::TimeStats* mTimeStats = new mock::TimeStats();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000192 Hwc2::mock::PowerAdvisor* mPowerAdvisor = nullptr;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700193
194 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
195
Alec Mouria90a5702021-04-16 16:36:21 +0000196 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700197};
198
199template <typename LayerCase>
200void CompositionTest::displayRefreshCompositionDirtyGeometry() {
201 setupForceGeometryDirty();
202 LayerCase::setupForDirtyGeometry(this);
203
204 // --------------------------------------------------------------------
205 // Invocation
206
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700207 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700208
209 LayerCase::cleanup(this);
210}
211
212template <typename LayerCase>
213void CompositionTest::displayRefreshCompositionDirtyFrame() {
214 LayerCase::setupForDirtyFrame(this);
215
216 // --------------------------------------------------------------------
217 // Invocation
218
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700219 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700220
221 LayerCase::cleanup(this);
222}
223
224template <typename LayerCase>
225void CompositionTest::captureScreenComposition() {
226 LayerCase::setupForScreenCapture(this);
227
228 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700229 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700230 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700231
Marin Shalamanov1c434292020-06-12 01:47:29 +0200232 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
233 ui::Dataspace::V0_SRGB, ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700234
235 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700236 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
237 CaptureArgs::UNSET_UID, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700238 };
239
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700240 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
241 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800242 mCaptureScreenBuffer =
243 std::make_shared<renderengine::mock::FakeExternalTexture>(renderArea->getReqWidth(),
244 renderArea->getReqHeight(),
245 HAL_PIXEL_FORMAT_RGBA_8888, 1,
246 usage);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700247
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700248 auto future = mFlinger.renderScreenImpl(*renderArea, traverseLayers, mCaptureScreenBuffer,
Robert Carr12a3b9b2022-03-10 09:55:29 -0800249 forSystem, regionSampling);
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700250 ASSERT_TRUE(future.valid());
251 const auto fenceResult = future.get();
Sally Qi59a9f502021-10-12 18:53:23 +0000252
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700253 EXPECT_EQ(NO_ERROR, fenceStatus(fenceResult));
254 if (fenceResult.ok()) {
255 fenceResult.value()->waitForever(LOG_TAG);
Sally Qi59a9f502021-10-12 18:53:23 +0000256 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700257
258 LayerCase::cleanup(this);
259}
260
Sally Qi4cabdd02021-08-05 16:45:57 -0700261template <class T>
262std::future<T> futureOf(T obj) {
263 std::promise<T> resultPromise;
264 std::future<T> resultFuture = resultPromise.get_future();
265 resultPromise.set_value(std::move(obj));
266 return resultFuture;
267}
268
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700269/* ------------------------------------------------------------------------
270 * Variants for each display configuration which can be tested
271 */
272
273template <typename Derived>
274struct BaseDisplayVariant {
275 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700276 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700277
278 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700279 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700280 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700281
Peiyong Line9d809e2020-04-14 13:10:48 -0700282 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700283 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700284 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700285 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800286 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700287
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800288 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
289 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
290 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
291 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
292 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
293 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
294 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique9370a482019-10-03 17:58:30 -0700295
296 const ::testing::TestInfo* const test_info =
297 ::testing::UnitTest::GetInstance()->current_test_info();
298
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800299 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
300 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800301 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
302 .setIsSecure(Derived::IS_SECURE)
Xiang Wang839fe5b2022-04-04 17:39:38 +0000303 .setPowerAdvisor(test->mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800304 .setName(std::string("Injected display for ") +
305 test_info->test_case_name() + "." + test_info->name())
306 .build();
Lloyd Pique9370a482019-10-03 17:58:30 -0700307
308 auto compositionDisplay =
309 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
310 ceDisplayArgs);
311
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700312 constexpr auto kDisplayConnectionType = ui::DisplayConnectionType::Internal;
313 constexpr bool kIsPrimary = true;
314
Marin Shalamanov700e6392020-02-12 20:22:26 +0100315 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700316 kDisplayConnectionType, HWC_DISPLAY, kIsPrimary)
Marin Shalamanov700e6392020-02-12 20:22:26 +0100317 .setDisplaySurface(test->mDisplaySurface)
318 .setNativeWindow(test->mNativeWindow)
319 .setSecure(Derived::IS_SECURE)
320 .setPowerMode(Derived::INIT_POWER_MODE)
321 .inject();
Ady Abrahamd11bade2022-08-01 16:18:03 -0700322 Mock::VerifyAndClear(test->mNativeWindow.get());
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700323
324 constexpr bool kIsInternal = kDisplayConnectionType == ui::DisplayConnectionType::Internal;
325 test->mDisplay->setLayerFilter({LAYER_STACK, kIsInternal});
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700326 }
327
328 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700329 static void setupPreconditionCallExpectations(CompositionTest* test) {
330 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500331 .WillOnce(DoAll(SetArgPointee<1>(
332 std::vector<aidl::android::hardware::graphics::composer3::
333 DisplayCapability>({})),
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700334 Return(Error::NONE)));
335 }
336
337 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700338 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Ady Abrahamdc011a92021-12-21 14:06:44 -0800339 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700340 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
341 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
342 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
343 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
344
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700345 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
346 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
347
348 Case::CompositionType::setupHwcSetCallExpectations(test);
349 Case::CompositionType::setupHwcGetCallExpectations(test);
350 }
351
352 template <typename Case>
353 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000354 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700355 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000356 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700357 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000358 const bool, base::unique_fd&&) -> std::future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700359 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
360 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
361 displaySettings.physicalDisplay);
362 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
363 displaySettings.clip);
Patrick Williams2e9748f2022-08-09 22:48:18 +0000364 return futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Pique9370a482019-10-03 17:58:30 -0700365 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700366 }
367
368 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
369 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
370 }
371
372 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
373 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
374 }
375
376 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800377 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
378 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800379
Lloyd Pique542307f2018-10-19 13:24:08 -0700380 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700381 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700382 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700383 }
384
Lloyd Pique66d68602019-02-13 14:23:31 -0800385 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800386 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
387 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800388 }
389
390 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800391 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800392 }
393
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700394 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700395 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700396 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700397 .Times(1);
398 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
399 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
400
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800401 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
402 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
403 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
404 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000405 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700406 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000407 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700408 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000409 const bool, base::unique_fd&&) -> std::future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700410 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
411 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
412 displaySettings.physicalDisplay);
413 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
414 displaySettings.clip);
415 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Patrick Williams2e9748f2022-08-09 22:48:18 +0000416 return futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Pique9370a482019-10-03 17:58:30 -0700417 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700418 }
419
420 template <typename Case>
421 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
422 Case::Layer::setupRECompositionCallExpectations(test);
423 }
424
425 template <typename Case>
426 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
427 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700428 }
429};
430
431struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
432
433struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
434 static constexpr bool IS_SECURE = false;
435
436 template <typename Case>
437 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
438 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700439 }
440
441 template <typename Case>
442 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
443 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700444 }
445};
446
447struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700448 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700449
450 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700451 static void setupPreconditionCallExpectations(CompositionTest*) {}
452
453 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700454 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
455 // TODO: This seems like an unnecessary call if display is powered off.
Ady Abrahamdc011a92021-12-21 14:06:44 -0800456 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700457
458 // TODO: This seems like an unnecessary call if display is powered off.
459 Case::CompositionType::setupHwcSetCallExpectations(test);
460 }
461
462 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800463 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
464 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700465
466 static void setupRECompositionCallExpectations(CompositionTest* test) {
467 // TODO: This seems like an unnecessary call if display is powered off.
468 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
469 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
470 }
471
472 template <typename Case>
473 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
474};
475
476/* ------------------------------------------------------------------------
477 * Variants for each layer configuration which can be tested
478 */
479
480template <typename LayerProperties>
481struct BaseLayerProperties {
482 static constexpr uint32_t WIDTH = 100;
483 static constexpr uint32_t HEIGHT = 100;
484 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
485 static constexpr uint64_t USAGE =
486 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
487 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
488 static constexpr uint32_t SCALING_MODE = 0;
489 static constexpr uint32_t TRANSFORM = 0;
490 static constexpr uint32_t LAYER_FLAGS = 0;
491 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
492 static constexpr IComposerClient::BlendMode BLENDMODE =
493 IComposerClient::BlendMode::PREMULTIPLIED;
494
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000495 static void setupLatchedBuffer(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700496 Mock::VerifyAndClear(test->mRenderEngine);
497
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000498 const auto buffer = std::make_shared<
499 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
500 LayerProperties::HEIGHT,
501 DEFAULT_TEXTURE_ID,
502 LayerProperties::FORMAT,
503 LayerProperties::USAGE |
504 GraphicBuffer::USAGE_HW_TEXTURE);
505
506 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
507 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
508 layerDrawingState.buffer = buffer;
509 layerDrawingState.acquireFence = Fence::NO_FENCE;
510 layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
511 layer->setSurfaceDamageRegion(
512 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700513
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700514 bool ignoredRecomputeVisibleRegions;
Vishnu Nair397a0e32022-07-26 00:01:48 +0000515 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700516 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700517 }
518
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000519 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700520 setupLatchedBuffer(test, layer);
521 }
522
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700523 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800524 if (!test->mDisplayOff) {
525 // TODO: Coverage of other values
526 EXPECT_CALL(*test->mComposer,
527 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
528 .Times(1);
529 // TODO: Coverage of other values for origin
530 EXPECT_CALL(*test->mComposer,
531 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
532 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
533 LayerProperties::HEIGHT})))
534 .Times(1);
535 EXPECT_CALL(*test->mComposer,
536 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
537 .Times(1);
538 // TODO: Coverage of other values
539 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700540
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800541 // These expectations retire on saturation as the code path these
542 // expectations are for appears to make an extra call to them.
543 // TODO: Investigate this extra call
544 EXPECT_CALL(*test->mComposer,
545 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
546 .Times(AtLeast(1))
547 .RetiresOnSaturation();
548 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700549 }
550
551 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800552 if (!test->mDisplayOff) {
553 EXPECT_CALL(*test->mComposer,
554 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
555 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
556 LayerProperties::HEIGHT})))
557 .Times(1);
558 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700559 }
560
561 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800562 if (!test->mDisplayOff) {
563 EXPECT_CALL(*test->mComposer,
564 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
565 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
566 .Times(1);
567 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700568 }
569
570 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800571 if (!test->mDisplayOff) {
572 EXPECT_CALL(*test->mComposer,
573 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
574 std::vector<IComposerClient::Rect>(
575 {IComposerClient::Rect(
576 {0, 0, LayerProperties::WIDTH,
577 LayerProperties::HEIGHT})})))
578 .Times(1);
579 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700580 }
581
582 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800583 if (!test->mDisplayOff) {
584 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
585 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700586
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800587 // TODO: use COLOR
588 EXPECT_CALL(*test->mComposer,
589 setLayerColor(HWC_DISPLAY, HWC_LAYER,
Ady Abraham6e60b142022-01-06 18:10:35 -0800590 aidl::android::hardware::graphics::composer3::Color(
591 {1.0f, 1.0f, 1.0f, 1.0f})))
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800592 .Times(1);
593 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700594 }
595
596 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800597 if (!test->mDisplayOff) {
598 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
599 .Times(1);
600 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
601 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700602 }
603
604 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000605 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700606 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000607 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700608 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000609 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000610 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
611 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
612 displaySettings.physicalDisplay);
613 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
614 displaySettings.clip);
615 // screen capture adds an additional color layer as an alpha
616 // prefill, so gtet the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000617 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800618 if (layerSettings.empty()) {
619 ADD_FAILURE() << "layerSettings was not expected to be empty in "
620 "setupREBufferCompositionCommonCallExpectations "
621 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700622 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800623 }
Sally Qi59a9f502021-10-12 18:53:23 +0000624 const renderengine::LayerSettings layer = layerSettings.back();
625 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
626 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
627 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
628 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
629 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
630 EXPECT_EQ(false, layer.source.buffer.isOpaque);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700631 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
632 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000633 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
634 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700635 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000636 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700637 }
638
639 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
640 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700641 }
642
643 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
644 setupREBufferCompositionCallExpectations(test);
645 }
646
647 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
648 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
649 }
650
651 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
652 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
653 }
654
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700655 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000656 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700657 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000658 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700659 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000660 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000661 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
662 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
663 displaySettings.physicalDisplay);
664 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
665 displaySettings.clip);
666 // screen capture adds an additional color layer as an alpha
667 // prefill, so get the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000668 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800669 if (layerSettings.empty()) {
670 ADD_FAILURE()
671 << "layerSettings was not expected to be empty in "
672 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700673 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800674 }
Sally Qi59a9f502021-10-12 18:53:23 +0000675 const renderengine::LayerSettings layer = layerSettings.back();
676 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000677 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
678 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000679 layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700680 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
681 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000682 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
683 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700684 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000685 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700686 }
687
688 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
689 setupREColorCompositionCallExpectations(test);
690 }
691};
692
693struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
694
Vishnu Nairfa247b12020-02-11 08:58:26 -0800695struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800696 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
697};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700698
699struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
700 using Base = BaseLayerProperties<SidebandLayerProperties>;
701 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
702
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000703 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700704 sp<NativeHandle> stream =
705 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
706 false);
707 test->mFlinger.setLayerSidebandStream(layer, stream);
708 }
709
710 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
711 EXPECT_CALL(*test->mComposer,
712 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
713 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
714 .Times(1);
715 }
716
717 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
718 EXPECT_CALL(*test->mComposer,
719 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
720 reinterpret_cast<native_handle_t*>(
721 DEFAULT_SIDEBAND_STREAM)))
722 .WillOnce(Return(Error::NONE));
723
724 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
725 }
726
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000727 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700728};
729
Garfield Tande619fa2020-10-02 17:13:53 -0700730template <typename LayerProperties>
731struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
732 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700733
734 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000735 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700736 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000737 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700738 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000739 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000740 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
741 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
742 displaySettings.physicalDisplay);
743 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
744 displaySettings.clip);
745 // screen capture adds an additional color layer as an alpha
746 // prefill, so get the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000747 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800748 if (layerSettings.empty()) {
749 ADD_FAILURE() << "layerSettings was not expected to be empty in "
750 "setupInsecureREBufferCompositionCommonCallExpectations "
751 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700752 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800753 }
Sally Qi59a9f502021-10-12 18:53:23 +0000754 const renderengine::LayerSettings layer = layerSettings.back();
755 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
756 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700757 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
758 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000759 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
760 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700761 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000762 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700763 }
764
765 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
766 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700767 }
768
769 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
770 setupInsecureREBufferCompositionCommonCallExpectations(test);
771 }
772};
773
Garfield Tande619fa2020-10-02 17:13:53 -0700774struct ParentSecureLayerProperties
775 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
776
777struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
778 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
779};
780
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700781struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
782 using Base = BaseLayerProperties<CursorLayerProperties>;
783
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000784 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700785 Base::setupLayerState(test, layer);
786 test->mFlinger.setLayerPotentialCursor(layer, true);
787 }
788};
789
790struct NoLayerVariant {
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000791 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700792
793 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
794 static void injectLayer(CompositionTest*, FlingerLayerType) {}
795 static void cleanupInjectedLayers(CompositionTest*) {}
796
797 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
798 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
799};
800
801template <typename LayerProperties>
802struct BaseLayerVariant {
803 template <typename L, typename F>
804 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700805 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700806
807 sp<L> layer = factory();
808
Dominik Laskowski49cea512019-11-12 14:13:23 -0800809 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700810 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800811
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700812 Mock::VerifyAndClear(test->mComposer);
813 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700814 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700815
Garfield Tande619fa2020-10-02 17:13:53 -0700816 initLayerDrawingStateAndComputeBounds(test, layer);
817
818 return layer;
819 }
820
821 template <typename L>
822 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700823 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700824 layerDrawingState.layerStack = LAYER_STACK;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700825 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
826 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700827 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700828 }
829
830 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
831 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
832 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
833
Lloyd Piquede196652020-01-22 17:29:58 -0800834 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
835 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700836 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
837 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700838
839 Mock::VerifyAndClear(test->mComposer);
840
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700841 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
842 }
843
844 static void cleanupInjectedLayers(CompositionTest* test) {
845 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
846 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800847
Lloyd Pique01c77c12019-04-17 12:48:32 -0700848 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700849 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800850
851 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700852 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700853 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700854 }
855};
856
857template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800858struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700859 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800860 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700861
862 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800863 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700864 return sp<EffectLayer>::make(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700865 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800866 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700867 });
Vishnu Nair60356342018-11-13 13:00:45 -0800868
869 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800870 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700871 return layer;
872 }
873
874 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700875 LayerProperties::setupREColorCompositionCallExpectations(test);
876 }
877
878 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
879 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
880 }
881
882 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
883 LayerProperties::setupHwcSetGeometryCallExpectations(test);
884 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
885 }
886
887 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
888 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
889 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
890 }
891};
892
893template <typename LayerProperties>
894struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
895 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000896 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700897
898 static FlingerLayerType createLayer(CompositionTest* test) {
899 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
900
901 FlingerLayerType layer =
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000902 Base::template createLayerWithFactory<BufferStateLayer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700903 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700904 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700905 args.textureName = test->mFlinger.mutableTexturePool().back();
Ady Abrahamd11bade2022-08-01 16:18:03 -0700906 return sp<BufferStateLayer>::make(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700907 });
908
909 LayerProperties::setupLayerState(test, layer);
910
911 return layer;
912 }
913
914 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700915 Base::cleanupInjectedLayers(test);
916 }
917
918 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
919 LayerProperties::setupHwcSetGeometryCallExpectations(test);
920 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
921 }
922
923 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
924 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
925 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
926 }
927
928 static void setupRECompositionCallExpectations(CompositionTest* test) {
929 LayerProperties::setupREBufferCompositionCallExpectations(test);
930 }
931
932 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
933 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
934 }
935
936 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
937 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
938 }
939
940 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
941 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
942 }
943};
944
Garfield Tande619fa2020-10-02 17:13:53 -0700945template <typename LayerProperties>
946struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
947 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairb21272e2022-07-01 22:47:33 +0000948 using FlingerLayerType = sp<EffectLayer>;
Garfield Tande619fa2020-10-02 17:13:53 -0700949
950 static FlingerLayerType createLayer(CompositionTest* test) {
951 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700952 LayerProperties::LAYER_FLAGS, LayerMetadata());
Ady Abrahamd11bade2022-08-01 16:18:03 -0700953 FlingerLayerType layer = sp<EffectLayer>::make(args);
Garfield Tande619fa2020-10-02 17:13:53 -0700954 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
955 return layer;
956 }
957};
958
959template <typename LayerVariant, typename ParentLayerVariant>
960struct ChildLayerVariant : public LayerVariant {
961 using Base = LayerVariant;
962 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
963 using ParentBase = ParentLayerVariant;
964
965 static FlingerLayerType createLayer(CompositionTest* test) {
966 // Need to create child layer first. Otherwise layer history size will be 2.
967 FlingerLayerType layer = Base::createLayer(test);
968
969 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
970 parentLayer->addChild(layer);
971 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
972
973 test->mAuxiliaryLayers.push_back(parentLayer);
974
975 return layer;
976 }
977
978 static void cleanupInjectedLayers(CompositionTest* test) {
979 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
980 // following call.
981 test->mAuxiliaryLayers.clear();
982
983 Base::cleanupInjectedLayers(test);
984 }
985};
986
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700987/* ------------------------------------------------------------------------
988 * Variants to control how the composition type is changed
989 */
990
991struct NoCompositionTypeVariant {
992 static void setupHwcSetCallExpectations(CompositionTest*) {}
993
994 static void setupHwcGetCallExpectations(CompositionTest* test) {
995 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
996 }
997};
998
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500999template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001000struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001001 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1002 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001003
1004 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001005 if (!test->mDisplayOff) {
1006 EXPECT_CALL(*test->mComposer,
1007 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1008 .Times(1);
1009 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001010 }
1011
1012 static void setupHwcGetCallExpectations(CompositionTest* test) {
1013 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1014 }
1015};
1016
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001017template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
1018 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001019struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001020 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1021 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001022
1023 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001024 if (!test->mDisplayOff) {
1025 EXPECT_CALL(*test->mComposer,
1026 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1027 .Times(1);
1028 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001029 }
1030
1031 static void setupHwcGetCallExpectations(CompositionTest* test) {
1032 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1033 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1034 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001035 SetArgPointee<2>(
1036 std::vector<aidl::android::hardware::graphics::composer3::
1037 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001038 Return(Error::NONE)));
1039 }
1040};
1041
1042/* ------------------------------------------------------------------------
1043 * Variants to select how the composition is expected to be handled
1044 */
1045
1046struct CompositionResultBaseVariant {
1047 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1048
1049 template <typename Case>
1050 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1051 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1052 }
1053
1054 template <typename Case>
1055 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1056 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1057 }
1058};
1059
1060struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1061 template <typename Case>
1062 static void setupCallExpectations(CompositionTest* test) {
1063 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1064 Case::Display::setupHwcCompositionCallExpectations(test);
1065 }
1066};
1067
1068struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1069 template <typename Case>
1070 static void setupCallExpectations(CompositionTest* test) {
1071 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1072 Case::Display::setupHwcCompositionCallExpectations(test);
1073 }
1074};
1075
1076struct RECompositionResultVariant : public CompositionResultBaseVariant {
1077 template <typename Case>
1078 static void setupCallExpectations(CompositionTest* test) {
1079 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001080 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001081 Case::Display::setupRECompositionCallExpectations(test);
1082 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1083 }
1084};
1085
Lloyd Pique66d68602019-02-13 14:23:31 -08001086struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001087 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001088 const auto outputLayer =
1089 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001090 LOG_FATAL_IF(!outputLayer);
1091 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001092 }
1093
1094 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001095 static void setupCallExpectations(CompositionTest* test) {
1096 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1097 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1098 Case::Display::setupRECompositionCallExpectations(test);
1099 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1100 }
1101
1102 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001103 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1104
1105 template <typename Case>
1106 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1107};
1108
Lloyd Pique4fe29402019-08-12 16:51:24 -07001109struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1110 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1111 test->mFlinger.mutableDebugDisableHWC() = true;
1112 }
1113
1114 template <typename Case>
1115 static void setupCallExpectations(CompositionTest* test) {
1116 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1117 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1118 Case::Display::setupRECompositionCallExpectations(test);
1119 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1120 }
1121
1122 template <typename Case>
1123 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1124
1125 template <typename Case>
1126 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1127};
1128
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001129struct EmptyScreenshotResultVariant {
1130 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1131
1132 template <typename Case>
1133 static void setupCallExpectations(CompositionTest*) {}
1134};
1135
1136struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1137 using Base = EmptyScreenshotResultVariant;
1138
1139 template <typename Case>
1140 static void setupCallExpectations(CompositionTest* test) {
1141 Base::template setupCallExpectations<Case>(test);
1142 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1143 }
1144};
1145
1146/* ------------------------------------------------------------------------
1147 * Composition test case, containing all the variants being tested
1148 */
1149
1150template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1151 typename CompositionResultCase>
1152struct CompositionCase {
1153 using ThisCase =
1154 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1155 using Display = DisplayCase;
1156 using Layer = LayerCase;
1157 using CompositionType = CompositionTypeCase;
1158 using CompositionResult = CompositionResultCase;
1159
1160 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001161 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001162 Display::setupPreconditions(test);
1163
1164 auto layer = Layer::createLayer(test);
1165 Layer::injectLayer(test, layer);
1166 CompositionResult::setupLayerState(test, layer);
1167 }
1168
1169 static void setupForDirtyGeometry(CompositionTest* test) {
1170 setupCommon(test);
1171
1172 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1173 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1174 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1175 CompositionResult::template setupCallExpectations<ThisCase>(test);
1176 }
1177
1178 static void setupForDirtyFrame(CompositionTest* test) {
1179 setupCommon(test);
1180
1181 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1182 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1183 CompositionResult::template setupCallExpectations<ThisCase>(test);
1184 }
1185
1186 static void setupForScreenCapture(CompositionTest* test) {
1187 setupCommon(test);
1188
1189 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1190 CompositionResult::template setupCallExpectations<ThisCase>(test);
1191 }
1192
1193 static void cleanup(CompositionTest* test) {
1194 Layer::cleanupInjectedLayers(test);
1195
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001196 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1197 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1198 ->mutableLayers()
1199 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001200 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001201 }
1202};
1203
1204/* ------------------------------------------------------------------------
1205 * Composition cases to test
1206 */
1207
1208TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1209 displayRefreshCompositionDirtyGeometry<
1210 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1211 NoCompositionResultVariant>>();
1212}
1213
1214TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1215 displayRefreshCompositionDirtyFrame<
1216 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1217 NoCompositionResultVariant>>();
1218}
1219
1220TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1221 captureScreenComposition<
1222 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1223 EmptyScreenshotResultVariant>>();
1224}
1225
1226/* ------------------------------------------------------------------------
1227 * Simple buffer layers
1228 */
1229
1230TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001231 displayRefreshCompositionDirtyGeometry<CompositionCase<
1232 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1233 KeepCompositionTypeVariant<
1234 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1235 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001236}
1237
1238TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001239 displayRefreshCompositionDirtyFrame<CompositionCase<
1240 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1241 KeepCompositionTypeVariant<
1242 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1243 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001244}
1245
1246TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001247 displayRefreshCompositionDirtyFrame<CompositionCase<
1248 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1249 ChangeCompositionTypeVariant<
1250 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1251 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1252 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001253}
1254
1255TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1256 captureScreenComposition<
1257 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1258 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1259}
1260
1261/* ------------------------------------------------------------------------
1262 * Single-color layers
1263 */
1264
Vishnu Nairfa247b12020-02-11 08:58:26 -08001265TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001266 displayRefreshCompositionDirtyGeometry<CompositionCase<
1267 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1268 KeepCompositionTypeVariant<
1269 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1270 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001271}
1272
Vishnu Nairfa247b12020-02-11 08:58:26 -08001273TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001274 displayRefreshCompositionDirtyFrame<CompositionCase<
1275 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1276 KeepCompositionTypeVariant<
1277 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1278 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001279}
1280
Vishnu Nairfa247b12020-02-11 08:58:26 -08001281TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001282 displayRefreshCompositionDirtyFrame<CompositionCase<
1283 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1284 ChangeCompositionTypeVariant<
1285 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1286 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1287 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001288}
1289
Vishnu Nairfa247b12020-02-11 08:58:26 -08001290TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001291 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001292 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001293 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1294}
1295
1296/* ------------------------------------------------------------------------
1297 * Layers with sideband buffers
1298 */
1299
1300TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001301 displayRefreshCompositionDirtyGeometry<CompositionCase<
1302 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1303 KeepCompositionTypeVariant<
1304 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1305 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001306}
1307
1308TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001309 displayRefreshCompositionDirtyFrame<CompositionCase<
1310 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1311 KeepCompositionTypeVariant<
1312 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1313 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001314}
1315
1316TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001317 displayRefreshCompositionDirtyFrame<CompositionCase<
1318 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1319 ChangeCompositionTypeVariant<
1320 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1321 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1322 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001323}
1324
1325TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1326 captureScreenComposition<
1327 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1328 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1329}
1330
1331/* ------------------------------------------------------------------------
1332 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1333 */
1334
1335TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001336 displayRefreshCompositionDirtyGeometry<CompositionCase<
1337 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1338 KeepCompositionTypeVariant<
1339 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1340 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001341}
1342
1343TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001344 displayRefreshCompositionDirtyFrame<CompositionCase<
1345 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1346 KeepCompositionTypeVariant<
1347 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1348 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001349}
1350
1351TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001352 displayRefreshCompositionDirtyFrame<CompositionCase<
1353 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1354 ChangeCompositionTypeVariant<
1355 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1356 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1357 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001358}
1359
1360TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1361 captureScreenComposition<
1362 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1363 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1364}
1365
1366/* ------------------------------------------------------------------------
1367 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1368 */
1369
1370TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001371 displayRefreshCompositionDirtyGeometry<CompositionCase<
1372 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1373 KeepCompositionTypeVariant<
1374 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1375 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001376}
1377
1378TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001379 displayRefreshCompositionDirtyFrame<CompositionCase<
1380 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1381 KeepCompositionTypeVariant<
1382 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1383 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001384}
1385
1386TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1387 captureScreenComposition<
1388 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1389 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1390}
1391
1392/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001393 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1394 */
1395
1396TEST_F(CompositionTest,
1397 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001398 displayRefreshCompositionDirtyGeometry<CompositionCase<
1399 InsecureDisplaySetupVariant,
1400 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1401 ContainerLayerVariant<SecureLayerProperties>>,
1402 KeepCompositionTypeVariant<
1403 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1404 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001405}
1406
1407TEST_F(CompositionTest,
1408 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001409 displayRefreshCompositionDirtyFrame<CompositionCase<
1410 InsecureDisplaySetupVariant,
1411 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1412 ContainerLayerVariant<SecureLayerProperties>>,
1413 KeepCompositionTypeVariant<
1414 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1415 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001416}
1417
1418TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1419 captureScreenComposition<
1420 CompositionCase<InsecureDisplaySetupVariant,
1421 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1422 ContainerLayerVariant<SecureLayerProperties>>,
1423 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1424}
1425
1426/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001427 * Cursor layers
1428 */
1429
1430TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001431 displayRefreshCompositionDirtyGeometry<CompositionCase<
1432 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1433 KeepCompositionTypeVariant<
1434 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1435 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001436}
1437
1438TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001439 displayRefreshCompositionDirtyFrame<CompositionCase<
1440 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1441 KeepCompositionTypeVariant<
1442 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1443 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001444}
1445
1446TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001447 displayRefreshCompositionDirtyFrame<CompositionCase<
1448 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1449 ChangeCompositionTypeVariant<
1450 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1451 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1452 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001453}
1454
1455TEST_F(CompositionTest, captureScreenCursorLayer) {
1456 captureScreenComposition<
1457 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1458 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1459}
1460
1461/* ------------------------------------------------------------------------
1462 * Simple buffer layer on a display which is powered off.
1463 */
1464
1465TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001466 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001467 displayRefreshCompositionDirtyGeometry<CompositionCase<
1468 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001469 KeepCompositionTypeVariant<
1470 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001471 HwcCompositionResultVariant>>();
1472}
1473
1474TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001475 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001476 displayRefreshCompositionDirtyFrame<CompositionCase<
1477 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001478 KeepCompositionTypeVariant<
1479 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001480 HwcCompositionResultVariant>>();
1481}
1482
1483TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001484 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001485 displayRefreshCompositionDirtyFrame<CompositionCase<
1486 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001487 ChangeCompositionTypeVariant<
1488 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1489 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001490 RECompositionResultVariant>>();
1491}
1492
1493TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1494 captureScreenComposition<CompositionCase<
1495 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1496 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1497}
1498
Lloyd Pique4fe29402019-08-12 16:51:24 -07001499/* ------------------------------------------------------------------------
1500 * Client composition forced through debug/developer settings
1501 */
1502
1503TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001504 displayRefreshCompositionDirtyGeometry<CompositionCase<
1505 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1506 KeepCompositionTypeVariant<
1507 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1508 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001509}
1510
1511TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001512 displayRefreshCompositionDirtyFrame<CompositionCase<
1513 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1514 KeepCompositionTypeVariant<
1515 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1516 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001517}
1518
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001519} // namespace
1520} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001521
1522// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001523#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"