blob: cdd77fec950ee8577af72e4e0fa0ffef64f6a1cb [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>
Dominik Laskowski16164eb2024-01-31 11:54:52 -050028#include <ftl/future.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070029#include <gmock/gmock.h>
30#include <gtest/gtest.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070031#include <gui/IProducerListener.h>
Evan Roskya1f1e152019-01-24 16:17:46 -080032#include <gui/LayerMetadata.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070033#include <log/log.h>
Vishnu Nairdbbe3852022-01-12 20:22:11 -080034#include <renderengine/mock/FakeExternalTexture.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070035#include <renderengine/mock/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070036#include <system/window.h>
37#include <utils/String8.h>
38
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020039#include "DisplayRenderArea.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070040#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070041#include "TestableSurfaceFlinger.h"
42#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique9370a482019-10-03 17:58:30 -070043#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070044#include "mock/MockEventThread.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080045#include "mock/MockTimeStats.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070046#include "mock/MockVsyncController.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070047#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070048
49namespace android {
50namespace {
51
Peiyong Line9d809e2020-04-14 13:10:48 -070052namespace hal = android::hardware::graphics::composer::hal;
53
Peiyong Lin65248e02020-04-18 21:15:07 -070054using hal::Error;
55using hal::IComposer;
56using hal::IComposerClient;
57using hal::PowerMode;
58using hal::Transform;
59
Ady Abrahamde549d42022-01-26 19:19:17 -080060using aidl::android::hardware::graphics::composer3::Capability;
61
Lloyd Piqued6b579f2018-04-06 15:29:10 -070062using testing::_;
David Sodman15094112018-10-11 09:39:37 -070063using testing::AtLeast;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070064using testing::DoAll;
65using testing::IsNull;
66using testing::Mock;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070067using testing::Return;
68using testing::ReturnRef;
69using testing::SetArgPointee;
70
Lloyd Piqued6b579f2018-04-06 15:29:10 -070071using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
72using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
Vishnu Nair96a5aaf2024-06-26 17:17:51 -070073using namespace ftl::flag_operators;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070074
Peiyong Line9d809e2020-04-14 13:10:48 -070075constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
76constexpr hal::HWLayerId HWC_LAYER = 5000;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070077constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
78
Dominik Laskowskif1833852021-03-23 15:06:50 -070079constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
Lloyd Piqued6b579f2018-04-06 15:29:10 -070080constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
81constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
82
Lloyd Piqued6b579f2018-04-06 15:29:10 -070083constexpr int DEFAULT_TEXTURE_ID = 6000;
Dominik Laskowski29fa1462021-04-27 15:51:50 -070084constexpr ui::LayerStack LAYER_STACK{7000u};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070085
86constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
87
88constexpr int DEFAULT_SIDEBAND_STREAM = 51;
89
Ady Abrahamdc011a92021-12-21 14:06:44 -080090MATCHER(IsIdentityMatrix, "") {
91 constexpr auto kIdentity = mat4();
92 return (mat4(arg) == kIdentity);
93}
94
Lloyd Piqued6b579f2018-04-06 15:29:10 -070095class CompositionTest : public testing::Test {
96public:
97 CompositionTest() {
98 const ::testing::TestInfo* const test_info =
99 ::testing::UnitTest::GetInstance()->current_test_info();
100 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
101
Dominik Laskowskiaee9a622023-02-11 14:24:19 -0500102 mFlinger.setupMockScheduler({.displayId = DEFAULT_DISPLAY_ID});
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700103
Alec Mourif6fd29e2018-11-17 04:56:41 +0000104 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
105 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
106 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
107 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700108
109 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800110 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800111
112 mComposer = new Hwc2::mock::Composer();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000113 mPowerAdvisor = new Hwc2::mock::PowerAdvisor();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800114 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Xiang Wang839fe5b2022-04-04 17:39:38 +0000115 mFlinger.setupPowerAdvisor(std::unique_ptr<Hwc2::PowerAdvisor>(mPowerAdvisor));
Garfield Tan9c9c1912021-07-19 12:02:16 -0700116 mFlinger.mutableMaxRenderTargetSize() = 16384;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700117 }
118
119 ~CompositionTest() {
120 const ::testing::TestInfo* const test_info =
121 ::testing::UnitTest::GetInstance()->current_test_info();
122 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
123 }
124
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700125 void setupForceGeometryDirty() {
126 // TODO: This requires the visible region and other related
127 // state to be set, and is problematic for BufferLayers since they are
128 // not visible without a buffer (and setting up a buffer looks like a
129 // pain)
130 // mFlinger.mutableVisibleRegionsDirty() = true;
131
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700132 mFlinger.mutableGeometryDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700133 }
134
135 template <typename Case>
136 void displayRefreshCompositionDirtyGeometry();
137
138 template <typename Case>
139 void displayRefreshCompositionDirtyFrame();
140
141 template <typename Case>
142 void captureScreenComposition();
143
Ady Abrahamde549d42022-01-26 19:19:17 -0800144 std::unordered_set<Capability> mDefaultCapabilities = {Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700145
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800146 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700147 TestableSurfaceFlinger mFlinger;
148 sp<DisplayDevice> mDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700149 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700150 sp<compositionengine::mock::DisplaySurface>::make();
151 sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make();
Garfield Tande619fa2020-10-02 17:13:53 -0700152 std::vector<sp<Layer>> mAuxiliaryLayers;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700153
Brian Lindahlf5ab5ae2022-12-21 14:27:15 -0700154 sp<GraphicBuffer> mBuffer =
155 sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_8888,
156 GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN);
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800157 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
158
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700159 Hwc2::mock::Composer* mComposer = nullptr;
160 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800161 mock::TimeStats* mTimeStats = new mock::TimeStats();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000162 Hwc2::mock::PowerAdvisor* mPowerAdvisor = nullptr;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700163
164 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
165
Alec Mouria90a5702021-04-16 16:36:21 +0000166 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700167};
168
169template <typename LayerCase>
170void CompositionTest::displayRefreshCompositionDirtyGeometry() {
171 setupForceGeometryDirty();
172 LayerCase::setupForDirtyGeometry(this);
173
174 // --------------------------------------------------------------------
175 // Invocation
176
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700177 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700178
179 LayerCase::cleanup(this);
180}
181
182template <typename LayerCase>
183void CompositionTest::displayRefreshCompositionDirtyFrame() {
184 LayerCase::setupForDirtyFrame(this);
185
186 // --------------------------------------------------------------------
187 // Invocation
188
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700189 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700190
191 LayerCase::cleanup(this);
192}
193
194template <typename LayerCase>
195void CompositionTest::captureScreenComposition() {
196 LayerCase::setupForScreenCapture(this);
197
198 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lucas Dupin9d763b72020-04-20 18:42:31 -0700199 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700200
Vishnu Nair96a5aaf2024-06-26 17:17:51 -0700201 auto renderArea =
202 DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
203 ui::Dataspace::V0_SRGB,
204 RenderArea::Options::CAPTURE_SECURE_LAYERS |
205 RenderArea::Options::HINT_FOR_SEAMLESS_TRANSITION);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700206
207 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700208 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
Ajinkya Chalke02844632023-03-01 12:10:14 +0000209 CaptureArgs::UNSET_UID, {}, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700210 };
211
Melody Hsueddfe932024-06-04 18:10:41 +0000212 // TODO: Use SurfaceFlinger::getLayerSnapshotsForScreenshots instead of this legacy function
213 auto getLayerSnapshotsFn = RenderArea::fromTraverseLayersLambda(traverseLayers);
Vishnu Nair7aa0eb72023-01-24 03:59:27 +0000214
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700215 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
216 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800217 mCaptureScreenBuffer =
218 std::make_shared<renderengine::mock::FakeExternalTexture>(renderArea->getReqWidth(),
219 renderArea->getReqHeight(),
220 HAL_PIXEL_FORMAT_RGBA_8888, 1,
221 usage);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700222
Melody Hsueddfe932024-06-04 18:10:41 +0000223 auto future = mFlinger.renderScreenImpl(mDisplay, std::move(renderArea), getLayerSnapshotsFn,
Chavi Weingartenf5fb5b02023-11-30 17:27:52 +0000224 mCaptureScreenBuffer, regionSampling);
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700225 ASSERT_TRUE(future.valid());
226 const auto fenceResult = future.get();
Sally Qi59a9f502021-10-12 18:53:23 +0000227
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700228 EXPECT_EQ(NO_ERROR, fenceStatus(fenceResult));
229 if (fenceResult.ok()) {
230 fenceResult.value()->waitForever(LOG_TAG);
Sally Qi59a9f502021-10-12 18:53:23 +0000231 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700232
233 LayerCase::cleanup(this);
234}
235
236/* ------------------------------------------------------------------------
237 * Variants for each display configuration which can be tested
238 */
239
240template <typename Derived>
241struct BaseDisplayVariant {
242 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700243 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700244
245 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700246 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700247 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700248
Peiyong Line9d809e2020-04-14 13:10:48 -0700249 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700250 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700251 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700252 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800253 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700254
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800255 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
256 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
257 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
258 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
259 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
260 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
261 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique9370a482019-10-03 17:58:30 -0700262
263 const ::testing::TestInfo* const test_info =
264 ::testing::UnitTest::GetInstance()->current_test_info();
265
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800266 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
267 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800268 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
269 .setIsSecure(Derived::IS_SECURE)
Xiang Wang839fe5b2022-04-04 17:39:38 +0000270 .setPowerAdvisor(test->mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800271 .setName(std::string("Injected display for ") +
272 test_info->test_case_name() + "." + test_info->name())
273 .build();
Lloyd Pique9370a482019-10-03 17:58:30 -0700274
275 auto compositionDisplay =
276 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
277 ceDisplayArgs);
278
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700279 constexpr auto kDisplayConnectionType = ui::DisplayConnectionType::Internal;
280 constexpr bool kIsPrimary = true;
281
Leon Scroggins IIIba9323a2023-02-22 10:40:20 -0500282 test->mDisplay =
283 FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
284 kDisplayConnectionType, HWC_DISPLAY, kIsPrimary)
285 .setDisplaySurface(test->mDisplaySurface)
286 .setNativeWindow(test->mNativeWindow)
287 .setSecure(Derived::IS_SECURE)
288 .setPowerMode(Derived::INIT_POWER_MODE)
289 .setRefreshRateSelector(test->mFlinger.scheduler()->refreshRateSelector())
Dominik Laskowski6e465152022-09-28 11:00:25 -0400290 .skipSchedulerRegistration()
Leon Scroggins IIIba9323a2023-02-22 10:40:20 -0500291 .inject();
Ady Abrahamd11bade2022-08-01 16:18:03 -0700292 Mock::VerifyAndClear(test->mNativeWindow.get());
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700293
294 constexpr bool kIsInternal = kDisplayConnectionType == ui::DisplayConnectionType::Internal;
295 test->mDisplay->setLayerFilter({LAYER_STACK, kIsInternal});
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700296 }
297
298 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700299 static void setupPreconditionCallExpectations(CompositionTest* test) {
300 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500301 .WillOnce(DoAll(SetArgPointee<1>(
302 std::vector<aidl::android::hardware::graphics::composer3::
303 DisplayCapability>({})),
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700304 Return(Error::NONE)));
305 }
306
307 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700308 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Ady Abrahamdc011a92021-12-21 14:06:44 -0800309 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700310 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
311 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
312 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
313 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
314
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700315 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
Alec Mourif97df4d2023-09-06 02:10:05 +0000316 EXPECT_CALL(*test->mDisplaySurface, advanceFrame(_)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700317
318 Case::CompositionType::setupHwcSetCallExpectations(test);
319 Case::CompositionType::setupHwcGetCallExpectations(test);
320 }
321
322 template <typename Case>
323 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000324 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700325 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000326 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700327 const std::shared_ptr<renderengine::ExternalTexture>&,
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500328 base::unique_fd&&) -> ftl::Future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700329 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
330 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
331 displaySettings.physicalDisplay);
332 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
333 displaySettings.clip);
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500334 return ftl::yield<FenceResult>(Fence::NO_FENCE);
Lloyd Pique9370a482019-10-03 17:58:30 -0700335 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700336 }
337
338 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
339 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
340 }
341
342 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
343 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
344 }
345
346 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
ramindani4aac32c2023-10-30 14:13:30 -0700347 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _, _))
Ady Abraham43065bd2021-12-10 17:22:15 -0800348 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800349
Lloyd Pique542307f2018-10-19 13:24:08 -0700350 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700351 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700352 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700353 }
354
Lloyd Pique66d68602019-02-13 14:23:31 -0800355 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
ramindani4aac32c2023-10-30 14:13:30 -0700356 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _, _))
Ady Abraham43065bd2021-12-10 17:22:15 -0800357 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800358 }
359
360 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
ramindani09acbb82023-11-03 09:02:38 -0700361 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800362 }
363
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700364 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700365 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700366 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700367 .Times(1);
368 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
369 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
370
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800371 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
372 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
373 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
374 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000375 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700376 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000377 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700378 const std::shared_ptr<renderengine::ExternalTexture>&,
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500379 base::unique_fd&&) -> ftl::Future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700380 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
381 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
382 displaySettings.physicalDisplay);
383 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
384 displaySettings.clip);
385 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500386 return ftl::yield<FenceResult>(Fence::NO_FENCE);
Lloyd Pique9370a482019-10-03 17:58:30 -0700387 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700388 }
389
390 template <typename Case>
391 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
392 Case::Layer::setupRECompositionCallExpectations(test);
393 }
394
395 template <typename Case>
396 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
397 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700398 }
399};
400
401struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
402
403struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
404 static constexpr bool IS_SECURE = false;
405
406 template <typename Case>
407 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
408 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700409 }
410
411 template <typename Case>
412 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
413 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700414 }
415};
416
417struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700418 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700419
420 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700421 static void setupPreconditionCallExpectations(CompositionTest*) {}
422
423 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700424 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
425 // TODO: This seems like an unnecessary call if display is powered off.
Ady Abrahamdc011a92021-12-21 14:06:44 -0800426 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700427
428 // TODO: This seems like an unnecessary call if display is powered off.
429 Case::CompositionType::setupHwcSetCallExpectations(test);
430 }
431
432 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800433 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
434 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700435
436 static void setupRECompositionCallExpectations(CompositionTest* test) {
437 // TODO: This seems like an unnecessary call if display is powered off.
438 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
439 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
440 }
441
442 template <typename Case>
443 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
444};
445
446/* ------------------------------------------------------------------------
447 * Variants for each layer configuration which can be tested
448 */
449
450template <typename LayerProperties>
451struct BaseLayerProperties {
452 static constexpr uint32_t WIDTH = 100;
453 static constexpr uint32_t HEIGHT = 100;
454 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
455 static constexpr uint64_t USAGE =
456 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
457 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
458 static constexpr uint32_t SCALING_MODE = 0;
459 static constexpr uint32_t TRANSFORM = 0;
460 static constexpr uint32_t LAYER_FLAGS = 0;
461 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
462 static constexpr IComposerClient::BlendMode BLENDMODE =
463 IComposerClient::BlendMode::PREMULTIPLIED;
464
Patrick Williams83f36b22022-09-14 17:57:35 +0000465 static void setupLatchedBuffer(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700466 Mock::VerifyAndClear(test->mRenderEngine);
467
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000468 const auto buffer = std::make_shared<
469 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
470 LayerProperties::HEIGHT,
471 DEFAULT_TEXTURE_ID,
472 LayerProperties::FORMAT,
473 LayerProperties::USAGE |
474 GraphicBuffer::USAGE_HW_TEXTURE);
475
476 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
477 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
478 layerDrawingState.buffer = buffer;
479 layerDrawingState.acquireFence = Fence::NO_FENCE;
480 layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
481 layer->setSurfaceDamageRegion(
482 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700483
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700484 bool ignoredRecomputeVisibleRegions;
Vishnu Nair397a0e32022-07-26 00:01:48 +0000485 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700486 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700487 }
488
Patrick Williams83f36b22022-09-14 17:57:35 +0000489 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700490 setupLatchedBuffer(test, layer);
491 }
492
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700493 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800494 if (!test->mDisplayOff) {
495 // TODO: Coverage of other values
496 EXPECT_CALL(*test->mComposer,
497 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
498 .Times(1);
499 // TODO: Coverage of other values for origin
500 EXPECT_CALL(*test->mComposer,
501 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
502 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
503 LayerProperties::HEIGHT})))
504 .Times(1);
505 EXPECT_CALL(*test->mComposer,
506 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
507 .Times(1);
508 // TODO: Coverage of other values
509 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700510
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800511 // These expectations retire on saturation as the code path these
512 // expectations are for appears to make an extra call to them.
513 // TODO: Investigate this extra call
514 EXPECT_CALL(*test->mComposer,
515 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
516 .Times(AtLeast(1))
517 .RetiresOnSaturation();
518 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700519 }
520
521 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800522 if (!test->mDisplayOff) {
523 EXPECT_CALL(*test->mComposer,
524 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
525 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
526 LayerProperties::HEIGHT})))
527 .Times(1);
528 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700529 }
530
531 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800532 if (!test->mDisplayOff) {
533 EXPECT_CALL(*test->mComposer,
534 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
535 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
536 .Times(1);
537 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700538 }
539
540 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800541 if (!test->mDisplayOff) {
542 EXPECT_CALL(*test->mComposer,
543 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
544 std::vector<IComposerClient::Rect>(
545 {IComposerClient::Rect(
546 {0, 0, LayerProperties::WIDTH,
547 LayerProperties::HEIGHT})})))
548 .Times(1);
549 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700550 }
551
552 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800553 if (!test->mDisplayOff) {
554 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
555 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700556
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800557 // TODO: use COLOR
558 EXPECT_CALL(*test->mComposer,
559 setLayerColor(HWC_DISPLAY, HWC_LAYER,
Ady Abraham6e60b142022-01-06 18:10:35 -0800560 aidl::android::hardware::graphics::composer3::Color(
561 {1.0f, 1.0f, 1.0f, 1.0f})))
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800562 .Times(1);
563 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700564 }
565
566 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800567 if (!test->mDisplayOff) {
568 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
569 .Times(1);
570 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
571 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700572 }
573
574 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000575 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700576 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000577 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourif29700f2023-08-17 21:53:31 +0000578 const std::shared_ptr<renderengine::ExternalTexture>&,
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500579 base::unique_fd&&) -> ftl::Future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000580 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
581 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
582 displaySettings.physicalDisplay);
583 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
584 displaySettings.clip);
585 // screen capture adds an additional color layer as an alpha
586 // prefill, so gtet the back layer.
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500587 ftl::Future<FenceResult> resultFuture =
588 ftl::yield<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800589 if (layerSettings.empty()) {
590 ADD_FAILURE() << "layerSettings was not expected to be empty in "
591 "setupREBufferCompositionCommonCallExpectations "
592 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700593 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800594 }
Sally Qi59a9f502021-10-12 18:53:23 +0000595 const renderengine::LayerSettings layer = layerSettings.back();
596 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
597 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
Sally Qi59a9f502021-10-12 18:53:23 +0000598 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
599 EXPECT_EQ(false, layer.source.buffer.isOpaque);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700600 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
601 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Alec Mouri74c7ae12023-03-26 02:57:47 +0000602 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
Sally Qi59a9f502021-10-12 18:53:23 +0000603 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700604 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000605 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700606 }
607
608 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
609 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700610 }
611
612 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
613 setupREBufferCompositionCallExpectations(test);
614 }
615
616 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
617 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
618 }
619
620 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
621 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
622 }
623
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700624 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000625 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700626 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000627 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourif29700f2023-08-17 21:53:31 +0000628 const std::shared_ptr<renderengine::ExternalTexture>&,
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500629 base::unique_fd&&) -> ftl::Future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000630 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
631 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
632 displaySettings.physicalDisplay);
633 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
634 displaySettings.clip);
635 // screen capture adds an additional color layer as an alpha
636 // prefill, so get the back layer.
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500637 ftl::Future<FenceResult> resultFuture =
638 ftl::yield<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800639 if (layerSettings.empty()) {
640 ADD_FAILURE()
641 << "layerSettings was not expected to be empty in "
642 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700643 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800644 }
Sally Qi59a9f502021-10-12 18:53:23 +0000645 const renderengine::LayerSettings layer = layerSettings.back();
646 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000647 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
648 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000649 layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700650 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
651 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Alec Mouri74c7ae12023-03-26 02:57:47 +0000652 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
Sally Qi59a9f502021-10-12 18:53:23 +0000653 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700654 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000655 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700656 }
657
658 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
659 setupREColorCompositionCallExpectations(test);
660 }
661};
662
663struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
664
Vishnu Nairfa247b12020-02-11 08:58:26 -0800665struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800666 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
667};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700668
669struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
670 using Base = BaseLayerProperties<SidebandLayerProperties>;
671 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
672
Patrick Williams83f36b22022-09-14 17:57:35 +0000673 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700674 sp<NativeHandle> stream =
675 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
676 false);
677 test->mFlinger.setLayerSidebandStream(layer, stream);
Vishnu Nair802ac4f2023-05-10 13:55:22 -0700678 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
679 layerDrawingState.crop =
680 Rect(0, 0, SidebandLayerProperties::HEIGHT, SidebandLayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700681 }
682
683 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
684 EXPECT_CALL(*test->mComposer,
685 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
686 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
687 .Times(1);
688 }
689
690 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
691 EXPECT_CALL(*test->mComposer,
692 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
693 reinterpret_cast<native_handle_t*>(
694 DEFAULT_SIDEBAND_STREAM)))
695 .WillOnce(Return(Error::NONE));
696
697 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
698 }
699
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000700 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700701};
702
Garfield Tande619fa2020-10-02 17:13:53 -0700703template <typename LayerProperties>
704struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
705 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700706
707 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000708 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700709 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000710 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourif29700f2023-08-17 21:53:31 +0000711 const std::shared_ptr<renderengine::ExternalTexture>&,
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500712 base::unique_fd&&) -> ftl::Future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000713 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
714 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
715 displaySettings.physicalDisplay);
716 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
717 displaySettings.clip);
718 // screen capture adds an additional color layer as an alpha
719 // prefill, so get the back layer.
Dominik Laskowski16164eb2024-01-31 11:54:52 -0500720 ftl::Future<FenceResult> resultFuture =
721 ftl::yield<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800722 if (layerSettings.empty()) {
723 ADD_FAILURE() << "layerSettings was not expected to be empty in "
724 "setupInsecureREBufferCompositionCommonCallExpectations "
725 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700726 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800727 }
Sally Qi59a9f502021-10-12 18:53:23 +0000728 const renderengine::LayerSettings layer = layerSettings.back();
729 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
730 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700731 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
732 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Alec Mouri74c7ae12023-03-26 02:57:47 +0000733 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
Sally Qi59a9f502021-10-12 18:53:23 +0000734 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700735 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000736 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700737 }
738
739 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
740 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700741 }
742
743 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
744 setupInsecureREBufferCompositionCommonCallExpectations(test);
745 }
746};
747
Garfield Tande619fa2020-10-02 17:13:53 -0700748struct ParentSecureLayerProperties
749 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
750
751struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
752 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
753};
754
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700755struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
756 using Base = BaseLayerProperties<CursorLayerProperties>;
757
Patrick Williams83f36b22022-09-14 17:57:35 +0000758 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700759 Base::setupLayerState(test, layer);
760 test->mFlinger.setLayerPotentialCursor(layer, true);
761 }
762};
763
764struct NoLayerVariant {
Patrick Williams83f36b22022-09-14 17:57:35 +0000765 using FlingerLayerType = sp<Layer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700766
767 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
768 static void injectLayer(CompositionTest*, FlingerLayerType) {}
769 static void cleanupInjectedLayers(CompositionTest*) {}
770
771 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
772 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
773};
774
775template <typename LayerProperties>
776struct BaseLayerVariant {
777 template <typename L, typename F>
778 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700779 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700780
781 sp<L> layer = factory();
782
Dominik Laskowski49cea512019-11-12 14:13:23 -0800783 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700784 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800785
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700786 Mock::VerifyAndClear(test->mComposer);
787 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700788 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700789
Garfield Tande619fa2020-10-02 17:13:53 -0700790 initLayerDrawingStateAndComputeBounds(test, layer);
791
792 return layer;
793 }
794
795 template <typename L>
796 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700797 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700798 layerDrawingState.layerStack = LAYER_STACK;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700799 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
800 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700801 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700802 }
803
804 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
805 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
806 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
807
Lloyd Piquede196652020-01-22 17:29:58 -0800808 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
809 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700810 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
811 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700812
813 Mock::VerifyAndClear(test->mComposer);
814
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700815 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
Vishnu Nair802ac4f2023-05-10 13:55:22 -0700816 test->mFlinger.mutableVisibleRegionsDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700817 }
818
819 static void cleanupInjectedLayers(CompositionTest* test) {
820 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
821 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800822
Lloyd Pique01c77c12019-04-17 12:48:32 -0700823 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700824 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Vishnu Nair802ac4f2023-05-10 13:55:22 -0700825 test->mFlinger.mutablePreviouslyComposedLayers().clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800826
827 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700828 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700829 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700830 }
831};
832
833template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800834struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700835 using Base = BaseLayerVariant<LayerProperties>;
Patrick Williams46b61b92022-09-01 17:25:49 +0000836 using FlingerLayerType = sp<Layer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700837
838 static FlingerLayerType createLayer(CompositionTest* test) {
Patrick Williams46b61b92022-09-01 17:25:49 +0000839 FlingerLayerType layer = Base::template createLayerWithFactory<Layer>(test, [test]() {
840 return sp<Layer>::make(LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(),
841 "test-layer", LayerProperties::LAYER_FLAGS,
842 LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700843 });
Vishnu Nair60356342018-11-13 13:00:45 -0800844
845 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800846 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700847 return layer;
848 }
849
850 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700851 LayerProperties::setupREColorCompositionCallExpectations(test);
852 }
853
854 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
855 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
856 }
857
858 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
859 LayerProperties::setupHwcSetGeometryCallExpectations(test);
860 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
861 }
862
863 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
864 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
865 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
866 }
867};
868
869template <typename LayerProperties>
870struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
871 using Base = BaseLayerVariant<LayerProperties>;
Patrick Williams83f36b22022-09-14 17:57:35 +0000872 using FlingerLayerType = sp<Layer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700873
874 static FlingerLayerType createLayer(CompositionTest* test) {
Alec Mouric3a17822023-08-16 14:56:30 +0000875 FlingerLayerType layer = Base::template createLayerWithFactory<Layer>(test, [test]() {
876 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
877 LayerProperties::LAYER_FLAGS, LayerMetadata());
878 return sp<Layer>::make(args);
879 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700880
881 LayerProperties::setupLayerState(test, layer);
882
883 return layer;
884 }
885
886 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700887 Base::cleanupInjectedLayers(test);
888 }
889
890 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
891 LayerProperties::setupHwcSetGeometryCallExpectations(test);
892 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
893 }
894
895 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
896 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
897 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
898 }
899
900 static void setupRECompositionCallExpectations(CompositionTest* test) {
901 LayerProperties::setupREBufferCompositionCallExpectations(test);
902 }
903
904 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
905 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
906 }
907
908 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
909 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
910 }
911
912 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
913 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
914 }
915};
916
Garfield Tande619fa2020-10-02 17:13:53 -0700917template <typename LayerProperties>
918struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
919 using Base = BaseLayerVariant<LayerProperties>;
Patrick Williams46b61b92022-09-01 17:25:49 +0000920 using FlingerLayerType = sp<Layer>;
Garfield Tande619fa2020-10-02 17:13:53 -0700921
922 static FlingerLayerType createLayer(CompositionTest* test) {
923 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700924 LayerProperties::LAYER_FLAGS, LayerMetadata());
Patrick Williams46b61b92022-09-01 17:25:49 +0000925 FlingerLayerType layer = sp<Layer>::make(args);
Garfield Tande619fa2020-10-02 17:13:53 -0700926 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
927 return layer;
928 }
929};
930
931template <typename LayerVariant, typename ParentLayerVariant>
932struct ChildLayerVariant : public LayerVariant {
933 using Base = LayerVariant;
934 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
935 using ParentBase = ParentLayerVariant;
936
937 static FlingerLayerType createLayer(CompositionTest* test) {
938 // Need to create child layer first. Otherwise layer history size will be 2.
939 FlingerLayerType layer = Base::createLayer(test);
940
941 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
942 parentLayer->addChild(layer);
943 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
944
945 test->mAuxiliaryLayers.push_back(parentLayer);
946
947 return layer;
948 }
949
950 static void cleanupInjectedLayers(CompositionTest* test) {
951 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
952 // following call.
953 test->mAuxiliaryLayers.clear();
954
955 Base::cleanupInjectedLayers(test);
956 }
957};
958
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700959/* ------------------------------------------------------------------------
960 * Variants to control how the composition type is changed
961 */
962
963struct NoCompositionTypeVariant {
964 static void setupHwcSetCallExpectations(CompositionTest*) {}
965
966 static void setupHwcGetCallExpectations(CompositionTest* test) {
967 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
968 }
969};
970
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500971template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700972struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500973 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
974 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700975
976 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800977 if (!test->mDisplayOff) {
978 EXPECT_CALL(*test->mComposer,
979 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
980 .Times(1);
981 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700982 }
983
984 static void setupHwcGetCallExpectations(CompositionTest* test) {
985 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
986 }
987};
988
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500989template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
990 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700991struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500992 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
993 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700994
995 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800996 if (!test->mDisplayOff) {
997 EXPECT_CALL(*test->mComposer,
998 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
999 .Times(1);
1000 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001001 }
1002
1003 static void setupHwcGetCallExpectations(CompositionTest* test) {
1004 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1005 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1006 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001007 SetArgPointee<2>(
1008 std::vector<aidl::android::hardware::graphics::composer3::
1009 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001010 Return(Error::NONE)));
1011 }
1012};
1013
1014/* ------------------------------------------------------------------------
1015 * Variants to select how the composition is expected to be handled
1016 */
1017
1018struct CompositionResultBaseVariant {
1019 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1020
1021 template <typename Case>
1022 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1023 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1024 }
1025
1026 template <typename Case>
1027 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1028 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1029 }
1030};
1031
1032struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1033 template <typename Case>
1034 static void setupCallExpectations(CompositionTest* test) {
1035 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1036 Case::Display::setupHwcCompositionCallExpectations(test);
1037 }
1038};
1039
1040struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1041 template <typename Case>
1042 static void setupCallExpectations(CompositionTest* test) {
1043 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1044 Case::Display::setupHwcCompositionCallExpectations(test);
1045 }
1046};
1047
1048struct RECompositionResultVariant : public CompositionResultBaseVariant {
1049 template <typename Case>
1050 static void setupCallExpectations(CompositionTest* test) {
1051 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001052 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001053 Case::Display::setupRECompositionCallExpectations(test);
1054 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1055 }
1056};
1057
Lloyd Pique66d68602019-02-13 14:23:31 -08001058struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001059 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001060 const auto outputLayer =
1061 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001062 LOG_FATAL_IF(!outputLayer);
1063 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001064 }
1065
1066 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001067 static void setupCallExpectations(CompositionTest* test) {
1068 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1069 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1070 Case::Display::setupRECompositionCallExpectations(test);
1071 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1072 }
1073
1074 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001075 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1076
1077 template <typename Case>
1078 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1079};
1080
Lloyd Pique4fe29402019-08-12 16:51:24 -07001081struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1082 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1083 test->mFlinger.mutableDebugDisableHWC() = true;
1084 }
1085
1086 template <typename Case>
1087 static void setupCallExpectations(CompositionTest* test) {
1088 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1089 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1090 Case::Display::setupRECompositionCallExpectations(test);
1091 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1092 }
1093
1094 template <typename Case>
1095 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1096
1097 template <typename Case>
1098 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1099};
1100
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001101struct EmptyScreenshotResultVariant {
1102 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1103
1104 template <typename Case>
1105 static void setupCallExpectations(CompositionTest*) {}
1106};
1107
1108struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1109 using Base = EmptyScreenshotResultVariant;
1110
1111 template <typename Case>
1112 static void setupCallExpectations(CompositionTest* test) {
1113 Base::template setupCallExpectations<Case>(test);
1114 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1115 }
1116};
1117
1118/* ------------------------------------------------------------------------
1119 * Composition test case, containing all the variants being tested
1120 */
1121
1122template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1123 typename CompositionResultCase>
1124struct CompositionCase {
1125 using ThisCase =
1126 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1127 using Display = DisplayCase;
1128 using Layer = LayerCase;
1129 using CompositionType = CompositionTypeCase;
1130 using CompositionResult = CompositionResultCase;
1131
1132 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001133 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001134 Display::setupPreconditions(test);
1135
1136 auto layer = Layer::createLayer(test);
1137 Layer::injectLayer(test, layer);
1138 CompositionResult::setupLayerState(test, layer);
1139 }
1140
1141 static void setupForDirtyGeometry(CompositionTest* test) {
1142 setupCommon(test);
1143
1144 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1145 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1146 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1147 CompositionResult::template setupCallExpectations<ThisCase>(test);
1148 }
1149
1150 static void setupForDirtyFrame(CompositionTest* test) {
1151 setupCommon(test);
1152
1153 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1154 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1155 CompositionResult::template setupCallExpectations<ThisCase>(test);
1156 }
1157
1158 static void setupForScreenCapture(CompositionTest* test) {
1159 setupCommon(test);
1160
1161 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1162 CompositionResult::template setupCallExpectations<ThisCase>(test);
1163 }
1164
1165 static void cleanup(CompositionTest* test) {
1166 Layer::cleanupInjectedLayers(test);
1167
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001168 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1169 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1170 ->mutableLayers()
1171 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001172 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001173 }
1174};
1175
1176/* ------------------------------------------------------------------------
1177 * Composition cases to test
1178 */
1179
1180TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1181 displayRefreshCompositionDirtyGeometry<
1182 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1183 NoCompositionResultVariant>>();
1184}
1185
1186TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1187 displayRefreshCompositionDirtyFrame<
1188 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1189 NoCompositionResultVariant>>();
1190}
1191
1192TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1193 captureScreenComposition<
1194 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1195 EmptyScreenshotResultVariant>>();
1196}
1197
1198/* ------------------------------------------------------------------------
1199 * Simple buffer layers
1200 */
1201
1202TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001203 displayRefreshCompositionDirtyGeometry<CompositionCase<
1204 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1205 KeepCompositionTypeVariant<
1206 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1207 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001208}
1209
1210TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001211 displayRefreshCompositionDirtyFrame<CompositionCase<
1212 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1213 KeepCompositionTypeVariant<
1214 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1215 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001216}
1217
1218TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001219 displayRefreshCompositionDirtyFrame<CompositionCase<
1220 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1221 ChangeCompositionTypeVariant<
1222 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1223 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1224 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001225}
1226
1227TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1228 captureScreenComposition<
1229 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1230 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1231}
1232
1233/* ------------------------------------------------------------------------
1234 * Single-color layers
1235 */
1236
Vishnu Nairfa247b12020-02-11 08:58:26 -08001237TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001238 displayRefreshCompositionDirtyGeometry<CompositionCase<
1239 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1240 KeepCompositionTypeVariant<
1241 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1242 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001243}
1244
Vishnu Nairfa247b12020-02-11 08:58:26 -08001245TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001246 displayRefreshCompositionDirtyFrame<CompositionCase<
1247 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1248 KeepCompositionTypeVariant<
1249 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1250 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001251}
1252
Vishnu Nairfa247b12020-02-11 08:58:26 -08001253TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001254 displayRefreshCompositionDirtyFrame<CompositionCase<
1255 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1256 ChangeCompositionTypeVariant<
1257 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1258 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1259 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001260}
1261
Vishnu Nairfa247b12020-02-11 08:58:26 -08001262TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001263 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001264 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001265 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1266}
1267
1268/* ------------------------------------------------------------------------
1269 * Layers with sideband buffers
1270 */
1271
1272TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001273 displayRefreshCompositionDirtyGeometry<CompositionCase<
1274 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1275 KeepCompositionTypeVariant<
1276 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1277 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001278}
1279
1280TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001281 displayRefreshCompositionDirtyFrame<CompositionCase<
1282 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1283 KeepCompositionTypeVariant<
1284 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1285 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001286}
1287
1288TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001289 displayRefreshCompositionDirtyFrame<CompositionCase<
1290 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1291 ChangeCompositionTypeVariant<
1292 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1293 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1294 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001295}
1296
1297TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1298 captureScreenComposition<
1299 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1300 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1301}
1302
1303/* ------------------------------------------------------------------------
1304 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1305 */
1306
1307TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001308 displayRefreshCompositionDirtyGeometry<CompositionCase<
1309 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1310 KeepCompositionTypeVariant<
1311 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1312 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001313}
1314
1315TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001316 displayRefreshCompositionDirtyFrame<CompositionCase<
1317 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1318 KeepCompositionTypeVariant<
1319 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1320 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001321}
1322
1323TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001324 displayRefreshCompositionDirtyFrame<CompositionCase<
1325 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1326 ChangeCompositionTypeVariant<
1327 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1328 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1329 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001330}
1331
1332TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1333 captureScreenComposition<
1334 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1335 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1336}
1337
1338/* ------------------------------------------------------------------------
1339 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1340 */
1341
1342TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001343 displayRefreshCompositionDirtyGeometry<CompositionCase<
1344 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1345 KeepCompositionTypeVariant<
1346 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1347 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001348}
1349
1350TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001351 displayRefreshCompositionDirtyFrame<CompositionCase<
1352 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1353 KeepCompositionTypeVariant<
1354 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1355 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001356}
1357
1358TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1359 captureScreenComposition<
1360 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1361 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1362}
1363
1364/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001365 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1366 */
1367
1368TEST_F(CompositionTest,
1369 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001370 displayRefreshCompositionDirtyGeometry<CompositionCase<
1371 InsecureDisplaySetupVariant,
1372 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1373 ContainerLayerVariant<SecureLayerProperties>>,
1374 KeepCompositionTypeVariant<
1375 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1376 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001377}
1378
1379TEST_F(CompositionTest,
1380 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001381 displayRefreshCompositionDirtyFrame<CompositionCase<
1382 InsecureDisplaySetupVariant,
1383 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1384 ContainerLayerVariant<SecureLayerProperties>>,
1385 KeepCompositionTypeVariant<
1386 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1387 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001388}
1389
1390TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1391 captureScreenComposition<
1392 CompositionCase<InsecureDisplaySetupVariant,
1393 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1394 ContainerLayerVariant<SecureLayerProperties>>,
1395 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1396}
1397
1398/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001399 * Cursor layers
1400 */
1401
1402TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001403 displayRefreshCompositionDirtyGeometry<CompositionCase<
1404 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1405 KeepCompositionTypeVariant<
1406 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1407 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001408}
1409
1410TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001411 displayRefreshCompositionDirtyFrame<CompositionCase<
1412 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1413 KeepCompositionTypeVariant<
1414 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1415 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001416}
1417
1418TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001419 displayRefreshCompositionDirtyFrame<CompositionCase<
1420 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1421 ChangeCompositionTypeVariant<
1422 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1423 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1424 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001425}
1426
1427TEST_F(CompositionTest, captureScreenCursorLayer) {
1428 captureScreenComposition<
1429 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1430 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1431}
1432
1433/* ------------------------------------------------------------------------
1434 * Simple buffer layer on a display which is powered off.
1435 */
1436
1437TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001438 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001439 displayRefreshCompositionDirtyGeometry<CompositionCase<
1440 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001441 KeepCompositionTypeVariant<
1442 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001443 HwcCompositionResultVariant>>();
1444}
1445
1446TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001447 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001448 displayRefreshCompositionDirtyFrame<CompositionCase<
1449 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001450 KeepCompositionTypeVariant<
1451 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001452 HwcCompositionResultVariant>>();
1453}
1454
1455TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001456 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001457 displayRefreshCompositionDirtyFrame<CompositionCase<
1458 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001459 ChangeCompositionTypeVariant<
1460 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1461 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001462 RECompositionResultVariant>>();
1463}
1464
1465TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1466 captureScreenComposition<CompositionCase<
1467 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1468 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1469}
1470
Lloyd Pique4fe29402019-08-12 16:51:24 -07001471/* ------------------------------------------------------------------------
1472 * Client composition forced through debug/developer settings
1473 */
1474
1475TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001476 displayRefreshCompositionDirtyGeometry<CompositionCase<
1477 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1478 KeepCompositionTypeVariant<
1479 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1480 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001481}
1482
1483TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001484 displayRefreshCompositionDirtyFrame<CompositionCase<
1485 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1486 KeepCompositionTypeVariant<
1487 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1488 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001489}
1490
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001491} // namespace
1492} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001493
1494// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001495#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"