blob: accd07b7fa1e0b844d155283198396a4c5127ad7 [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 Abraham62f216c2020-10-13 19:07:23 -0700132 .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0,
133 ResyncCallback())));
Dominik Laskowski98041832019-08-01 18:35:59 -0700134
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700135 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700136 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abraham62f216c2020-10-13 19:07:23 -0700137 .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0,
138 ResyncCallback())));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700139
Ady Abraham8cb21882020-08-26 18:22:05 -0700140 auto vsyncController = std::make_unique<mock::VsyncController>();
141 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700142
Ady Abraham8cb21882020-08-26 18:22:05 -0700143 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
144 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100145 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700146 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700147
Ady Abraham8cb21882020-08-26 18:22:05 -0700148 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
Dominik Laskowski83bd7712022-01-07 14:30:53 -0800149 std::move(eventThread), std::move(sfEventThread),
150 TestableSurfaceFlinger::SchedulerCallbackImpl::kNoOp,
151 TestableSurfaceFlinger::kTwoDisplayModes);
Ana Krulecafb45842019-02-13 13:33:03 -0800152 }
153
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700154 void setupForceGeometryDirty() {
155 // TODO: This requires the visible region and other related
156 // state to be set, and is problematic for BufferLayers since they are
157 // not visible without a buffer (and setting up a buffer looks like a
158 // pain)
159 // mFlinger.mutableVisibleRegionsDirty() = true;
160
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700161 mFlinger.mutableGeometryDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700162 }
163
164 template <typename Case>
165 void displayRefreshCompositionDirtyGeometry();
166
167 template <typename Case>
168 void displayRefreshCompositionDirtyFrame();
169
170 template <typename Case>
171 void captureScreenComposition();
172
Ady Abrahamde549d42022-01-26 19:19:17 -0800173 std::unordered_set<Capability> mDefaultCapabilities = {Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700174
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800175 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700176 TestableSurfaceFlinger mFlinger;
177 sp<DisplayDevice> mDisplay;
178 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700179 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
180 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700181 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Garfield Tande619fa2020-10-02 17:13:53 -0700182 std::vector<sp<Layer>> mAuxiliaryLayers;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700183
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800184 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
185 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
186
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700187 Hwc2::mock::Composer* mComposer = nullptr;
188 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800189 mock::TimeStats* mTimeStats = new mock::TimeStats();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000190 Hwc2::mock::PowerAdvisor* mPowerAdvisor = nullptr;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700191
192 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
193
Alec Mouria90a5702021-04-16 16:36:21 +0000194 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700195};
196
197template <typename LayerCase>
198void CompositionTest::displayRefreshCompositionDirtyGeometry() {
199 setupForceGeometryDirty();
200 LayerCase::setupForDirtyGeometry(this);
201
202 // --------------------------------------------------------------------
203 // Invocation
204
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700205 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700206
207 LayerCase::cleanup(this);
208}
209
210template <typename LayerCase>
211void CompositionTest::displayRefreshCompositionDirtyFrame() {
212 LayerCase::setupForDirtyFrame(this);
213
214 // --------------------------------------------------------------------
215 // Invocation
216
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700217 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700218
219 LayerCase::cleanup(this);
220}
221
222template <typename LayerCase>
223void CompositionTest::captureScreenComposition() {
224 LayerCase::setupForScreenCapture(this);
225
226 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700227 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700228 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700229
Marin Shalamanov1c434292020-06-12 01:47:29 +0200230 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
231 ui::Dataspace::V0_SRGB, ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700232
233 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700234 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
235 CaptureArgs::UNSET_UID, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700236 };
237
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700238 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
239 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800240 mCaptureScreenBuffer =
241 std::make_shared<renderengine::mock::FakeExternalTexture>(renderArea->getReqWidth(),
242 renderArea->getReqHeight(),
243 HAL_PIXEL_FORMAT_RGBA_8888, 1,
244 usage);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700245
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700246 auto future = mFlinger.renderScreenImpl(*renderArea, traverseLayers, mCaptureScreenBuffer,
Robert Carr12a3b9b2022-03-10 09:55:29 -0800247 forSystem, regionSampling);
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700248 ASSERT_TRUE(future.valid());
249 const auto fenceResult = future.get();
Sally Qi59a9f502021-10-12 18:53:23 +0000250
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700251 EXPECT_EQ(NO_ERROR, fenceStatus(fenceResult));
252 if (fenceResult.ok()) {
253 fenceResult.value()->waitForever(LOG_TAG);
Sally Qi59a9f502021-10-12 18:53:23 +0000254 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700255
256 LayerCase::cleanup(this);
257}
258
Sally Qi4cabdd02021-08-05 16:45:57 -0700259template <class T>
260std::future<T> futureOf(T obj) {
261 std::promise<T> resultPromise;
262 std::future<T> resultFuture = resultPromise.get_future();
263 resultPromise.set_value(std::move(obj));
264 return resultFuture;
265}
266
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700267/* ------------------------------------------------------------------------
268 * Variants for each display configuration which can be tested
269 */
270
271template <typename Derived>
272struct BaseDisplayVariant {
273 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700274 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700275
276 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700277 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700278 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700279
Peiyong Line9d809e2020-04-14 13:10:48 -0700280 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700281 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700282 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700283 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800284 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700285
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800286 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
287 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
288 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
289 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
290 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
291 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
292 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique9370a482019-10-03 17:58:30 -0700293
294 const ::testing::TestInfo* const test_info =
295 ::testing::UnitTest::GetInstance()->current_test_info();
296
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800297 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
298 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800299 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
300 .setIsSecure(Derived::IS_SECURE)
Xiang Wang839fe5b2022-04-04 17:39:38 +0000301 .setPowerAdvisor(test->mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800302 .setName(std::string("Injected display for ") +
303 test_info->test_case_name() + "." + test_info->name())
304 .build();
Lloyd Pique9370a482019-10-03 17:58:30 -0700305
306 auto compositionDisplay =
307 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
308 ceDisplayArgs);
309
Marin Shalamanov700e6392020-02-12 20:22:26 +0100310 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100311 ui::DisplayConnectionType::Internal, HWC_DISPLAY,
Marin Shalamanov700e6392020-02-12 20:22:26 +0100312 true /* isPrimary */)
313 .setDisplaySurface(test->mDisplaySurface)
314 .setNativeWindow(test->mNativeWindow)
315 .setSecure(Derived::IS_SECURE)
316 .setPowerMode(Derived::INIT_POWER_MODE)
317 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800318 Mock::VerifyAndClear(test->mNativeWindow);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700319 test->mDisplay->setLayerStack(LAYER_STACK);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700320 }
321
322 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700323 static void setupPreconditionCallExpectations(CompositionTest* test) {
324 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500325 .WillOnce(DoAll(SetArgPointee<1>(
326 std::vector<aidl::android::hardware::graphics::composer3::
327 DisplayCapability>({})),
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700328 Return(Error::NONE)));
329 }
330
331 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700332 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Ady Abrahamdc011a92021-12-21 14:06:44 -0800333 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700334 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
335 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
336 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
337 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
338
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700339 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
340 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
341
342 Case::CompositionType::setupHwcSetCallExpectations(test);
343 Case::CompositionType::setupHwcGetCallExpectations(test);
344 }
345
346 template <typename Case>
347 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000348 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700349 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000350 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700351 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000352 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700353 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700354 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
355 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
356 displaySettings.physicalDisplay);
357 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
358 displaySettings.clip);
Sally Qi4cabdd02021-08-05 16:45:57 -0700359 return futureOf<renderengine::RenderEngineResult>(
360 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700361 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700362 }
363
364 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
365 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
366 }
367
368 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
369 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
370 }
371
372 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800373 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
374 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800375
Lloyd Pique542307f2018-10-19 13:24:08 -0700376 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700377 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700378 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700379 }
380
Lloyd Pique66d68602019-02-13 14:23:31 -0800381 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800382 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
383 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800384 }
385
386 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800387 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800388 }
389
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700390 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700391 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700392 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700393 .Times(1);
394 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
395 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
396
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800397 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
398 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
399 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
400 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000401 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700402 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000403 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700404 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000405 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700406 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700407 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
408 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
409 displaySettings.physicalDisplay);
410 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
411 displaySettings.clip);
412 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Sally Qi4cabdd02021-08-05 16:45:57 -0700413 return futureOf<renderengine::RenderEngineResult>(
414 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700415 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700416 }
417
418 template <typename Case>
419 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
420 Case::Layer::setupRECompositionCallExpectations(test);
421 }
422
423 template <typename Case>
424 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
425 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700426 }
427};
428
429struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
430
431struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
432 static constexpr bool IS_SECURE = false;
433
434 template <typename Case>
435 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
436 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700437 }
438
439 template <typename Case>
440 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
441 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700442 }
443};
444
445struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700446 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700447
448 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700449 static void setupPreconditionCallExpectations(CompositionTest*) {}
450
451 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700452 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
453 // TODO: This seems like an unnecessary call if display is powered off.
Ady Abrahamdc011a92021-12-21 14:06:44 -0800454 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700455
456 // TODO: This seems like an unnecessary call if display is powered off.
457 Case::CompositionType::setupHwcSetCallExpectations(test);
458 }
459
460 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800461 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
462 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700463
464 static void setupRECompositionCallExpectations(CompositionTest* test) {
465 // TODO: This seems like an unnecessary call if display is powered off.
466 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
467 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
468 }
469
470 template <typename Case>
471 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
472};
473
474/* ------------------------------------------------------------------------
475 * Variants for each layer configuration which can be tested
476 */
477
478template <typename LayerProperties>
479struct BaseLayerProperties {
480 static constexpr uint32_t WIDTH = 100;
481 static constexpr uint32_t HEIGHT = 100;
482 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
483 static constexpr uint64_t USAGE =
484 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
485 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
486 static constexpr uint32_t SCALING_MODE = 0;
487 static constexpr uint32_t TRANSFORM = 0;
488 static constexpr uint32_t LAYER_FLAGS = 0;
489 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
490 static constexpr IComposerClient::BlendMode BLENDMODE =
491 IComposerClient::BlendMode::PREMULTIPLIED;
492
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000493 static void setupLatchedBuffer(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700494 Mock::VerifyAndClear(test->mRenderEngine);
495
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000496 const auto buffer = std::make_shared<
497 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
498 LayerProperties::HEIGHT,
499 DEFAULT_TEXTURE_ID,
500 LayerProperties::FORMAT,
501 LayerProperties::USAGE |
502 GraphicBuffer::USAGE_HW_TEXTURE);
503
504 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
505 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
506 layerDrawingState.buffer = buffer;
507 layerDrawingState.acquireFence = Fence::NO_FENCE;
508 layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
509 layer->setSurfaceDamageRegion(
510 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700511
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700512 bool ignoredRecomputeVisibleRegions;
Vishnu Nair397a0e32022-07-26 00:01:48 +0000513 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700514 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700515 }
516
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000517 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700518 setupLatchedBuffer(test, layer);
519 }
520
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700521 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800522 if (!test->mDisplayOff) {
523 // TODO: Coverage of other values
524 EXPECT_CALL(*test->mComposer,
525 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
526 .Times(1);
527 // TODO: Coverage of other values for origin
528 EXPECT_CALL(*test->mComposer,
529 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
530 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
531 LayerProperties::HEIGHT})))
532 .Times(1);
533 EXPECT_CALL(*test->mComposer,
534 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
535 .Times(1);
536 // TODO: Coverage of other values
537 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700538
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800539 // These expectations retire on saturation as the code path these
540 // expectations are for appears to make an extra call to them.
541 // TODO: Investigate this extra call
542 EXPECT_CALL(*test->mComposer,
543 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
544 .Times(AtLeast(1))
545 .RetiresOnSaturation();
546 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700547 }
548
549 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800550 if (!test->mDisplayOff) {
551 EXPECT_CALL(*test->mComposer,
552 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
553 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
554 LayerProperties::HEIGHT})))
555 .Times(1);
556 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700557 }
558
559 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800560 if (!test->mDisplayOff) {
561 EXPECT_CALL(*test->mComposer,
562 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
563 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
564 .Times(1);
565 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700566 }
567
568 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800569 if (!test->mDisplayOff) {
570 EXPECT_CALL(*test->mComposer,
571 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
572 std::vector<IComposerClient::Rect>(
573 {IComposerClient::Rect(
574 {0, 0, LayerProperties::WIDTH,
575 LayerProperties::HEIGHT})})))
576 .Times(1);
577 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700578 }
579
580 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800581 if (!test->mDisplayOff) {
582 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
583 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700584
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800585 // TODO: use COLOR
586 EXPECT_CALL(*test->mComposer,
587 setLayerColor(HWC_DISPLAY, HWC_LAYER,
Ady Abraham6e60b142022-01-06 18:10:35 -0800588 aidl::android::hardware::graphics::composer3::Color(
589 {1.0f, 1.0f, 1.0f, 1.0f})))
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800590 .Times(1);
591 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700592 }
593
594 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800595 if (!test->mDisplayOff) {
596 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
597 .Times(1);
598 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
599 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700600 }
601
602 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000603 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700604 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000605 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700606 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000607 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000608 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
609 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
610 displaySettings.physicalDisplay);
611 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
612 displaySettings.clip);
613 // screen capture adds an additional color layer as an alpha
614 // prefill, so gtet the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700615 std::future<renderengine::RenderEngineResult> resultFuture =
616 futureOf<renderengine::RenderEngineResult>(
617 {NO_ERROR, base::unique_fd()});
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,
Sally Qi59a9f502021-10-12 18:53:23 +0000660 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
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.
Sally Qi4cabdd02021-08-05 16:45:57 -0700668 std::future<renderengine::RenderEngineResult> resultFuture =
669 futureOf<renderengine::RenderEngineResult>(
670 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800671 if (layerSettings.empty()) {
672 ADD_FAILURE()
673 << "layerSettings was not expected to be empty in "
674 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700675 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800676 }
Sally Qi59a9f502021-10-12 18:53:23 +0000677 const renderengine::LayerSettings layer = layerSettings.back();
678 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000679 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
680 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000681 layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700682 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
683 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000684 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
685 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700686 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000687 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700688 }
689
690 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
691 setupREColorCompositionCallExpectations(test);
692 }
693};
694
695struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
696
Vishnu Nairfa247b12020-02-11 08:58:26 -0800697struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800698 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
699};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700700
701struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
702 using Base = BaseLayerProperties<SidebandLayerProperties>;
703 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
704
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000705 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700706 sp<NativeHandle> stream =
707 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
708 false);
709 test->mFlinger.setLayerSidebandStream(layer, stream);
710 }
711
712 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
713 EXPECT_CALL(*test->mComposer,
714 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
715 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
716 .Times(1);
717 }
718
719 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
720 EXPECT_CALL(*test->mComposer,
721 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
722 reinterpret_cast<native_handle_t*>(
723 DEFAULT_SIDEBAND_STREAM)))
724 .WillOnce(Return(Error::NONE));
725
726 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
727 }
728
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000729 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700730};
731
Garfield Tande619fa2020-10-02 17:13:53 -0700732template <typename LayerProperties>
733struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
734 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700735
736 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000737 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700738 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000739 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700740 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000741 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000742 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
743 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
744 displaySettings.physicalDisplay);
745 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
746 displaySettings.clip);
747 // screen capture adds an additional color layer as an alpha
748 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700749 std::future<renderengine::RenderEngineResult> resultFuture =
750 futureOf<renderengine::RenderEngineResult>(
751 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800752 if (layerSettings.empty()) {
753 ADD_FAILURE() << "layerSettings was not expected to be empty in "
754 "setupInsecureREBufferCompositionCommonCallExpectations "
755 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700756 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800757 }
Sally Qi59a9f502021-10-12 18:53:23 +0000758 const renderengine::LayerSettings layer = layerSettings.back();
759 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
760 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700761 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
762 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000763 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
764 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700765 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000766 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700767 }
768
769 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
770 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700771 }
772
773 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
774 setupInsecureREBufferCompositionCommonCallExpectations(test);
775 }
776};
777
Garfield Tande619fa2020-10-02 17:13:53 -0700778struct ParentSecureLayerProperties
779 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
780
781struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
782 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
783};
784
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700785struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
786 using Base = BaseLayerProperties<CursorLayerProperties>;
787
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000788 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700789 Base::setupLayerState(test, layer);
790 test->mFlinger.setLayerPotentialCursor(layer, true);
791 }
792};
793
794struct NoLayerVariant {
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000795 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700796
797 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
798 static void injectLayer(CompositionTest*, FlingerLayerType) {}
799 static void cleanupInjectedLayers(CompositionTest*) {}
800
801 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
802 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
803};
804
805template <typename LayerProperties>
806struct BaseLayerVariant {
807 template <typename L, typename F>
808 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700809 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700810
811 sp<L> layer = factory();
812
Dominik Laskowski49cea512019-11-12 14:13:23 -0800813 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700814 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800815
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700816 Mock::VerifyAndClear(test->mComposer);
817 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700818 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700819
Garfield Tande619fa2020-10-02 17:13:53 -0700820 initLayerDrawingStateAndComputeBounds(test, layer);
821
822 return layer;
823 }
824
825 template <typename L>
826 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700827 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700828 layerDrawingState.layerStack = LAYER_STACK;
chaviw766c9c52021-02-10 17:36:47 -0800829 layerDrawingState.width = 100;
830 layerDrawingState.height = 100;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700831 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
832 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700833 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700834 }
835
836 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
837 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
838 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
839
Lloyd Piquede196652020-01-22 17:29:58 -0800840 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
841 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700842 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
843 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700844
845 Mock::VerifyAndClear(test->mComposer);
846
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700847 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
848 }
849
850 static void cleanupInjectedLayers(CompositionTest* test) {
851 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
852 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800853
Lloyd Pique01c77c12019-04-17 12:48:32 -0700854 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700855 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800856
857 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700858 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700859 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700860 }
861};
862
863template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800864struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700865 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800866 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700867
868 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800869 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
870 return new EffectLayer(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700871 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800872 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700873 });
Vishnu Nair60356342018-11-13 13:00:45 -0800874
875 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800876 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700877 return layer;
878 }
879
880 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700881 LayerProperties::setupREColorCompositionCallExpectations(test);
882 }
883
884 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
885 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
886 }
887
888 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
889 LayerProperties::setupHwcSetGeometryCallExpectations(test);
890 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
891 }
892
893 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
894 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
895 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
896 }
897};
898
899template <typename LayerProperties>
900struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
901 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000902 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700903
904 static FlingerLayerType createLayer(CompositionTest* test) {
905 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
906
907 FlingerLayerType layer =
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000908 Base::template createLayerWithFactory<BufferStateLayer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700909 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700910 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700911 args.textureName = test->mFlinger.mutableTexturePool().back();
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000912 return new BufferStateLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700913 });
914
915 LayerProperties::setupLayerState(test, layer);
916
917 return layer;
918 }
919
920 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700921 Base::cleanupInjectedLayers(test);
922 }
923
924 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
925 LayerProperties::setupHwcSetGeometryCallExpectations(test);
926 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
927 }
928
929 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
930 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
931 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
932 }
933
934 static void setupRECompositionCallExpectations(CompositionTest* test) {
935 LayerProperties::setupREBufferCompositionCallExpectations(test);
936 }
937
938 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
939 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
940 }
941
942 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
943 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
944 }
945
946 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
947 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
948 }
949};
950
Garfield Tande619fa2020-10-02 17:13:53 -0700951template <typename LayerProperties>
952struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
953 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairb21272e2022-07-01 22:47:33 +0000954 using FlingerLayerType = sp<EffectLayer>;
Garfield Tande619fa2020-10-02 17:13:53 -0700955
956 static FlingerLayerType createLayer(CompositionTest* test) {
957 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700958 LayerProperties::LAYER_FLAGS, LayerMetadata());
Vishnu Nairb21272e2022-07-01 22:47:33 +0000959 FlingerLayerType layer = new EffectLayer(args);
Garfield Tande619fa2020-10-02 17:13:53 -0700960 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
961 return layer;
962 }
963};
964
965template <typename LayerVariant, typename ParentLayerVariant>
966struct ChildLayerVariant : public LayerVariant {
967 using Base = LayerVariant;
968 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
969 using ParentBase = ParentLayerVariant;
970
971 static FlingerLayerType createLayer(CompositionTest* test) {
972 // Need to create child layer first. Otherwise layer history size will be 2.
973 FlingerLayerType layer = Base::createLayer(test);
974
975 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
976 parentLayer->addChild(layer);
977 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
978
979 test->mAuxiliaryLayers.push_back(parentLayer);
980
981 return layer;
982 }
983
984 static void cleanupInjectedLayers(CompositionTest* test) {
985 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
986 // following call.
987 test->mAuxiliaryLayers.clear();
988
989 Base::cleanupInjectedLayers(test);
990 }
991};
992
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700993/* ------------------------------------------------------------------------
994 * Variants to control how the composition type is changed
995 */
996
997struct NoCompositionTypeVariant {
998 static void setupHwcSetCallExpectations(CompositionTest*) {}
999
1000 static void setupHwcGetCallExpectations(CompositionTest* test) {
1001 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1002 }
1003};
1004
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001005template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001006struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001007 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1008 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001009
1010 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001011 if (!test->mDisplayOff) {
1012 EXPECT_CALL(*test->mComposer,
1013 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1014 .Times(1);
1015 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001016 }
1017
1018 static void setupHwcGetCallExpectations(CompositionTest* test) {
1019 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1020 }
1021};
1022
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001023template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
1024 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001025struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001026 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1027 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001028
1029 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001030 if (!test->mDisplayOff) {
1031 EXPECT_CALL(*test->mComposer,
1032 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1033 .Times(1);
1034 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001035 }
1036
1037 static void setupHwcGetCallExpectations(CompositionTest* test) {
1038 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1039 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1040 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001041 SetArgPointee<2>(
1042 std::vector<aidl::android::hardware::graphics::composer3::
1043 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001044 Return(Error::NONE)));
1045 }
1046};
1047
1048/* ------------------------------------------------------------------------
1049 * Variants to select how the composition is expected to be handled
1050 */
1051
1052struct CompositionResultBaseVariant {
1053 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1054
1055 template <typename Case>
1056 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1057 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1058 }
1059
1060 template <typename Case>
1061 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1062 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1063 }
1064};
1065
1066struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1067 template <typename Case>
1068 static void setupCallExpectations(CompositionTest* test) {
1069 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1070 Case::Display::setupHwcCompositionCallExpectations(test);
1071 }
1072};
1073
1074struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1075 template <typename Case>
1076 static void setupCallExpectations(CompositionTest* test) {
1077 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1078 Case::Display::setupHwcCompositionCallExpectations(test);
1079 }
1080};
1081
1082struct RECompositionResultVariant : public CompositionResultBaseVariant {
1083 template <typename Case>
1084 static void setupCallExpectations(CompositionTest* test) {
1085 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001086 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001087 Case::Display::setupRECompositionCallExpectations(test);
1088 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1089 }
1090};
1091
Lloyd Pique66d68602019-02-13 14:23:31 -08001092struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001093 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001094 const auto outputLayer =
1095 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001096 LOG_FATAL_IF(!outputLayer);
1097 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001098 }
1099
1100 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001101 static void setupCallExpectations(CompositionTest* test) {
1102 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1103 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1104 Case::Display::setupRECompositionCallExpectations(test);
1105 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1106 }
1107
1108 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001109 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1110
1111 template <typename Case>
1112 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1113};
1114
Lloyd Pique4fe29402019-08-12 16:51:24 -07001115struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1116 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1117 test->mFlinger.mutableDebugDisableHWC() = true;
1118 }
1119
1120 template <typename Case>
1121 static void setupCallExpectations(CompositionTest* test) {
1122 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1123 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1124 Case::Display::setupRECompositionCallExpectations(test);
1125 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1126 }
1127
1128 template <typename Case>
1129 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1130
1131 template <typename Case>
1132 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1133};
1134
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001135struct EmptyScreenshotResultVariant {
1136 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1137
1138 template <typename Case>
1139 static void setupCallExpectations(CompositionTest*) {}
1140};
1141
1142struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1143 using Base = EmptyScreenshotResultVariant;
1144
1145 template <typename Case>
1146 static void setupCallExpectations(CompositionTest* test) {
1147 Base::template setupCallExpectations<Case>(test);
1148 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1149 }
1150};
1151
1152/* ------------------------------------------------------------------------
1153 * Composition test case, containing all the variants being tested
1154 */
1155
1156template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1157 typename CompositionResultCase>
1158struct CompositionCase {
1159 using ThisCase =
1160 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1161 using Display = DisplayCase;
1162 using Layer = LayerCase;
1163 using CompositionType = CompositionTypeCase;
1164 using CompositionResult = CompositionResultCase;
1165
1166 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001167 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001168 Display::setupPreconditions(test);
1169
1170 auto layer = Layer::createLayer(test);
1171 Layer::injectLayer(test, layer);
1172 CompositionResult::setupLayerState(test, layer);
1173 }
1174
1175 static void setupForDirtyGeometry(CompositionTest* test) {
1176 setupCommon(test);
1177
1178 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1179 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1180 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1181 CompositionResult::template setupCallExpectations<ThisCase>(test);
1182 }
1183
1184 static void setupForDirtyFrame(CompositionTest* test) {
1185 setupCommon(test);
1186
1187 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1188 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1189 CompositionResult::template setupCallExpectations<ThisCase>(test);
1190 }
1191
1192 static void setupForScreenCapture(CompositionTest* test) {
1193 setupCommon(test);
1194
1195 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1196 CompositionResult::template setupCallExpectations<ThisCase>(test);
1197 }
1198
1199 static void cleanup(CompositionTest* test) {
1200 Layer::cleanupInjectedLayers(test);
1201
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001202 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1203 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1204 ->mutableLayers()
1205 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001206 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001207 }
1208};
1209
1210/* ------------------------------------------------------------------------
1211 * Composition cases to test
1212 */
1213
1214TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1215 displayRefreshCompositionDirtyGeometry<
1216 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1217 NoCompositionResultVariant>>();
1218}
1219
1220TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1221 displayRefreshCompositionDirtyFrame<
1222 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1223 NoCompositionResultVariant>>();
1224}
1225
1226TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1227 captureScreenComposition<
1228 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1229 EmptyScreenshotResultVariant>>();
1230}
1231
1232/* ------------------------------------------------------------------------
1233 * Simple buffer layers
1234 */
1235
1236TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001237 displayRefreshCompositionDirtyGeometry<CompositionCase<
1238 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1239 KeepCompositionTypeVariant<
1240 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1241 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001242}
1243
1244TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001245 displayRefreshCompositionDirtyFrame<CompositionCase<
1246 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1247 KeepCompositionTypeVariant<
1248 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1249 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001250}
1251
1252TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001253 displayRefreshCompositionDirtyFrame<CompositionCase<
1254 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1255 ChangeCompositionTypeVariant<
1256 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1257 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1258 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001259}
1260
1261TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1262 captureScreenComposition<
1263 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1264 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1265}
1266
1267/* ------------------------------------------------------------------------
1268 * Single-color layers
1269 */
1270
Vishnu Nairfa247b12020-02-11 08:58:26 -08001271TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001272 displayRefreshCompositionDirtyGeometry<CompositionCase<
1273 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1274 KeepCompositionTypeVariant<
1275 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1276 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001277}
1278
Vishnu Nairfa247b12020-02-11 08:58:26 -08001279TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001280 displayRefreshCompositionDirtyFrame<CompositionCase<
1281 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1282 KeepCompositionTypeVariant<
1283 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1284 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001285}
1286
Vishnu Nairfa247b12020-02-11 08:58:26 -08001287TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001288 displayRefreshCompositionDirtyFrame<CompositionCase<
1289 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1290 ChangeCompositionTypeVariant<
1291 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1292 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1293 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001294}
1295
Vishnu Nairfa247b12020-02-11 08:58:26 -08001296TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001297 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001298 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001299 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1300}
1301
1302/* ------------------------------------------------------------------------
1303 * Layers with sideband buffers
1304 */
1305
1306TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001307 displayRefreshCompositionDirtyGeometry<CompositionCase<
1308 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1309 KeepCompositionTypeVariant<
1310 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1311 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001312}
1313
1314TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001315 displayRefreshCompositionDirtyFrame<CompositionCase<
1316 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1317 KeepCompositionTypeVariant<
1318 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1319 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001320}
1321
1322TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001323 displayRefreshCompositionDirtyFrame<CompositionCase<
1324 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1325 ChangeCompositionTypeVariant<
1326 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1327 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1328 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001329}
1330
1331TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1332 captureScreenComposition<
1333 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1334 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1335}
1336
1337/* ------------------------------------------------------------------------
1338 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1339 */
1340
1341TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001342 displayRefreshCompositionDirtyGeometry<CompositionCase<
1343 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1344 KeepCompositionTypeVariant<
1345 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1346 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001347}
1348
1349TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001350 displayRefreshCompositionDirtyFrame<CompositionCase<
1351 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1352 KeepCompositionTypeVariant<
1353 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1354 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001355}
1356
1357TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001358 displayRefreshCompositionDirtyFrame<CompositionCase<
1359 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1360 ChangeCompositionTypeVariant<
1361 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1362 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1363 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001364}
1365
1366TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1367 captureScreenComposition<
1368 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1369 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1370}
1371
1372/* ------------------------------------------------------------------------
1373 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1374 */
1375
1376TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001377 displayRefreshCompositionDirtyGeometry<CompositionCase<
1378 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1379 KeepCompositionTypeVariant<
1380 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1381 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001382}
1383
1384TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001385 displayRefreshCompositionDirtyFrame<CompositionCase<
1386 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1387 KeepCompositionTypeVariant<
1388 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1389 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001390}
1391
1392TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1393 captureScreenComposition<
1394 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1395 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1396}
1397
1398/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001399 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1400 */
1401
1402TEST_F(CompositionTest,
1403 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001404 displayRefreshCompositionDirtyGeometry<CompositionCase<
1405 InsecureDisplaySetupVariant,
1406 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1407 ContainerLayerVariant<SecureLayerProperties>>,
1408 KeepCompositionTypeVariant<
1409 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1410 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001411}
1412
1413TEST_F(CompositionTest,
1414 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001415 displayRefreshCompositionDirtyFrame<CompositionCase<
1416 InsecureDisplaySetupVariant,
1417 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1418 ContainerLayerVariant<SecureLayerProperties>>,
1419 KeepCompositionTypeVariant<
1420 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1421 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001422}
1423
1424TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1425 captureScreenComposition<
1426 CompositionCase<InsecureDisplaySetupVariant,
1427 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1428 ContainerLayerVariant<SecureLayerProperties>>,
1429 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1430}
1431
1432/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001433 * Cursor layers
1434 */
1435
1436TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001437 displayRefreshCompositionDirtyGeometry<CompositionCase<
1438 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1439 KeepCompositionTypeVariant<
1440 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1441 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001442}
1443
1444TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001445 displayRefreshCompositionDirtyFrame<CompositionCase<
1446 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1447 KeepCompositionTypeVariant<
1448 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1449 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001450}
1451
1452TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001453 displayRefreshCompositionDirtyFrame<CompositionCase<
1454 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1455 ChangeCompositionTypeVariant<
1456 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1457 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1458 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001459}
1460
1461TEST_F(CompositionTest, captureScreenCursorLayer) {
1462 captureScreenComposition<
1463 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1464 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1465}
1466
1467/* ------------------------------------------------------------------------
1468 * Simple buffer layer on a display which is powered off.
1469 */
1470
1471TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001472 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001473 displayRefreshCompositionDirtyGeometry<CompositionCase<
1474 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001475 KeepCompositionTypeVariant<
1476 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001477 HwcCompositionResultVariant>>();
1478}
1479
1480TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001481 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001482 displayRefreshCompositionDirtyFrame<CompositionCase<
1483 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001484 KeepCompositionTypeVariant<
1485 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001486 HwcCompositionResultVariant>>();
1487}
1488
1489TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001490 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001491 displayRefreshCompositionDirtyFrame<CompositionCase<
1492 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001493 ChangeCompositionTypeVariant<
1494 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1495 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001496 RECompositionResultVariant>>();
1497}
1498
1499TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1500 captureScreenComposition<CompositionCase<
1501 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1502 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1503}
1504
Lloyd Pique4fe29402019-08-12 16:51:24 -07001505/* ------------------------------------------------------------------------
1506 * Client composition forced through debug/developer settings
1507 */
1508
1509TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001510 displayRefreshCompositionDirtyGeometry<CompositionCase<
1511 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1512 KeepCompositionTypeVariant<
1513 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1514 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001515}
1516
1517TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001518 displayRefreshCompositionDirtyFrame<CompositionCase<
1519 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1520 KeepCompositionTypeVariant<
1521 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1522 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001523}
1524
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001525} // namespace
1526} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001527
1528// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001529#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"