blob: 6ca21bd4585c3eb69ca6133c81e710f1358f7b7b [file] [log] [blame]
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
Alec Mouria90a5702021-04-16 16:36:21 +000018#include "renderengine/ExternalTexture.h"
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080019#pragma clang diagnostic push
20#pragma clang diagnostic ignored "-Wconversion"
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010021#pragma clang diagnostic ignored "-Wextra"
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080022
Lloyd Piqued6b579f2018-04-06 15:29:10 -070023#undef LOG_TAG
24#define LOG_TAG "CompositionTest"
25
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080026#include <compositionengine/Display.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070027#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070028#include <gmock/gmock.h>
29#include <gtest/gtest.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070030#include <gui/IProducerListener.h>
Evan Roskya1f1e152019-01-24 16:17:46 -080031#include <gui/LayerMetadata.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070032#include <log/log.h>
Vishnu Nairdbbe3852022-01-12 20:22:11 -080033#include <renderengine/mock/FakeExternalTexture.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070034#include <renderengine/mock/Framebuffer.h>
35#include <renderengine/mock/Image.h>
36#include <renderengine/mock/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070037#include <system/window.h>
38#include <utils/String8.h>
39
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020040#include "DisplayRenderArea.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070041#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070042#include "TestableSurfaceFlinger.h"
43#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique9370a482019-10-03 17:58:30 -070044#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070045#include "mock/MockEventThread.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080046#include "mock/MockTimeStats.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070047#include "mock/MockVsyncController.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070048#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070049
50namespace android {
51namespace {
52
Peiyong Line9d809e2020-04-14 13:10:48 -070053namespace hal = android::hardware::graphics::composer::hal;
54
Peiyong Lin65248e02020-04-18 21:15:07 -070055using hal::Error;
56using hal::IComposer;
57using hal::IComposerClient;
58using hal::PowerMode;
59using hal::Transform;
60
Ady Abrahamde549d42022-01-26 19:19:17 -080061using aidl::android::hardware::graphics::composer3::Capability;
62
Lloyd Piqued6b579f2018-04-06 15:29:10 -070063using testing::_;
David Sodman15094112018-10-11 09:39:37 -070064using testing::AtLeast;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070065using testing::DoAll;
66using testing::IsNull;
67using testing::Mock;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070068using testing::Return;
69using testing::ReturnRef;
70using testing::SetArgPointee;
71
Lloyd Piqued6b579f2018-04-06 15:29:10 -070072using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
73using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
74
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);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700199 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700200 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700201
Marin Shalamanov1c434292020-06-12 01:47:29 +0200202 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
Alec Mouri3e5965f2023-04-07 18:00:58 +0000203 ui::Dataspace::V0_SRGB, true, true);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700204
205 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700206 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
Ajinkya Chalke02844632023-03-01 12:10:14 +0000207 CaptureArgs::UNSET_UID, {}, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700208 };
209
Vishnu Nair7aa0eb72023-01-24 03:59:27 +0000210 auto getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers);
211
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700212 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
213 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800214 mCaptureScreenBuffer =
215 std::make_shared<renderengine::mock::FakeExternalTexture>(renderArea->getReqWidth(),
216 renderArea->getReqHeight(),
217 HAL_PIXEL_FORMAT_RGBA_8888, 1,
218 usage);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700219
Vishnu Nair7aa0eb72023-01-24 03:59:27 +0000220 auto future = mFlinger.renderScreenImpl(std::move(renderArea), getLayerSnapshots,
Patrick Williams7584c6a2022-10-29 02:10:58 +0000221 mCaptureScreenBuffer, forSystem, regionSampling);
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700222 ASSERT_TRUE(future.valid());
223 const auto fenceResult = future.get();
Sally Qi59a9f502021-10-12 18:53:23 +0000224
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700225 EXPECT_EQ(NO_ERROR, fenceStatus(fenceResult));
226 if (fenceResult.ok()) {
227 fenceResult.value()->waitForever(LOG_TAG);
Sally Qi59a9f502021-10-12 18:53:23 +0000228 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700229
230 LayerCase::cleanup(this);
231}
232
Sally Qi4cabdd02021-08-05 16:45:57 -0700233template <class T>
234std::future<T> futureOf(T obj) {
235 std::promise<T> resultPromise;
236 std::future<T> resultFuture = resultPromise.get_future();
237 resultPromise.set_value(std::move(obj));
238 return resultFuture;
239}
240
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700241/* ------------------------------------------------------------------------
242 * Variants for each display configuration which can be tested
243 */
244
245template <typename Derived>
246struct BaseDisplayVariant {
247 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700248 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700249
250 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700251 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700252 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700253
Peiyong Line9d809e2020-04-14 13:10:48 -0700254 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700255 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700256 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700257 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800258 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700259
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800260 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
261 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
262 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
263 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
264 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
265 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
266 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique9370a482019-10-03 17:58:30 -0700267
268 const ::testing::TestInfo* const test_info =
269 ::testing::UnitTest::GetInstance()->current_test_info();
270
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800271 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
272 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800273 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
274 .setIsSecure(Derived::IS_SECURE)
Xiang Wang839fe5b2022-04-04 17:39:38 +0000275 .setPowerAdvisor(test->mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800276 .setName(std::string("Injected display for ") +
277 test_info->test_case_name() + "." + test_info->name())
278 .build();
Lloyd Pique9370a482019-10-03 17:58:30 -0700279
280 auto compositionDisplay =
281 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
282 ceDisplayArgs);
283
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700284 constexpr auto kDisplayConnectionType = ui::DisplayConnectionType::Internal;
285 constexpr bool kIsPrimary = true;
286
Leon Scroggins IIIba9323a2023-02-22 10:40:20 -0500287 test->mDisplay =
288 FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
289 kDisplayConnectionType, HWC_DISPLAY, kIsPrimary)
290 .setDisplaySurface(test->mDisplaySurface)
291 .setNativeWindow(test->mNativeWindow)
292 .setSecure(Derived::IS_SECURE)
293 .setPowerMode(Derived::INIT_POWER_MODE)
294 .setRefreshRateSelector(test->mFlinger.scheduler()->refreshRateSelector())
295 .skipRegisterDisplay()
296 .inject();
Ady Abrahamd11bade2022-08-01 16:18:03 -0700297 Mock::VerifyAndClear(test->mNativeWindow.get());
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700298
299 constexpr bool kIsInternal = kDisplayConnectionType == ui::DisplayConnectionType::Internal;
300 test->mDisplay->setLayerFilter({LAYER_STACK, kIsInternal});
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700301 }
302
303 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700304 static void setupPreconditionCallExpectations(CompositionTest* test) {
305 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500306 .WillOnce(DoAll(SetArgPointee<1>(
307 std::vector<aidl::android::hardware::graphics::composer3::
308 DisplayCapability>({})),
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700309 Return(Error::NONE)));
310 }
311
312 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700313 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Ady Abrahamdc011a92021-12-21 14:06:44 -0800314 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700315 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
316 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
317 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
318 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
319
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700320 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
321 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
322
323 Case::CompositionType::setupHwcSetCallExpectations(test);
324 Case::CompositionType::setupHwcGetCallExpectations(test);
325 }
326
327 template <typename Case>
328 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000329 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700330 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000331 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700332 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000333 const bool, base::unique_fd&&) -> std::future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700334 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
335 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
336 displaySettings.physicalDisplay);
337 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
338 displaySettings.clip);
Patrick Williams2e9748f2022-08-09 22:48:18 +0000339 return futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Pique9370a482019-10-03 17:58:30 -0700340 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700341 }
342
343 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
344 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
345 }
346
347 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
348 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
349 }
350
351 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800352 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
353 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800354
Lloyd Pique542307f2018-10-19 13:24:08 -0700355 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700356 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700357 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700358 }
359
Lloyd Pique66d68602019-02-13 14:23:31 -0800360 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800361 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
362 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800363 }
364
365 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800366 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800367 }
368
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700369 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700370 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700371 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700372 .Times(1);
373 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
374 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
375
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800376 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
377 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
378 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
379 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000380 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700381 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000382 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700383 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000384 const bool, base::unique_fd&&) -> std::future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700385 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
386 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
387 displaySettings.physicalDisplay);
388 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
389 displaySettings.clip);
390 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Patrick Williams2e9748f2022-08-09 22:48:18 +0000391 return futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Pique9370a482019-10-03 17:58:30 -0700392 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700393 }
394
395 template <typename Case>
396 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
397 Case::Layer::setupRECompositionCallExpectations(test);
398 }
399
400 template <typename Case>
401 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
402 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700403 }
404};
405
406struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
407
408struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
409 static constexpr bool IS_SECURE = false;
410
411 template <typename Case>
412 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
413 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700414 }
415
416 template <typename Case>
417 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
418 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700419 }
420};
421
422struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700423 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700424
425 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700426 static void setupPreconditionCallExpectations(CompositionTest*) {}
427
428 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700429 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
430 // TODO: This seems like an unnecessary call if display is powered off.
Ady Abrahamdc011a92021-12-21 14:06:44 -0800431 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700432
433 // TODO: This seems like an unnecessary call if display is powered off.
434 Case::CompositionType::setupHwcSetCallExpectations(test);
435 }
436
437 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800438 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
439 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700440
441 static void setupRECompositionCallExpectations(CompositionTest* test) {
442 // TODO: This seems like an unnecessary call if display is powered off.
443 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
444 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
445 }
446
447 template <typename Case>
448 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
449};
450
451/* ------------------------------------------------------------------------
452 * Variants for each layer configuration which can be tested
453 */
454
455template <typename LayerProperties>
456struct BaseLayerProperties {
457 static constexpr uint32_t WIDTH = 100;
458 static constexpr uint32_t HEIGHT = 100;
459 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
460 static constexpr uint64_t USAGE =
461 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
462 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
463 static constexpr uint32_t SCALING_MODE = 0;
464 static constexpr uint32_t TRANSFORM = 0;
465 static constexpr uint32_t LAYER_FLAGS = 0;
466 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
467 static constexpr IComposerClient::BlendMode BLENDMODE =
468 IComposerClient::BlendMode::PREMULTIPLIED;
469
Patrick Williams83f36b22022-09-14 17:57:35 +0000470 static void setupLatchedBuffer(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700471 Mock::VerifyAndClear(test->mRenderEngine);
472
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000473 const auto buffer = std::make_shared<
474 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
475 LayerProperties::HEIGHT,
476 DEFAULT_TEXTURE_ID,
477 LayerProperties::FORMAT,
478 LayerProperties::USAGE |
479 GraphicBuffer::USAGE_HW_TEXTURE);
480
481 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
482 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
483 layerDrawingState.buffer = buffer;
484 layerDrawingState.acquireFence = Fence::NO_FENCE;
485 layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
486 layer->setSurfaceDamageRegion(
487 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700488
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700489 bool ignoredRecomputeVisibleRegions;
Vishnu Nair397a0e32022-07-26 00:01:48 +0000490 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700491 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700492 }
493
Patrick Williams83f36b22022-09-14 17:57:35 +0000494 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700495 setupLatchedBuffer(test, layer);
496 }
497
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700498 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800499 if (!test->mDisplayOff) {
500 // TODO: Coverage of other values
501 EXPECT_CALL(*test->mComposer,
502 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
503 .Times(1);
504 // TODO: Coverage of other values for origin
505 EXPECT_CALL(*test->mComposer,
506 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
507 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
508 LayerProperties::HEIGHT})))
509 .Times(1);
510 EXPECT_CALL(*test->mComposer,
511 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
512 .Times(1);
513 // TODO: Coverage of other values
514 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700515
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800516 // These expectations retire on saturation as the code path these
517 // expectations are for appears to make an extra call to them.
518 // TODO: Investigate this extra call
519 EXPECT_CALL(*test->mComposer,
520 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
521 .Times(AtLeast(1))
522 .RetiresOnSaturation();
523 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700524 }
525
526 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800527 if (!test->mDisplayOff) {
528 EXPECT_CALL(*test->mComposer,
529 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
530 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
531 LayerProperties::HEIGHT})))
532 .Times(1);
533 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700534 }
535
536 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800537 if (!test->mDisplayOff) {
538 EXPECT_CALL(*test->mComposer,
539 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
540 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
541 .Times(1);
542 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700543 }
544
545 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800546 if (!test->mDisplayOff) {
547 EXPECT_CALL(*test->mComposer,
548 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
549 std::vector<IComposerClient::Rect>(
550 {IComposerClient::Rect(
551 {0, 0, LayerProperties::WIDTH,
552 LayerProperties::HEIGHT})})))
553 .Times(1);
554 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700555 }
556
557 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800558 if (!test->mDisplayOff) {
559 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
560 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700561
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800562 // TODO: use COLOR
563 EXPECT_CALL(*test->mComposer,
564 setLayerColor(HWC_DISPLAY, HWC_LAYER,
Ady Abraham6e60b142022-01-06 18:10:35 -0800565 aidl::android::hardware::graphics::composer3::Color(
566 {1.0f, 1.0f, 1.0f, 1.0f})))
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800567 .Times(1);
568 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700569 }
570
571 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800572 if (!test->mDisplayOff) {
573 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
574 .Times(1);
575 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
576 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700577 }
578
579 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000580 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700581 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000582 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700583 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000584 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000585 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
586 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
587 displaySettings.physicalDisplay);
588 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
589 displaySettings.clip);
590 // screen capture adds an additional color layer as an alpha
591 // prefill, so gtet the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000592 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800593 if (layerSettings.empty()) {
594 ADD_FAILURE() << "layerSettings was not expected to be empty in "
595 "setupREBufferCompositionCommonCallExpectations "
596 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700597 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800598 }
Sally Qi59a9f502021-10-12 18:53:23 +0000599 const renderengine::LayerSettings layer = layerSettings.back();
600 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
601 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
602 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
603 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
604 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
605 EXPECT_EQ(false, layer.source.buffer.isOpaque);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700606 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
607 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Alec Mouri74c7ae12023-03-26 02:57:47 +0000608 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
Sally Qi59a9f502021-10-12 18:53:23 +0000609 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700610 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000611 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700612 }
613
614 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
615 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700616 }
617
618 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
619 setupREBufferCompositionCallExpectations(test);
620 }
621
622 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
623 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
624 }
625
626 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
627 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
628 }
629
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700630 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000631 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700632 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000633 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700634 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000635 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000636 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
637 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
638 displaySettings.physicalDisplay);
639 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
640 displaySettings.clip);
641 // screen capture adds an additional color layer as an alpha
642 // prefill, so get the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000643 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800644 if (layerSettings.empty()) {
645 ADD_FAILURE()
646 << "layerSettings was not expected to be empty in "
647 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700648 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800649 }
Sally Qi59a9f502021-10-12 18:53:23 +0000650 const renderengine::LayerSettings layer = layerSettings.back();
651 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000652 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
653 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000654 layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700655 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
656 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Alec Mouri74c7ae12023-03-26 02:57:47 +0000657 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
Sally Qi59a9f502021-10-12 18:53:23 +0000658 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700659 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000660 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700661 }
662
663 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
664 setupREColorCompositionCallExpectations(test);
665 }
666};
667
668struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
669
Vishnu Nairfa247b12020-02-11 08:58:26 -0800670struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800671 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
672};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700673
674struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
675 using Base = BaseLayerProperties<SidebandLayerProperties>;
676 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
677
Patrick Williams83f36b22022-09-14 17:57:35 +0000678 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700679 sp<NativeHandle> stream =
680 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
681 false);
682 test->mFlinger.setLayerSidebandStream(layer, stream);
683 }
684
685 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
686 EXPECT_CALL(*test->mComposer,
687 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
688 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
689 .Times(1);
690 }
691
692 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
693 EXPECT_CALL(*test->mComposer,
694 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
695 reinterpret_cast<native_handle_t*>(
696 DEFAULT_SIDEBAND_STREAM)))
697 .WillOnce(Return(Error::NONE));
698
699 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
700 }
701
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000702 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700703};
704
Garfield Tande619fa2020-10-02 17:13:53 -0700705template <typename LayerProperties>
706struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
707 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700708
709 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000710 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700711 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000712 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700713 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000714 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000715 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
716 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
717 displaySettings.physicalDisplay);
718 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
719 displaySettings.clip);
720 // screen capture adds an additional color layer as an alpha
721 // prefill, so get the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000722 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800723 if (layerSettings.empty()) {
724 ADD_FAILURE() << "layerSettings was not expected to be empty in "
725 "setupInsecureREBufferCompositionCommonCallExpectations "
726 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700727 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800728 }
Sally Qi59a9f502021-10-12 18:53:23 +0000729 const renderengine::LayerSettings layer = layerSettings.back();
730 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
731 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700732 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
733 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Alec Mouri74c7ae12023-03-26 02:57:47 +0000734 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
Sally Qi59a9f502021-10-12 18:53:23 +0000735 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700736 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000737 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700738 }
739
740 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
741 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700742 }
743
744 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
745 setupInsecureREBufferCompositionCommonCallExpectations(test);
746 }
747};
748
Garfield Tande619fa2020-10-02 17:13:53 -0700749struct ParentSecureLayerProperties
750 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
751
752struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
753 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
754};
755
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700756struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
757 using Base = BaseLayerProperties<CursorLayerProperties>;
758
Patrick Williams83f36b22022-09-14 17:57:35 +0000759 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700760 Base::setupLayerState(test, layer);
761 test->mFlinger.setLayerPotentialCursor(layer, true);
762 }
763};
764
765struct NoLayerVariant {
Patrick Williams83f36b22022-09-14 17:57:35 +0000766 using FlingerLayerType = sp<Layer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700767
768 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
769 static void injectLayer(CompositionTest*, FlingerLayerType) {}
770 static void cleanupInjectedLayers(CompositionTest*) {}
771
772 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
773 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
774};
775
776template <typename LayerProperties>
777struct BaseLayerVariant {
778 template <typename L, typename F>
779 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700780 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700781
782 sp<L> layer = factory();
783
Dominik Laskowski49cea512019-11-12 14:13:23 -0800784 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700785 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800786
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700787 Mock::VerifyAndClear(test->mComposer);
788 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700789 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700790
Garfield Tande619fa2020-10-02 17:13:53 -0700791 initLayerDrawingStateAndComputeBounds(test, layer);
792
793 return layer;
794 }
795
796 template <typename L>
797 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700798 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700799 layerDrawingState.layerStack = LAYER_STACK;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700800 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
801 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700802 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700803 }
804
805 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
806 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
807 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
808
Lloyd Piquede196652020-01-22 17:29:58 -0800809 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
810 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700811 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
812 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700813
814 Mock::VerifyAndClear(test->mComposer);
815
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700816 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
817 }
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();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800825
826 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700827 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700828 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700829 }
830};
831
832template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800833struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700834 using Base = BaseLayerVariant<LayerProperties>;
Patrick Williams46b61b92022-09-01 17:25:49 +0000835 using FlingerLayerType = sp<Layer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700836
837 static FlingerLayerType createLayer(CompositionTest* test) {
Patrick Williams46b61b92022-09-01 17:25:49 +0000838 FlingerLayerType layer = Base::template createLayerWithFactory<Layer>(test, [test]() {
839 return sp<Layer>::make(LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(),
840 "test-layer", LayerProperties::LAYER_FLAGS,
841 LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700842 });
Vishnu Nair60356342018-11-13 13:00:45 -0800843
844 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800845 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700846 return layer;
847 }
848
849 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700850 LayerProperties::setupREColorCompositionCallExpectations(test);
851 }
852
853 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
854 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
855 }
856
857 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
858 LayerProperties::setupHwcSetGeometryCallExpectations(test);
859 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
860 }
861
862 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
863 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
864 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
865 }
866};
867
868template <typename LayerProperties>
869struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
870 using Base = BaseLayerVariant<LayerProperties>;
Patrick Williams83f36b22022-09-14 17:57:35 +0000871 using FlingerLayerType = sp<Layer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700872
873 static FlingerLayerType createLayer(CompositionTest* test) {
874 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
875
876 FlingerLayerType layer =
Patrick Williams83f36b22022-09-14 17:57:35 +0000877 Base::template createLayerWithFactory<Layer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700878 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700879 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700880 args.textureName = test->mFlinger.mutableTexturePool().back();
Patrick Williams83f36b22022-09-14 17:57:35 +0000881 return sp<Layer>::make(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700882 });
883
884 LayerProperties::setupLayerState(test, layer);
885
886 return layer;
887 }
888
889 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700890 Base::cleanupInjectedLayers(test);
891 }
892
893 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
894 LayerProperties::setupHwcSetGeometryCallExpectations(test);
895 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
896 }
897
898 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
899 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
900 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
901 }
902
903 static void setupRECompositionCallExpectations(CompositionTest* test) {
904 LayerProperties::setupREBufferCompositionCallExpectations(test);
905 }
906
907 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
908 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
909 }
910
911 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
912 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
913 }
914
915 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
916 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
917 }
918};
919
Garfield Tande619fa2020-10-02 17:13:53 -0700920template <typename LayerProperties>
921struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
922 using Base = BaseLayerVariant<LayerProperties>;
Patrick Williams46b61b92022-09-01 17:25:49 +0000923 using FlingerLayerType = sp<Layer>;
Garfield Tande619fa2020-10-02 17:13:53 -0700924
925 static FlingerLayerType createLayer(CompositionTest* test) {
926 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700927 LayerProperties::LAYER_FLAGS, LayerMetadata());
Patrick Williams46b61b92022-09-01 17:25:49 +0000928 FlingerLayerType layer = sp<Layer>::make(args);
Garfield Tande619fa2020-10-02 17:13:53 -0700929 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
930 return layer;
931 }
932};
933
934template <typename LayerVariant, typename ParentLayerVariant>
935struct ChildLayerVariant : public LayerVariant {
936 using Base = LayerVariant;
937 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
938 using ParentBase = ParentLayerVariant;
939
940 static FlingerLayerType createLayer(CompositionTest* test) {
941 // Need to create child layer first. Otherwise layer history size will be 2.
942 FlingerLayerType layer = Base::createLayer(test);
943
944 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
945 parentLayer->addChild(layer);
946 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
947
948 test->mAuxiliaryLayers.push_back(parentLayer);
949
950 return layer;
951 }
952
953 static void cleanupInjectedLayers(CompositionTest* test) {
954 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
955 // following call.
956 test->mAuxiliaryLayers.clear();
957
958 Base::cleanupInjectedLayers(test);
959 }
960};
961
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700962/* ------------------------------------------------------------------------
963 * Variants to control how the composition type is changed
964 */
965
966struct NoCompositionTypeVariant {
967 static void setupHwcSetCallExpectations(CompositionTest*) {}
968
969 static void setupHwcGetCallExpectations(CompositionTest* test) {
970 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
971 }
972};
973
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500974template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700975struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500976 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
977 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700978
979 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800980 if (!test->mDisplayOff) {
981 EXPECT_CALL(*test->mComposer,
982 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
983 .Times(1);
984 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700985 }
986
987 static void setupHwcGetCallExpectations(CompositionTest* test) {
988 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
989 }
990};
991
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500992template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
993 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700994struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500995 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
996 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700997
998 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800999 if (!test->mDisplayOff) {
1000 EXPECT_CALL(*test->mComposer,
1001 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1002 .Times(1);
1003 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001004 }
1005
1006 static void setupHwcGetCallExpectations(CompositionTest* test) {
1007 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1008 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1009 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001010 SetArgPointee<2>(
1011 std::vector<aidl::android::hardware::graphics::composer3::
1012 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001013 Return(Error::NONE)));
1014 }
1015};
1016
1017/* ------------------------------------------------------------------------
1018 * Variants to select how the composition is expected to be handled
1019 */
1020
1021struct CompositionResultBaseVariant {
1022 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1023
1024 template <typename Case>
1025 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1026 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1027 }
1028
1029 template <typename Case>
1030 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1031 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1032 }
1033};
1034
1035struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1036 template <typename Case>
1037 static void setupCallExpectations(CompositionTest* test) {
1038 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1039 Case::Display::setupHwcCompositionCallExpectations(test);
1040 }
1041};
1042
1043struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1044 template <typename Case>
1045 static void setupCallExpectations(CompositionTest* test) {
1046 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1047 Case::Display::setupHwcCompositionCallExpectations(test);
1048 }
1049};
1050
1051struct RECompositionResultVariant : public CompositionResultBaseVariant {
1052 template <typename Case>
1053 static void setupCallExpectations(CompositionTest* test) {
1054 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001055 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001056 Case::Display::setupRECompositionCallExpectations(test);
1057 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1058 }
1059};
1060
Lloyd Pique66d68602019-02-13 14:23:31 -08001061struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001062 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001063 const auto outputLayer =
1064 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001065 LOG_FATAL_IF(!outputLayer);
1066 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001067 }
1068
1069 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001070 static void setupCallExpectations(CompositionTest* test) {
1071 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1072 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1073 Case::Display::setupRECompositionCallExpectations(test);
1074 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1075 }
1076
1077 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001078 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1079
1080 template <typename Case>
1081 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1082};
1083
Lloyd Pique4fe29402019-08-12 16:51:24 -07001084struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1085 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1086 test->mFlinger.mutableDebugDisableHWC() = true;
1087 }
1088
1089 template <typename Case>
1090 static void setupCallExpectations(CompositionTest* test) {
1091 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1092 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1093 Case::Display::setupRECompositionCallExpectations(test);
1094 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1095 }
1096
1097 template <typename Case>
1098 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1099
1100 template <typename Case>
1101 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1102};
1103
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001104struct EmptyScreenshotResultVariant {
1105 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1106
1107 template <typename Case>
1108 static void setupCallExpectations(CompositionTest*) {}
1109};
1110
1111struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1112 using Base = EmptyScreenshotResultVariant;
1113
1114 template <typename Case>
1115 static void setupCallExpectations(CompositionTest* test) {
1116 Base::template setupCallExpectations<Case>(test);
1117 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1118 }
1119};
1120
1121/* ------------------------------------------------------------------------
1122 * Composition test case, containing all the variants being tested
1123 */
1124
1125template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1126 typename CompositionResultCase>
1127struct CompositionCase {
1128 using ThisCase =
1129 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1130 using Display = DisplayCase;
1131 using Layer = LayerCase;
1132 using CompositionType = CompositionTypeCase;
1133 using CompositionResult = CompositionResultCase;
1134
1135 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001136 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001137 Display::setupPreconditions(test);
1138
1139 auto layer = Layer::createLayer(test);
1140 Layer::injectLayer(test, layer);
1141 CompositionResult::setupLayerState(test, layer);
1142 }
1143
1144 static void setupForDirtyGeometry(CompositionTest* test) {
1145 setupCommon(test);
1146
1147 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1148 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1149 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1150 CompositionResult::template setupCallExpectations<ThisCase>(test);
1151 }
1152
1153 static void setupForDirtyFrame(CompositionTest* test) {
1154 setupCommon(test);
1155
1156 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1157 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1158 CompositionResult::template setupCallExpectations<ThisCase>(test);
1159 }
1160
1161 static void setupForScreenCapture(CompositionTest* test) {
1162 setupCommon(test);
1163
1164 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1165 CompositionResult::template setupCallExpectations<ThisCase>(test);
1166 }
1167
1168 static void cleanup(CompositionTest* test) {
1169 Layer::cleanupInjectedLayers(test);
1170
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001171 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1172 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1173 ->mutableLayers()
1174 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001175 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001176 }
1177};
1178
1179/* ------------------------------------------------------------------------
1180 * Composition cases to test
1181 */
1182
1183TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1184 displayRefreshCompositionDirtyGeometry<
1185 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1186 NoCompositionResultVariant>>();
1187}
1188
1189TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1190 displayRefreshCompositionDirtyFrame<
1191 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1192 NoCompositionResultVariant>>();
1193}
1194
1195TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1196 captureScreenComposition<
1197 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1198 EmptyScreenshotResultVariant>>();
1199}
1200
1201/* ------------------------------------------------------------------------
1202 * Simple buffer layers
1203 */
1204
1205TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001206 displayRefreshCompositionDirtyGeometry<CompositionCase<
1207 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1208 KeepCompositionTypeVariant<
1209 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1210 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001211}
1212
1213TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001214 displayRefreshCompositionDirtyFrame<CompositionCase<
1215 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1216 KeepCompositionTypeVariant<
1217 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1218 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001219}
1220
1221TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001222 displayRefreshCompositionDirtyFrame<CompositionCase<
1223 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1224 ChangeCompositionTypeVariant<
1225 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1226 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1227 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001228}
1229
1230TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1231 captureScreenComposition<
1232 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1233 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1234}
1235
1236/* ------------------------------------------------------------------------
1237 * Single-color layers
1238 */
1239
Vishnu Nairfa247b12020-02-11 08:58:26 -08001240TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001241 displayRefreshCompositionDirtyGeometry<CompositionCase<
1242 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1243 KeepCompositionTypeVariant<
1244 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1245 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001246}
1247
Vishnu Nairfa247b12020-02-11 08:58:26 -08001248TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001249 displayRefreshCompositionDirtyFrame<CompositionCase<
1250 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1251 KeepCompositionTypeVariant<
1252 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1253 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001254}
1255
Vishnu Nairfa247b12020-02-11 08:58:26 -08001256TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001257 displayRefreshCompositionDirtyFrame<CompositionCase<
1258 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1259 ChangeCompositionTypeVariant<
1260 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1261 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1262 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001263}
1264
Vishnu Nairfa247b12020-02-11 08:58:26 -08001265TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001266 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001267 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001268 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1269}
1270
1271/* ------------------------------------------------------------------------
1272 * Layers with sideband buffers
1273 */
1274
1275TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001276 displayRefreshCompositionDirtyGeometry<CompositionCase<
1277 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1278 KeepCompositionTypeVariant<
1279 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1280 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001281}
1282
1283TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001284 displayRefreshCompositionDirtyFrame<CompositionCase<
1285 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1286 KeepCompositionTypeVariant<
1287 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1288 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001289}
1290
1291TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001292 displayRefreshCompositionDirtyFrame<CompositionCase<
1293 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1294 ChangeCompositionTypeVariant<
1295 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1296 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1297 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001298}
1299
1300TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1301 captureScreenComposition<
1302 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1303 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1304}
1305
1306/* ------------------------------------------------------------------------
1307 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1308 */
1309
1310TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001311 displayRefreshCompositionDirtyGeometry<CompositionCase<
1312 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1313 KeepCompositionTypeVariant<
1314 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1315 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001316}
1317
1318TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001319 displayRefreshCompositionDirtyFrame<CompositionCase<
1320 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1321 KeepCompositionTypeVariant<
1322 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1323 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001324}
1325
1326TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001327 displayRefreshCompositionDirtyFrame<CompositionCase<
1328 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1329 ChangeCompositionTypeVariant<
1330 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1331 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1332 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001333}
1334
1335TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1336 captureScreenComposition<
1337 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1338 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1339}
1340
1341/* ------------------------------------------------------------------------
1342 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1343 */
1344
1345TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001346 displayRefreshCompositionDirtyGeometry<CompositionCase<
1347 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1348 KeepCompositionTypeVariant<
1349 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1350 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001351}
1352
1353TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001354 displayRefreshCompositionDirtyFrame<CompositionCase<
1355 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1356 KeepCompositionTypeVariant<
1357 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1358 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001359}
1360
1361TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1362 captureScreenComposition<
1363 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1364 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1365}
1366
1367/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001368 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1369 */
1370
1371TEST_F(CompositionTest,
1372 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001373 displayRefreshCompositionDirtyGeometry<CompositionCase<
1374 InsecureDisplaySetupVariant,
1375 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1376 ContainerLayerVariant<SecureLayerProperties>>,
1377 KeepCompositionTypeVariant<
1378 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1379 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001380}
1381
1382TEST_F(CompositionTest,
1383 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001384 displayRefreshCompositionDirtyFrame<CompositionCase<
1385 InsecureDisplaySetupVariant,
1386 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1387 ContainerLayerVariant<SecureLayerProperties>>,
1388 KeepCompositionTypeVariant<
1389 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1390 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001391}
1392
1393TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1394 captureScreenComposition<
1395 CompositionCase<InsecureDisplaySetupVariant,
1396 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1397 ContainerLayerVariant<SecureLayerProperties>>,
1398 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1399}
1400
1401/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001402 * Cursor layers
1403 */
1404
1405TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001406 displayRefreshCompositionDirtyGeometry<CompositionCase<
1407 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1408 KeepCompositionTypeVariant<
1409 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1410 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001411}
1412
1413TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001414 displayRefreshCompositionDirtyFrame<CompositionCase<
1415 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1416 KeepCompositionTypeVariant<
1417 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1418 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001419}
1420
1421TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001422 displayRefreshCompositionDirtyFrame<CompositionCase<
1423 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1424 ChangeCompositionTypeVariant<
1425 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1426 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1427 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001428}
1429
1430TEST_F(CompositionTest, captureScreenCursorLayer) {
1431 captureScreenComposition<
1432 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1433 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1434}
1435
1436/* ------------------------------------------------------------------------
1437 * Simple buffer layer on a display which is powered off.
1438 */
1439
1440TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001441 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001442 displayRefreshCompositionDirtyGeometry<CompositionCase<
1443 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001444 KeepCompositionTypeVariant<
1445 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001446 HwcCompositionResultVariant>>();
1447}
1448
1449TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001450 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001451 displayRefreshCompositionDirtyFrame<CompositionCase<
1452 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001453 KeepCompositionTypeVariant<
1454 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001455 HwcCompositionResultVariant>>();
1456}
1457
1458TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001459 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001460 displayRefreshCompositionDirtyFrame<CompositionCase<
1461 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001462 ChangeCompositionTypeVariant<
1463 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1464 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001465 RECompositionResultVariant>>();
1466}
1467
1468TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1469 captureScreenComposition<CompositionCase<
1470 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1471 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1472}
1473
Lloyd Pique4fe29402019-08-12 16:51:24 -07001474/* ------------------------------------------------------------------------
1475 * Client composition forced through debug/developer settings
1476 */
1477
1478TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001479 displayRefreshCompositionDirtyGeometry<CompositionCase<
1480 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1481 KeepCompositionTypeVariant<
1482 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1483 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001484}
1485
1486TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001487 displayRefreshCompositionDirtyFrame<CompositionCase<
1488 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1489 KeepCompositionTypeVariant<
1490 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1491 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001492}
1493
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001494} // namespace
1495} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001496
1497// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001498#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"