blob: bdbf243dd4a13512e51f9f03d2face709e5a5f9d [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/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070035#include <system/window.h>
36#include <utils/String8.h>
37
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020038#include "DisplayRenderArea.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070039#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070040#include "TestableSurfaceFlinger.h"
41#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique9370a482019-10-03 17:58:30 -070042#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070043#include "mock/MockEventThread.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080044#include "mock/MockTimeStats.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070045#include "mock/MockVsyncController.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070046#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070047
48namespace android {
49namespace {
50
Peiyong Line9d809e2020-04-14 13:10:48 -070051namespace hal = android::hardware::graphics::composer::hal;
52
Peiyong Lin65248e02020-04-18 21:15:07 -070053using hal::Error;
54using hal::IComposer;
55using hal::IComposerClient;
56using hal::PowerMode;
57using hal::Transform;
58
Ady Abrahamde549d42022-01-26 19:19:17 -080059using aidl::android::hardware::graphics::composer3::Capability;
60
Lloyd Piqued6b579f2018-04-06 15:29:10 -070061using testing::_;
David Sodman15094112018-10-11 09:39:37 -070062using testing::AtLeast;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070063using testing::DoAll;
64using testing::IsNull;
65using testing::Mock;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070066using testing::Return;
67using testing::ReturnRef;
68using testing::SetArgPointee;
69
Lloyd Piqued6b579f2018-04-06 15:29:10 -070070using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
71using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
72
Peiyong Line9d809e2020-04-14 13:10:48 -070073constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
74constexpr hal::HWLayerId HWC_LAYER = 5000;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070075constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
76
Dominik Laskowskif1833852021-03-23 15:06:50 -070077constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
Lloyd Piqued6b579f2018-04-06 15:29:10 -070078constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
79constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
80
Lloyd Piqued6b579f2018-04-06 15:29:10 -070081constexpr int DEFAULT_TEXTURE_ID = 6000;
Dominik Laskowski29fa1462021-04-27 15:51:50 -070082constexpr ui::LayerStack LAYER_STACK{7000u};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070083
84constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
85
86constexpr int DEFAULT_SIDEBAND_STREAM = 51;
87
Ady Abrahamdc011a92021-12-21 14:06:44 -080088MATCHER(IsIdentityMatrix, "") {
89 constexpr auto kIdentity = mat4();
90 return (mat4(arg) == kIdentity);
91}
92
Lloyd Piqued6b579f2018-04-06 15:29:10 -070093class CompositionTest : public testing::Test {
94public:
95 CompositionTest() {
96 const ::testing::TestInfo* const test_info =
97 ::testing::UnitTest::GetInstance()->current_test_info();
98 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
99
Dominik Laskowskiaee9a622023-02-11 14:24:19 -0500100 mFlinger.setupMockScheduler({.displayId = DEFAULT_DISPLAY_ID});
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700101
Alec Mourif6fd29e2018-11-17 04:56:41 +0000102 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
103 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
104 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
105 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700106
107 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800108 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800109
110 mComposer = new Hwc2::mock::Composer();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000111 mPowerAdvisor = new Hwc2::mock::PowerAdvisor();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800112 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Xiang Wang839fe5b2022-04-04 17:39:38 +0000113 mFlinger.setupPowerAdvisor(std::unique_ptr<Hwc2::PowerAdvisor>(mPowerAdvisor));
Garfield Tan9c9c1912021-07-19 12:02:16 -0700114 mFlinger.mutableMaxRenderTargetSize() = 16384;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700115 }
116
117 ~CompositionTest() {
118 const ::testing::TestInfo* const test_info =
119 ::testing::UnitTest::GetInstance()->current_test_info();
120 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
121 }
122
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700123 void setupForceGeometryDirty() {
124 // TODO: This requires the visible region and other related
125 // state to be set, and is problematic for BufferLayers since they are
126 // not visible without a buffer (and setting up a buffer looks like a
127 // pain)
128 // mFlinger.mutableVisibleRegionsDirty() = true;
129
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700130 mFlinger.mutableGeometryDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700131 }
132
133 template <typename Case>
134 void displayRefreshCompositionDirtyGeometry();
135
136 template <typename Case>
137 void displayRefreshCompositionDirtyFrame();
138
139 template <typename Case>
140 void captureScreenComposition();
141
Ady Abrahamde549d42022-01-26 19:19:17 -0800142 std::unordered_set<Capability> mDefaultCapabilities = {Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700143
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800144 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700145 TestableSurfaceFlinger mFlinger;
146 sp<DisplayDevice> mDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700147 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700148 sp<compositionengine::mock::DisplaySurface>::make();
149 sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make();
Garfield Tande619fa2020-10-02 17:13:53 -0700150 std::vector<sp<Layer>> mAuxiliaryLayers;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700151
Brian Lindahlf5ab5ae2022-12-21 14:27:15 -0700152 sp<GraphicBuffer> mBuffer =
153 sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_8888,
154 GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN);
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800155 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
156
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700157 Hwc2::mock::Composer* mComposer = nullptr;
158 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800159 mock::TimeStats* mTimeStats = new mock::TimeStats();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000160 Hwc2::mock::PowerAdvisor* mPowerAdvisor = nullptr;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700161
162 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
163
Alec Mouria90a5702021-04-16 16:36:21 +0000164 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700165};
166
167template <typename LayerCase>
168void CompositionTest::displayRefreshCompositionDirtyGeometry() {
169 setupForceGeometryDirty();
170 LayerCase::setupForDirtyGeometry(this);
171
172 // --------------------------------------------------------------------
173 // Invocation
174
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700175 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700176
177 LayerCase::cleanup(this);
178}
179
180template <typename LayerCase>
181void CompositionTest::displayRefreshCompositionDirtyFrame() {
182 LayerCase::setupForDirtyFrame(this);
183
184 // --------------------------------------------------------------------
185 // Invocation
186
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700187 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700188
189 LayerCase::cleanup(this);
190}
191
192template <typename LayerCase>
193void CompositionTest::captureScreenComposition() {
194 LayerCase::setupForScreenCapture(this);
195
196 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700197 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700198 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700199
Marin Shalamanov1c434292020-06-12 01:47:29 +0200200 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
Alec Mouri3e5965f2023-04-07 18:00:58 +0000201 ui::Dataspace::V0_SRGB, true, true);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700202
203 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700204 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
Ajinkya Chalke02844632023-03-01 12:10:14 +0000205 CaptureArgs::UNSET_UID, {}, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700206 };
207
Vishnu Nair7aa0eb72023-01-24 03:59:27 +0000208 auto getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers);
209
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700210 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
211 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800212 mCaptureScreenBuffer =
213 std::make_shared<renderengine::mock::FakeExternalTexture>(renderArea->getReqWidth(),
214 renderArea->getReqHeight(),
215 HAL_PIXEL_FORMAT_RGBA_8888, 1,
216 usage);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700217
Vishnu Nair7aa0eb72023-01-24 03:59:27 +0000218 auto future = mFlinger.renderScreenImpl(std::move(renderArea), getLayerSnapshots,
Patrick Williams7584c6a2022-10-29 02:10:58 +0000219 mCaptureScreenBuffer, forSystem, regionSampling);
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700220 ASSERT_TRUE(future.valid());
221 const auto fenceResult = future.get();
Sally Qi59a9f502021-10-12 18:53:23 +0000222
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700223 EXPECT_EQ(NO_ERROR, fenceStatus(fenceResult));
224 if (fenceResult.ok()) {
225 fenceResult.value()->waitForever(LOG_TAG);
Sally Qi59a9f502021-10-12 18:53:23 +0000226 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700227
228 LayerCase::cleanup(this);
229}
230
Sally Qi4cabdd02021-08-05 16:45:57 -0700231template <class T>
232std::future<T> futureOf(T obj) {
233 std::promise<T> resultPromise;
234 std::future<T> resultFuture = resultPromise.get_future();
235 resultPromise.set_value(std::move(obj));
236 return resultFuture;
237}
238
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700239/* ------------------------------------------------------------------------
240 * Variants for each display configuration which can be tested
241 */
242
243template <typename Derived>
244struct BaseDisplayVariant {
245 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700246 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700247
248 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700249 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700250 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700251
Peiyong Line9d809e2020-04-14 13:10:48 -0700252 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700253 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700254 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700255 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800256 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700257
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800258 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
259 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
260 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
261 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
262 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
263 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
264 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique9370a482019-10-03 17:58:30 -0700265
266 const ::testing::TestInfo* const test_info =
267 ::testing::UnitTest::GetInstance()->current_test_info();
268
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800269 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
270 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800271 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
272 .setIsSecure(Derived::IS_SECURE)
Xiang Wang839fe5b2022-04-04 17:39:38 +0000273 .setPowerAdvisor(test->mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800274 .setName(std::string("Injected display for ") +
275 test_info->test_case_name() + "." + test_info->name())
276 .build();
Lloyd Pique9370a482019-10-03 17:58:30 -0700277
278 auto compositionDisplay =
279 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
280 ceDisplayArgs);
281
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700282 constexpr auto kDisplayConnectionType = ui::DisplayConnectionType::Internal;
283 constexpr bool kIsPrimary = true;
284
Leon Scroggins IIIba9323a2023-02-22 10:40:20 -0500285 test->mDisplay =
286 FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
287 kDisplayConnectionType, HWC_DISPLAY, kIsPrimary)
288 .setDisplaySurface(test->mDisplaySurface)
289 .setNativeWindow(test->mNativeWindow)
290 .setSecure(Derived::IS_SECURE)
291 .setPowerMode(Derived::INIT_POWER_MODE)
292 .setRefreshRateSelector(test->mFlinger.scheduler()->refreshRateSelector())
293 .skipRegisterDisplay()
294 .inject();
Ady Abrahamd11bade2022-08-01 16:18:03 -0700295 Mock::VerifyAndClear(test->mNativeWindow.get());
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700296
297 constexpr bool kIsInternal = kDisplayConnectionType == ui::DisplayConnectionType::Internal;
298 test->mDisplay->setLayerFilter({LAYER_STACK, kIsInternal});
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700299 }
300
301 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700302 static void setupPreconditionCallExpectations(CompositionTest* test) {
303 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500304 .WillOnce(DoAll(SetArgPointee<1>(
305 std::vector<aidl::android::hardware::graphics::composer3::
306 DisplayCapability>({})),
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700307 Return(Error::NONE)));
308 }
309
310 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700311 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Ady Abrahamdc011a92021-12-21 14:06:44 -0800312 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700313 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
314 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
315 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
316 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
317
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700318 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
319 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
320
321 Case::CompositionType::setupHwcSetCallExpectations(test);
322 Case::CompositionType::setupHwcGetCallExpectations(test);
323 }
324
325 template <typename Case>
326 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000327 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700328 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000329 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700330 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000331 const bool, base::unique_fd&&) -> std::future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700332 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
333 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
334 displaySettings.physicalDisplay);
335 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
336 displaySettings.clip);
Patrick Williams2e9748f2022-08-09 22:48:18 +0000337 return futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Pique9370a482019-10-03 17:58:30 -0700338 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700339 }
340
341 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
342 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
343 }
344
345 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
346 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
347 }
348
349 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800350 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
351 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800352
Lloyd Pique542307f2018-10-19 13:24:08 -0700353 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700354 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700355 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700356 }
357
Lloyd Pique66d68602019-02-13 14:23:31 -0800358 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800359 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
360 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800361 }
362
363 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800364 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800365 }
366
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700367 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700368 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700369 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700370 .Times(1);
371 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
372 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
373
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800374 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
375 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
376 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
377 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000378 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700379 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000380 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700381 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000382 const bool, base::unique_fd&&) -> std::future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700383 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
384 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
385 displaySettings.physicalDisplay);
386 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
387 displaySettings.clip);
388 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Patrick Williams2e9748f2022-08-09 22:48:18 +0000389 return futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Pique9370a482019-10-03 17:58:30 -0700390 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700391 }
392
393 template <typename Case>
394 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
395 Case::Layer::setupRECompositionCallExpectations(test);
396 }
397
398 template <typename Case>
399 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
400 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700401 }
402};
403
404struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
405
406struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
407 static constexpr bool IS_SECURE = false;
408
409 template <typename Case>
410 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
411 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700412 }
413
414 template <typename Case>
415 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
416 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700417 }
418};
419
420struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700421 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700422
423 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700424 static void setupPreconditionCallExpectations(CompositionTest*) {}
425
426 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700427 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
428 // TODO: This seems like an unnecessary call if display is powered off.
Ady Abrahamdc011a92021-12-21 14:06:44 -0800429 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700430
431 // TODO: This seems like an unnecessary call if display is powered off.
432 Case::CompositionType::setupHwcSetCallExpectations(test);
433 }
434
435 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800436 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
437 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700438
439 static void setupRECompositionCallExpectations(CompositionTest* test) {
440 // TODO: This seems like an unnecessary call if display is powered off.
441 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
442 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
443 }
444
445 template <typename Case>
446 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
447};
448
449/* ------------------------------------------------------------------------
450 * Variants for each layer configuration which can be tested
451 */
452
453template <typename LayerProperties>
454struct BaseLayerProperties {
455 static constexpr uint32_t WIDTH = 100;
456 static constexpr uint32_t HEIGHT = 100;
457 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
458 static constexpr uint64_t USAGE =
459 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
460 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
461 static constexpr uint32_t SCALING_MODE = 0;
462 static constexpr uint32_t TRANSFORM = 0;
463 static constexpr uint32_t LAYER_FLAGS = 0;
464 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
465 static constexpr IComposerClient::BlendMode BLENDMODE =
466 IComposerClient::BlendMode::PREMULTIPLIED;
467
Patrick Williams83f36b22022-09-14 17:57:35 +0000468 static void setupLatchedBuffer(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700469 Mock::VerifyAndClear(test->mRenderEngine);
470
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000471 const auto buffer = std::make_shared<
472 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
473 LayerProperties::HEIGHT,
474 DEFAULT_TEXTURE_ID,
475 LayerProperties::FORMAT,
476 LayerProperties::USAGE |
477 GraphicBuffer::USAGE_HW_TEXTURE);
478
479 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
480 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
481 layerDrawingState.buffer = buffer;
482 layerDrawingState.acquireFence = Fence::NO_FENCE;
483 layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
484 layer->setSurfaceDamageRegion(
485 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700486
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700487 bool ignoredRecomputeVisibleRegions;
Vishnu Nair397a0e32022-07-26 00:01:48 +0000488 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700489 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700490 }
491
Patrick Williams83f36b22022-09-14 17:57:35 +0000492 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700493 setupLatchedBuffer(test, layer);
494 }
495
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700496 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800497 if (!test->mDisplayOff) {
498 // TODO: Coverage of other values
499 EXPECT_CALL(*test->mComposer,
500 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
501 .Times(1);
502 // TODO: Coverage of other values for origin
503 EXPECT_CALL(*test->mComposer,
504 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
505 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
506 LayerProperties::HEIGHT})))
507 .Times(1);
508 EXPECT_CALL(*test->mComposer,
509 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
510 .Times(1);
511 // TODO: Coverage of other values
512 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700513
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800514 // These expectations retire on saturation as the code path these
515 // expectations are for appears to make an extra call to them.
516 // TODO: Investigate this extra call
517 EXPECT_CALL(*test->mComposer,
518 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
519 .Times(AtLeast(1))
520 .RetiresOnSaturation();
521 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700522 }
523
524 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800525 if (!test->mDisplayOff) {
526 EXPECT_CALL(*test->mComposer,
527 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
528 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
529 LayerProperties::HEIGHT})))
530 .Times(1);
531 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700532 }
533
534 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800535 if (!test->mDisplayOff) {
536 EXPECT_CALL(*test->mComposer,
537 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
538 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
539 .Times(1);
540 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700541 }
542
543 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800544 if (!test->mDisplayOff) {
545 EXPECT_CALL(*test->mComposer,
546 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
547 std::vector<IComposerClient::Rect>(
548 {IComposerClient::Rect(
549 {0, 0, LayerProperties::WIDTH,
550 LayerProperties::HEIGHT})})))
551 .Times(1);
552 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700553 }
554
555 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800556 if (!test->mDisplayOff) {
557 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
558 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700559
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800560 // TODO: use COLOR
561 EXPECT_CALL(*test->mComposer,
562 setLayerColor(HWC_DISPLAY, HWC_LAYER,
Ady Abraham6e60b142022-01-06 18:10:35 -0800563 aidl::android::hardware::graphics::composer3::Color(
564 {1.0f, 1.0f, 1.0f, 1.0f})))
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800565 .Times(1);
566 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700567 }
568
569 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800570 if (!test->mDisplayOff) {
571 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
572 .Times(1);
573 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
574 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700575 }
576
577 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000578 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700579 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000580 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700581 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000582 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000583 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
584 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
585 displaySettings.physicalDisplay);
586 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
587 displaySettings.clip);
588 // screen capture adds an additional color layer as an alpha
589 // prefill, so gtet the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000590 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800591 if (layerSettings.empty()) {
592 ADD_FAILURE() << "layerSettings was not expected to be empty in "
593 "setupREBufferCompositionCommonCallExpectations "
594 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700595 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800596 }
Sally Qi59a9f502021-10-12 18:53:23 +0000597 const renderengine::LayerSettings layer = layerSettings.back();
598 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
599 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
Sally Qi59a9f502021-10-12 18:53:23 +0000600 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
601 EXPECT_EQ(false, layer.source.buffer.isOpaque);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700602 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
603 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Alec Mouri74c7ae12023-03-26 02:57:47 +0000604 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
Sally Qi59a9f502021-10-12 18:53:23 +0000605 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700606 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000607 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700608 }
609
610 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
611 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700612 }
613
614 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
615 setupREBufferCompositionCallExpectations(test);
616 }
617
618 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
619 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
620 }
621
622 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
623 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
624 }
625
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700626 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000627 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700628 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000629 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700630 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000631 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000632 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
633 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
634 displaySettings.physicalDisplay);
635 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
636 displaySettings.clip);
637 // screen capture adds an additional color layer as an alpha
638 // prefill, so get the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000639 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800640 if (layerSettings.empty()) {
641 ADD_FAILURE()
642 << "layerSettings was not expected to be empty in "
643 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700644 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800645 }
Sally Qi59a9f502021-10-12 18:53:23 +0000646 const renderengine::LayerSettings layer = layerSettings.back();
647 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000648 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
649 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000650 layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700651 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
652 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Alec Mouri74c7ae12023-03-26 02:57:47 +0000653 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
Sally Qi59a9f502021-10-12 18:53:23 +0000654 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700655 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000656 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700657 }
658
659 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
660 setupREColorCompositionCallExpectations(test);
661 }
662};
663
664struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
665
Vishnu Nairfa247b12020-02-11 08:58:26 -0800666struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800667 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
668};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700669
670struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
671 using Base = BaseLayerProperties<SidebandLayerProperties>;
672 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
673
Patrick Williams83f36b22022-09-14 17:57:35 +0000674 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700675 sp<NativeHandle> stream =
676 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
677 false);
678 test->mFlinger.setLayerSidebandStream(layer, stream);
Vishnu Nair802ac4f2023-05-10 13:55:22 -0700679 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
680 layerDrawingState.crop =
681 Rect(0, 0, SidebandLayerProperties::HEIGHT, SidebandLayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700682 }
683
684 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
685 EXPECT_CALL(*test->mComposer,
686 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
687 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
688 .Times(1);
689 }
690
691 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
692 EXPECT_CALL(*test->mComposer,
693 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
694 reinterpret_cast<native_handle_t*>(
695 DEFAULT_SIDEBAND_STREAM)))
696 .WillOnce(Return(Error::NONE));
697
698 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
699 }
700
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000701 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700702};
703
Garfield Tande619fa2020-10-02 17:13:53 -0700704template <typename LayerProperties>
705struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
706 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700707
708 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000709 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700710 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000711 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700712 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000713 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000714 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
715 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
716 displaySettings.physicalDisplay);
717 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
718 displaySettings.clip);
719 // screen capture adds an additional color layer as an alpha
720 // prefill, so get the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000721 std::future<FenceResult> resultFuture = futureOf<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"