blob: 554e454183116763bfb337db914037db9ac8e678 [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>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070033#include <renderengine/mock/Framebuffer.h>
34#include <renderengine/mock/Image.h>
35#include <renderengine/mock/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070036#include <system/window.h>
37#include <utils/String8.h>
38
39#include "BufferQueueLayer.h"
Garfield Tande619fa2020-10-02 17:13:53 -070040#include "ContainerLayer.h"
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020041#include "DisplayRenderArea.h"
Vishnu Nairfa247b12020-02-11 08:58:26 -080042#include "EffectLayer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070043#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070044#include "TestableSurfaceFlinger.h"
45#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique9370a482019-10-03 17:58:30 -070046#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070047#include "mock/MockEventThread.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080048#include "mock/MockTimeStats.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070049#include "mock/MockVsyncController.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070050#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070051
52namespace android {
53namespace {
54
Peiyong Line9d809e2020-04-14 13:10:48 -070055namespace hal = android::hardware::graphics::composer::hal;
56
Peiyong Lin65248e02020-04-18 21:15:07 -070057using hal::Error;
58using hal::IComposer;
59using hal::IComposerClient;
60using hal::PowerMode;
61using hal::Transform;
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
90class CompositionTest : public testing::Test {
91public:
92 CompositionTest() {
93 const ::testing::TestInfo* const test_info =
94 ::testing::UnitTest::GetInstance()->current_test_info();
95 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
96
Ana Krulecafb45842019-02-13 13:33:03 -080097 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -070098
Alec Mourif6fd29e2018-11-17 04:56:41 +000099 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
100 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
101 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
102 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700103
104 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800105 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800106
107 mComposer = new Hwc2::mock::Composer();
108 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Garfield Tan9c9c1912021-07-19 12:02:16 -0700109
110 mFlinger.mutableMaxRenderTargetSize() = 16384;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700111 }
112
113 ~CompositionTest() {
114 const ::testing::TestInfo* const test_info =
115 ::testing::UnitTest::GetInstance()->current_test_info();
116 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
117 }
118
Ana Krulecafb45842019-02-13 13:33:03 -0800119 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700120 auto eventThread = std::make_unique<mock::EventThread>();
121 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800122
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700123 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700124 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abraham62f216c2020-10-13 19:07:23 -0700125 .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0,
126 ResyncCallback())));
Dominik Laskowski98041832019-08-01 18:35:59 -0700127
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700128 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700129 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abraham62f216c2020-10-13 19:07:23 -0700130 .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0,
131 ResyncCallback())));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700132
Ady Abraham8cb21882020-08-26 18:22:05 -0700133 auto vsyncController = std::make_unique<mock::VsyncController>();
134 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700135
Ady Abraham8cb21882020-08-26 18:22:05 -0700136 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
137 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100138 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700139 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700140
Dominik Laskowski068173d2021-08-11 17:22:59 -0700141 constexpr scheduler::ISchedulerCallback* kCallback = nullptr;
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700142 constexpr bool kHasMultipleConfigs = true;
Ady Abraham8cb21882020-08-26 18:22:05 -0700143 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
144 std::move(eventThread), std::move(sfEventThread), kCallback,
145 kHasMultipleConfigs);
Ana Krulecafb45842019-02-13 13:33:03 -0800146 }
147
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700148 void setupForceGeometryDirty() {
149 // TODO: This requires the visible region and other related
150 // state to be set, and is problematic for BufferLayers since they are
151 // not visible without a buffer (and setting up a buffer looks like a
152 // pain)
153 // mFlinger.mutableVisibleRegionsDirty() = true;
154
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700155 mFlinger.mutableGeometryDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700156 }
157
158 template <typename Case>
159 void displayRefreshCompositionDirtyGeometry();
160
161 template <typename Case>
162 void displayRefreshCompositionDirtyFrame();
163
164 template <typename Case>
165 void captureScreenComposition();
166
Peiyong Line9d809e2020-04-14 13:10:48 -0700167 std::unordered_set<hal::Capability> mDefaultCapabilities = {hal::Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700168
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800169 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700170 TestableSurfaceFlinger mFlinger;
171 sp<DisplayDevice> mDisplay;
172 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700173 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
174 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700175 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Garfield Tande619fa2020-10-02 17:13:53 -0700176 std::vector<sp<Layer>> mAuxiliaryLayers;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700177
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800178 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
179 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
180
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700181 Hwc2::mock::Composer* mComposer = nullptr;
182 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800183 mock::TimeStats* mTimeStats = new mock::TimeStats();
Lloyd Pique9370a482019-10-03 17:58:30 -0700184 Hwc2::mock::PowerAdvisor mPowerAdvisor;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700185
186 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
187
Alec Mouria90a5702021-04-16 16:36:21 +0000188 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700189};
190
191template <typename LayerCase>
192void CompositionTest::displayRefreshCompositionDirtyGeometry() {
193 setupForceGeometryDirty();
194 LayerCase::setupForDirtyGeometry(this);
195
196 // --------------------------------------------------------------------
197 // Invocation
198
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700199 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700200
201 LayerCase::cleanup(this);
202}
203
204template <typename LayerCase>
205void CompositionTest::displayRefreshCompositionDirtyFrame() {
206 LayerCase::setupForDirtyFrame(this);
207
208 // --------------------------------------------------------------------
209 // Invocation
210
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700211 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700212
213 LayerCase::cleanup(this);
214}
215
216template <typename LayerCase>
217void CompositionTest::captureScreenComposition() {
218 LayerCase::setupForScreenCapture(this);
219
220 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700221 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700222 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700223
Marin Shalamanov1c434292020-06-12 01:47:29 +0200224 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
225 ui::Dataspace::V0_SRGB, ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700226
227 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700228 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
229 CaptureArgs::UNSET_UID, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700230 };
231
232 // TODO: Eliminate expensive/real allocation if possible.
233 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
234 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Alec Mouria90a5702021-04-16 16:36:21 +0000235 mCaptureScreenBuffer = std::make_shared<
236 renderengine::ExternalTexture>(new GraphicBuffer(renderArea->getReqWidth(),
237 renderArea->getReqHeight(),
238 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage,
239 "screenshot"),
240 *mRenderEngine, true);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700241
Sally Qi59a9f502021-10-12 18:53:23 +0000242 auto result = mFlinger.renderScreenImplLocked(*renderArea, traverseLayers, mCaptureScreenBuffer,
243 forSystem, regionSampling);
244 EXPECT_TRUE(result.valid());
245
246 auto& [status, drawFence] = result.get();
247
248 EXPECT_EQ(NO_ERROR, status);
249 if (drawFence.ok()) {
250 sync_wait(drawFence.get(), -1);
251 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700252
253 LayerCase::cleanup(this);
254}
255
Sally Qi4cabdd02021-08-05 16:45:57 -0700256template <class T>
257std::future<T> futureOf(T obj) {
258 std::promise<T> resultPromise;
259 std::future<T> resultFuture = resultPromise.get_future();
260 resultPromise.set_value(std::move(obj));
261 return resultFuture;
262}
263
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700264/* ------------------------------------------------------------------------
265 * Variants for each display configuration which can be tested
266 */
267
268template <typename Derived>
269struct BaseDisplayVariant {
270 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700271 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700272
273 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700274 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700275 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700276
Peiyong Line9d809e2020-04-14 13:10:48 -0700277 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700278 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700279 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700280 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800281 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700282
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800283 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
284 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
285 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
286 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
287 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
288 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
289 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique9370a482019-10-03 17:58:30 -0700290
291 const ::testing::TestInfo* const test_info =
292 ::testing::UnitTest::GetInstance()->current_test_info();
293
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800294 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
295 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800296 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
297 .setIsSecure(Derived::IS_SECURE)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800298 .setPowerAdvisor(&test->mPowerAdvisor)
299 .setName(std::string("Injected display for ") +
300 test_info->test_case_name() + "." + test_info->name())
301 .build();
Lloyd Pique9370a482019-10-03 17:58:30 -0700302
303 auto compositionDisplay =
304 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
305 ceDisplayArgs);
306
Marin Shalamanov700e6392020-02-12 20:22:26 +0100307 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100308 ui::DisplayConnectionType::Internal, HWC_DISPLAY,
Marin Shalamanov700e6392020-02-12 20:22:26 +0100309 true /* isPrimary */)
310 .setDisplaySurface(test->mDisplaySurface)
311 .setNativeWindow(test->mNativeWindow)
312 .setSecure(Derived::IS_SECURE)
313 .setPowerMode(Derived::INIT_POWER_MODE)
314 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800315 Mock::VerifyAndClear(test->mNativeWindow);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700316 test->mDisplay->setLayerStack(LAYER_STACK);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700317 }
318
319 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700320 static void setupPreconditionCallExpectations(CompositionTest* test) {
321 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
322 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
323 Return(Error::NONE)));
324 }
325
326 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700327 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
328 EXPECT_CALL(*test->mComposer,
329 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
330 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700331 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
332 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
333 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
334 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
335
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700336 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
337 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
338
339 Case::CompositionType::setupHwcSetCallExpectations(test);
340 Case::CompositionType::setupHwcGetCallExpectations(test);
341 }
342
343 template <typename Case>
344 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000345 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700346 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000347 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700348 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000349 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700350 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700351 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
352 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
353 displaySettings.physicalDisplay);
354 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
355 displaySettings.clip);
Sally Qi4cabdd02021-08-05 16:45:57 -0700356 return futureOf<renderengine::RenderEngineResult>(
357 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700358 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700359 }
360
361 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
362 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
363 }
364
365 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
366 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
367 }
368
369 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800370 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
371
Lloyd Pique542307f2018-10-19 13:24:08 -0700372 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700373 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700374 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700375 }
376
Lloyd Pique66d68602019-02-13 14:23:31 -0800377 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
378 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
379 }
380
381 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
382 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1);
383 }
384
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700385 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700386 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700387 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700388 .Times(1);
389 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
390 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
391
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800392 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
393 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
394 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
395 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000396 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700397 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000398 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700399 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000400 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700401 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700402 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
403 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
404 displaySettings.physicalDisplay);
405 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
406 displaySettings.clip);
407 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Sally Qi4cabdd02021-08-05 16:45:57 -0700408 return futureOf<renderengine::RenderEngineResult>(
409 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700410 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700411 }
412
413 template <typename Case>
414 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
415 Case::Layer::setupRECompositionCallExpectations(test);
416 }
417
418 template <typename Case>
419 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
420 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700421 }
422};
423
424struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
425
426struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
427 static constexpr bool IS_SECURE = false;
428
429 template <typename Case>
430 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
431 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700432 }
433
434 template <typename Case>
435 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
436 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700437 }
438};
439
440struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700441 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700442
443 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700444 static void setupPreconditionCallExpectations(CompositionTest*) {}
445
446 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700447 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
448 // TODO: This seems like an unnecessary call if display is powered off.
449 EXPECT_CALL(*test->mComposer,
450 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
451 .Times(1);
452
453 // TODO: This seems like an unnecessary call if display is powered off.
454 Case::CompositionType::setupHwcSetCallExpectations(test);
455 }
456
457 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800458 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
459 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700460
461 static void setupRECompositionCallExpectations(CompositionTest* test) {
462 // TODO: This seems like an unnecessary call if display is powered off.
463 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
464 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
465 }
466
467 template <typename Case>
468 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
469};
470
471/* ------------------------------------------------------------------------
472 * Variants for each layer configuration which can be tested
473 */
474
475template <typename LayerProperties>
476struct BaseLayerProperties {
477 static constexpr uint32_t WIDTH = 100;
478 static constexpr uint32_t HEIGHT = 100;
479 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
480 static constexpr uint64_t USAGE =
481 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
482 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
483 static constexpr uint32_t SCALING_MODE = 0;
484 static constexpr uint32_t TRANSFORM = 0;
485 static constexpr uint32_t LAYER_FLAGS = 0;
486 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
487 static constexpr IComposerClient::BlendMode BLENDMODE =
488 IComposerClient::BlendMode::PREMULTIPLIED;
489
490 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
491 auto producer = layer->getProducer();
492
493 IGraphicBufferProducer::QueueBufferOutput qbo;
494 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
495 if (result != NO_ERROR) {
496 ALOGE("Failed to connect() (%d)", result);
497 return;
498 }
499
500 int slot;
501 sp<Fence> fence;
502 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
503 LayerProperties::HEIGHT, LayerProperties::FORMAT,
504 LayerProperties::USAGE, nullptr, nullptr);
505 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
506 ALOGE("Failed to dequeueBuffer() (%d)", result);
507 return;
508 }
509
510 sp<GraphicBuffer> buffer;
511 result = producer->requestBuffer(slot, &buffer);
512 if (result != NO_ERROR) {
513 ALOGE("Failed to requestBuffer() (%d)", result);
514 return;
515 }
516
517 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
518 LayerProperties::DATASPACE,
519 Rect(LayerProperties::WIDTH,
520 LayerProperties::HEIGHT),
521 LayerProperties::SCALING_MODE,
522 LayerProperties::TRANSFORM, Fence::NO_FENCE);
523 result = producer->queueBuffer(slot, qbi, &qbo);
524 if (result != NO_ERROR) {
525 ALOGE("Failed to queueBuffer (%d)", result);
526 return;
527 }
528 }
529
530 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
531 // TODO: Eliminate the complexity of actually creating a buffer
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -0800532 layer->setSizeForTest(LayerProperties::WIDTH, LayerProperties::HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700533 status_t err =
534 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
535 LayerProperties::FORMAT);
536 ASSERT_EQ(NO_ERROR, err);
537 Mock::VerifyAndClear(test->mRenderEngine);
538
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700539 EXPECT_CALL(*test->mFlinger.scheduler(), scheduleFrame()).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700540 enqueueBuffer(test, layer);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700541 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700542
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700543 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700544 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700545 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700546 }
547
548 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
549 setupLatchedBuffer(test, layer);
550 }
551
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700552 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800553 if (!test->mDisplayOff) {
554 // TODO: Coverage of other values
555 EXPECT_CALL(*test->mComposer,
556 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
557 .Times(1);
558 // TODO: Coverage of other values for origin
559 EXPECT_CALL(*test->mComposer,
560 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
561 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
562 LayerProperties::HEIGHT})))
563 .Times(1);
564 EXPECT_CALL(*test->mComposer,
565 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
566 .Times(1);
567 // TODO: Coverage of other values
568 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700569
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800570 // These expectations retire on saturation as the code path these
571 // expectations are for appears to make an extra call to them.
572 // TODO: Investigate this extra call
573 EXPECT_CALL(*test->mComposer,
574 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
575 .Times(AtLeast(1))
576 .RetiresOnSaturation();
577 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700578 }
579
580 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800581 if (!test->mDisplayOff) {
582 EXPECT_CALL(*test->mComposer,
583 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
584 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
585 LayerProperties::HEIGHT})))
586 .Times(1);
587 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700588 }
589
590 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800591 if (!test->mDisplayOff) {
592 EXPECT_CALL(*test->mComposer,
593 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
594 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
595 .Times(1);
596 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700597 }
598
599 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800600 if (!test->mDisplayOff) {
601 EXPECT_CALL(*test->mComposer,
602 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
603 std::vector<IComposerClient::Rect>(
604 {IComposerClient::Rect(
605 {0, 0, LayerProperties::WIDTH,
606 LayerProperties::HEIGHT})})))
607 .Times(1);
608 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700609 }
610
611 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800612 if (!test->mDisplayOff) {
613 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
614 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700615
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800616 // TODO: use COLOR
617 EXPECT_CALL(*test->mComposer,
618 setLayerColor(HWC_DISPLAY, HWC_LAYER,
619 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
620 .Times(1);
621 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700622 }
623
624 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800625 if (!test->mDisplayOff) {
626 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
627 .Times(1);
628 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
629 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700630 }
631
632 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000633 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700634 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000635 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700636 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000637 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000638 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
639 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
640 displaySettings.physicalDisplay);
641 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
642 displaySettings.clip);
643 // screen capture adds an additional color layer as an alpha
644 // prefill, so gtet the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700645 std::future<renderengine::RenderEngineResult> resultFuture =
646 futureOf<renderengine::RenderEngineResult>(
647 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800648 if (layerSettings.empty()) {
649 ADD_FAILURE() << "layerSettings was not expected to be empty in "
650 "setupREBufferCompositionCommonCallExpectations "
651 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700652 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800653 }
Sally Qi59a9f502021-10-12 18:53:23 +0000654 const renderengine::LayerSettings layer = layerSettings.back();
655 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
656 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
657 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
658 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
659 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
660 EXPECT_EQ(false, layer.source.buffer.isOpaque);
661 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
662 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
663 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700664 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000665 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700666 }
667
668 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
669 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700670 }
671
672 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
673 setupREBufferCompositionCallExpectations(test);
674 }
675
676 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
677 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
678 }
679
680 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
681 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
682 }
683
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700684 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000685 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700686 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000687 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700688 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000689 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000690 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
691 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
692 displaySettings.physicalDisplay);
693 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
694 displaySettings.clip);
695 // screen capture adds an additional color layer as an alpha
696 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700697 std::future<renderengine::RenderEngineResult> resultFuture =
698 futureOf<renderengine::RenderEngineResult>(
699 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800700 if (layerSettings.empty()) {
701 ADD_FAILURE()
702 << "layerSettings was not expected to be empty in "
703 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700704 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800705 }
Sally Qi59a9f502021-10-12 18:53:23 +0000706 const renderengine::LayerSettings layer = layerSettings.back();
707 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000708 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
709 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000710 layer.source.solidColor);
711 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
712 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
713 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700714 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000715 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700716 }
717
718 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
719 setupREColorCompositionCallExpectations(test);
720 }
721};
722
723struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
724
Vishnu Nairfa247b12020-02-11 08:58:26 -0800725struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800726 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
727};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700728
729struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
730 using Base = BaseLayerProperties<SidebandLayerProperties>;
731 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
732
733 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
734 sp<NativeHandle> stream =
735 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
736 false);
737 test->mFlinger.setLayerSidebandStream(layer, stream);
738 }
739
740 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
741 EXPECT_CALL(*test->mComposer,
742 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
743 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
744 .Times(1);
745 }
746
747 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
748 EXPECT_CALL(*test->mComposer,
749 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
750 reinterpret_cast<native_handle_t*>(
751 DEFAULT_SIDEBAND_STREAM)))
752 .WillOnce(Return(Error::NONE));
753
754 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
755 }
756
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000757 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700758};
759
Garfield Tande619fa2020-10-02 17:13:53 -0700760template <typename LayerProperties>
761struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
762 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700763
764 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000765 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700766 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000767 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700768 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000769 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000770 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
771 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
772 displaySettings.physicalDisplay);
773 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
774 displaySettings.clip);
775 // screen capture adds an additional color layer as an alpha
776 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700777 std::future<renderengine::RenderEngineResult> resultFuture =
778 futureOf<renderengine::RenderEngineResult>(
779 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800780 if (layerSettings.empty()) {
781 ADD_FAILURE() << "layerSettings was not expected to be empty in "
782 "setupInsecureREBufferCompositionCommonCallExpectations "
783 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700784 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800785 }
Sally Qi59a9f502021-10-12 18:53:23 +0000786 const renderengine::LayerSettings layer = layerSettings.back();
787 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
788 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
789 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
790 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
791 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700792 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000793 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700794 }
795
796 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
797 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700798 }
799
800 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
801 setupInsecureREBufferCompositionCommonCallExpectations(test);
802 }
803};
804
Garfield Tande619fa2020-10-02 17:13:53 -0700805struct ParentSecureLayerProperties
806 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
807
808struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
809 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
810};
811
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700812struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
813 using Base = BaseLayerProperties<CursorLayerProperties>;
814
815 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
816 Base::setupLayerState(test, layer);
817 test->mFlinger.setLayerPotentialCursor(layer, true);
818 }
819};
820
821struct NoLayerVariant {
822 using FlingerLayerType = sp<BufferQueueLayer>;
823
824 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
825 static void injectLayer(CompositionTest*, FlingerLayerType) {}
826 static void cleanupInjectedLayers(CompositionTest*) {}
827
828 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
829 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
830};
831
832template <typename LayerProperties>
833struct BaseLayerVariant {
834 template <typename L, typename F>
835 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700836 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700837
838 sp<L> layer = factory();
839
Dominik Laskowski49cea512019-11-12 14:13:23 -0800840 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700841 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800842
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700843 Mock::VerifyAndClear(test->mComposer);
844 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700845 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700846
Garfield Tande619fa2020-10-02 17:13:53 -0700847 initLayerDrawingStateAndComputeBounds(test, layer);
848
849 return layer;
850 }
851
852 template <typename L>
853 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700854 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700855 layerDrawingState.layerStack = LAYER_STACK;
chaviw766c9c52021-02-10 17:36:47 -0800856 layerDrawingState.width = 100;
857 layerDrawingState.height = 100;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700858 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
859 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700860 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700861 }
862
863 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
864 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
865 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
866
Lloyd Piquede196652020-01-22 17:29:58 -0800867 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
868 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700869 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
870 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700871
872 Mock::VerifyAndClear(test->mComposer);
873
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700874 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
875 }
876
877 static void cleanupInjectedLayers(CompositionTest* test) {
878 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
879 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800880
Lloyd Pique01c77c12019-04-17 12:48:32 -0700881 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700882 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800883
884 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700885 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700886 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700887 }
888};
889
890template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800891struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700892 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800893 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700894
895 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800896 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
897 return new EffectLayer(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700898 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800899 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700900 });
Vishnu Nair60356342018-11-13 13:00:45 -0800901
902 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800903 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700904 return layer;
905 }
906
907 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700908 LayerProperties::setupREColorCompositionCallExpectations(test);
909 }
910
911 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
912 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
913 }
914
915 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
916 LayerProperties::setupHwcSetGeometryCallExpectations(test);
917 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
918 }
919
920 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
921 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
922 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
923 }
924};
925
926template <typename LayerProperties>
927struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
928 using Base = BaseLayerVariant<LayerProperties>;
929 using FlingerLayerType = sp<BufferQueueLayer>;
930
931 static FlingerLayerType createLayer(CompositionTest* test) {
932 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
933
934 FlingerLayerType layer =
935 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700936 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700937 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700938 args.textureName = test->mFlinger.mutableTexturePool().back();
939 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700940 });
941
942 LayerProperties::setupLayerState(test, layer);
943
944 return layer;
945 }
946
947 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700948 Base::cleanupInjectedLayers(test);
949 }
950
951 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
952 LayerProperties::setupHwcSetGeometryCallExpectations(test);
953 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
954 }
955
956 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
957 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
958 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
959 }
960
961 static void setupRECompositionCallExpectations(CompositionTest* test) {
962 LayerProperties::setupREBufferCompositionCallExpectations(test);
963 }
964
965 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
966 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
967 }
968
969 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
970 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
971 }
972
973 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
974 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
975 }
976};
977
Garfield Tande619fa2020-10-02 17:13:53 -0700978template <typename LayerProperties>
979struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
980 using Base = BaseLayerVariant<LayerProperties>;
981 using FlingerLayerType = sp<ContainerLayer>;
982
983 static FlingerLayerType createLayer(CompositionTest* test) {
984 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700985 LayerProperties::LAYER_FLAGS, LayerMetadata());
986 FlingerLayerType layer = new ContainerLayer(args);
987 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
988 return layer;
989 }
990};
991
992template <typename LayerVariant, typename ParentLayerVariant>
993struct ChildLayerVariant : public LayerVariant {
994 using Base = LayerVariant;
995 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
996 using ParentBase = ParentLayerVariant;
997
998 static FlingerLayerType createLayer(CompositionTest* test) {
999 // Need to create child layer first. Otherwise layer history size will be 2.
1000 FlingerLayerType layer = Base::createLayer(test);
1001
1002 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
1003 parentLayer->addChild(layer);
1004 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
1005
1006 test->mAuxiliaryLayers.push_back(parentLayer);
1007
1008 return layer;
1009 }
1010
1011 static void cleanupInjectedLayers(CompositionTest* test) {
1012 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
1013 // following call.
1014 test->mAuxiliaryLayers.clear();
1015
1016 Base::cleanupInjectedLayers(test);
1017 }
1018};
1019
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001020/* ------------------------------------------------------------------------
1021 * Variants to control how the composition type is changed
1022 */
1023
1024struct NoCompositionTypeVariant {
1025 static void setupHwcSetCallExpectations(CompositionTest*) {}
1026
1027 static void setupHwcGetCallExpectations(CompositionTest* test) {
1028 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1029 }
1030};
1031
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001032template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001033struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001034 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1035 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001036
1037 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001038 if (!test->mDisplayOff) {
1039 EXPECT_CALL(*test->mComposer,
1040 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1041 .Times(1);
1042 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001043 }
1044
1045 static void setupHwcGetCallExpectations(CompositionTest* test) {
1046 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1047 }
1048};
1049
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001050template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
1051 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001052struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001053 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1054 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001055
1056 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001057 if (!test->mDisplayOff) {
1058 EXPECT_CALL(*test->mComposer,
1059 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1060 .Times(1);
1061 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001062 }
1063
1064 static void setupHwcGetCallExpectations(CompositionTest* test) {
1065 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1066 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1067 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001068 SetArgPointee<2>(
1069 std::vector<aidl::android::hardware::graphics::composer3::
1070 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001071 Return(Error::NONE)));
1072 }
1073};
1074
1075/* ------------------------------------------------------------------------
1076 * Variants to select how the composition is expected to be handled
1077 */
1078
1079struct CompositionResultBaseVariant {
1080 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1081
1082 template <typename Case>
1083 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1084 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1085 }
1086
1087 template <typename Case>
1088 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1089 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1090 }
1091};
1092
1093struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1094 template <typename Case>
1095 static void setupCallExpectations(CompositionTest* test) {
1096 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1097 Case::Display::setupHwcCompositionCallExpectations(test);
1098 }
1099};
1100
1101struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1102 template <typename Case>
1103 static void setupCallExpectations(CompositionTest* test) {
1104 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1105 Case::Display::setupHwcCompositionCallExpectations(test);
1106 }
1107};
1108
1109struct RECompositionResultVariant : public CompositionResultBaseVariant {
1110 template <typename Case>
1111 static void setupCallExpectations(CompositionTest* test) {
1112 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001113 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001114 Case::Display::setupRECompositionCallExpectations(test);
1115 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1116 }
1117};
1118
Lloyd Pique66d68602019-02-13 14:23:31 -08001119struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001120 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001121 const auto outputLayer =
1122 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001123 LOG_FATAL_IF(!outputLayer);
1124 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001125 }
1126
1127 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001128 static void setupCallExpectations(CompositionTest* test) {
1129 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1130 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1131 Case::Display::setupRECompositionCallExpectations(test);
1132 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1133 }
1134
1135 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001136 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1137
1138 template <typename Case>
1139 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1140};
1141
Lloyd Pique4fe29402019-08-12 16:51:24 -07001142struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1143 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1144 test->mFlinger.mutableDebugDisableHWC() = true;
1145 }
1146
1147 template <typename Case>
1148 static void setupCallExpectations(CompositionTest* test) {
1149 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1150 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1151 Case::Display::setupRECompositionCallExpectations(test);
1152 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1153 }
1154
1155 template <typename Case>
1156 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1157
1158 template <typename Case>
1159 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1160};
1161
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001162struct EmptyScreenshotResultVariant {
1163 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1164
1165 template <typename Case>
1166 static void setupCallExpectations(CompositionTest*) {}
1167};
1168
1169struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1170 using Base = EmptyScreenshotResultVariant;
1171
1172 template <typename Case>
1173 static void setupCallExpectations(CompositionTest* test) {
1174 Base::template setupCallExpectations<Case>(test);
1175 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1176 }
1177};
1178
1179/* ------------------------------------------------------------------------
1180 * Composition test case, containing all the variants being tested
1181 */
1182
1183template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1184 typename CompositionResultCase>
1185struct CompositionCase {
1186 using ThisCase =
1187 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1188 using Display = DisplayCase;
1189 using Layer = LayerCase;
1190 using CompositionType = CompositionTypeCase;
1191 using CompositionResult = CompositionResultCase;
1192
1193 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001194 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001195 Display::setupPreconditions(test);
1196
1197 auto layer = Layer::createLayer(test);
1198 Layer::injectLayer(test, layer);
1199 CompositionResult::setupLayerState(test, layer);
1200 }
1201
1202 static void setupForDirtyGeometry(CompositionTest* test) {
1203 setupCommon(test);
1204
1205 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1206 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1207 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1208 CompositionResult::template setupCallExpectations<ThisCase>(test);
1209 }
1210
1211 static void setupForDirtyFrame(CompositionTest* test) {
1212 setupCommon(test);
1213
1214 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1215 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1216 CompositionResult::template setupCallExpectations<ThisCase>(test);
1217 }
1218
1219 static void setupForScreenCapture(CompositionTest* test) {
1220 setupCommon(test);
1221
1222 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1223 CompositionResult::template setupCallExpectations<ThisCase>(test);
1224 }
1225
1226 static void cleanup(CompositionTest* test) {
1227 Layer::cleanupInjectedLayers(test);
1228
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001229 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1230 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1231 ->mutableLayers()
1232 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001233 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001234 }
1235};
1236
1237/* ------------------------------------------------------------------------
1238 * Composition cases to test
1239 */
1240
1241TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1242 displayRefreshCompositionDirtyGeometry<
1243 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1244 NoCompositionResultVariant>>();
1245}
1246
1247TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1248 displayRefreshCompositionDirtyFrame<
1249 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1250 NoCompositionResultVariant>>();
1251}
1252
1253TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1254 captureScreenComposition<
1255 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1256 EmptyScreenshotResultVariant>>();
1257}
1258
1259/* ------------------------------------------------------------------------
1260 * Simple buffer layers
1261 */
1262
1263TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001264 displayRefreshCompositionDirtyGeometry<CompositionCase<
1265 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1266 KeepCompositionTypeVariant<
1267 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1268 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001269}
1270
1271TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001272 displayRefreshCompositionDirtyFrame<CompositionCase<
1273 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1274 KeepCompositionTypeVariant<
1275 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1276 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001277}
1278
1279TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001280 displayRefreshCompositionDirtyFrame<CompositionCase<
1281 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1282 ChangeCompositionTypeVariant<
1283 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1284 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1285 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001286}
1287
1288TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1289 captureScreenComposition<
1290 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1291 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1292}
1293
1294/* ------------------------------------------------------------------------
1295 * Single-color layers
1296 */
1297
Vishnu Nairfa247b12020-02-11 08:58:26 -08001298TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001299 displayRefreshCompositionDirtyGeometry<CompositionCase<
1300 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1301 KeepCompositionTypeVariant<
1302 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1303 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001304}
1305
Vishnu Nairfa247b12020-02-11 08:58:26 -08001306TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001307 displayRefreshCompositionDirtyFrame<CompositionCase<
1308 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1309 KeepCompositionTypeVariant<
1310 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1311 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001312}
1313
Vishnu Nairfa247b12020-02-11 08:58:26 -08001314TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001315 displayRefreshCompositionDirtyFrame<CompositionCase<
1316 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1317 ChangeCompositionTypeVariant<
1318 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1319 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1320 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001321}
1322
Vishnu Nairfa247b12020-02-11 08:58:26 -08001323TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001324 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001325 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001326 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1327}
1328
1329/* ------------------------------------------------------------------------
1330 * Layers with sideband buffers
1331 */
1332
1333TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001334 displayRefreshCompositionDirtyGeometry<CompositionCase<
1335 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1336 KeepCompositionTypeVariant<
1337 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1338 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001339}
1340
1341TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001342 displayRefreshCompositionDirtyFrame<CompositionCase<
1343 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1344 KeepCompositionTypeVariant<
1345 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1346 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001347}
1348
1349TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001350 displayRefreshCompositionDirtyFrame<CompositionCase<
1351 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1352 ChangeCompositionTypeVariant<
1353 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1354 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1355 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001356}
1357
1358TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1359 captureScreenComposition<
1360 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1361 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1362}
1363
1364/* ------------------------------------------------------------------------
1365 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1366 */
1367
1368TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001369 displayRefreshCompositionDirtyGeometry<CompositionCase<
1370 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1371 KeepCompositionTypeVariant<
1372 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1373 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001374}
1375
1376TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001377 displayRefreshCompositionDirtyFrame<CompositionCase<
1378 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1379 KeepCompositionTypeVariant<
1380 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1381 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001382}
1383
1384TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001385 displayRefreshCompositionDirtyFrame<CompositionCase<
1386 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1387 ChangeCompositionTypeVariant<
1388 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1389 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1390 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001391}
1392
1393TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1394 captureScreenComposition<
1395 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1396 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1397}
1398
1399/* ------------------------------------------------------------------------
1400 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1401 */
1402
1403TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001404 displayRefreshCompositionDirtyGeometry<CompositionCase<
1405 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1406 KeepCompositionTypeVariant<
1407 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1408 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001409}
1410
1411TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001412 displayRefreshCompositionDirtyFrame<CompositionCase<
1413 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1414 KeepCompositionTypeVariant<
1415 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1416 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001417}
1418
1419TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1420 captureScreenComposition<
1421 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1422 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1423}
1424
1425/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001426 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1427 */
1428
1429TEST_F(CompositionTest,
1430 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001431 displayRefreshCompositionDirtyGeometry<CompositionCase<
1432 InsecureDisplaySetupVariant,
1433 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1434 ContainerLayerVariant<SecureLayerProperties>>,
1435 KeepCompositionTypeVariant<
1436 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1437 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001438}
1439
1440TEST_F(CompositionTest,
1441 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001442 displayRefreshCompositionDirtyFrame<CompositionCase<
1443 InsecureDisplaySetupVariant,
1444 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1445 ContainerLayerVariant<SecureLayerProperties>>,
1446 KeepCompositionTypeVariant<
1447 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1448 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001449}
1450
1451TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1452 captureScreenComposition<
1453 CompositionCase<InsecureDisplaySetupVariant,
1454 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1455 ContainerLayerVariant<SecureLayerProperties>>,
1456 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1457}
1458
1459/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001460 * Cursor layers
1461 */
1462
1463TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001464 displayRefreshCompositionDirtyGeometry<CompositionCase<
1465 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1466 KeepCompositionTypeVariant<
1467 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1468 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001469}
1470
1471TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001472 displayRefreshCompositionDirtyFrame<CompositionCase<
1473 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1474 KeepCompositionTypeVariant<
1475 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1476 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001477}
1478
1479TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001480 displayRefreshCompositionDirtyFrame<CompositionCase<
1481 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1482 ChangeCompositionTypeVariant<
1483 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1484 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1485 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001486}
1487
1488TEST_F(CompositionTest, captureScreenCursorLayer) {
1489 captureScreenComposition<
1490 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1491 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1492}
1493
1494/* ------------------------------------------------------------------------
1495 * Simple buffer layer on a display which is powered off.
1496 */
1497
1498TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001499 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001500 displayRefreshCompositionDirtyGeometry<CompositionCase<
1501 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001502 KeepCompositionTypeVariant<
1503 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001504 HwcCompositionResultVariant>>();
1505}
1506
1507TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001508 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001509 displayRefreshCompositionDirtyFrame<CompositionCase<
1510 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001511 KeepCompositionTypeVariant<
1512 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001513 HwcCompositionResultVariant>>();
1514}
1515
1516TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001517 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001518 displayRefreshCompositionDirtyFrame<CompositionCase<
1519 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001520 ChangeCompositionTypeVariant<
1521 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1522 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001523 RECompositionResultVariant>>();
1524}
1525
1526TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1527 captureScreenComposition<CompositionCase<
1528 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1529 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1530}
1531
Lloyd Pique4fe29402019-08-12 16:51:24 -07001532/* ------------------------------------------------------------------------
1533 * Client composition forced through debug/developer settings
1534 */
1535
1536TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001537 displayRefreshCompositionDirtyGeometry<CompositionCase<
1538 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1539 KeepCompositionTypeVariant<
1540 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1541 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001542}
1543
1544TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001545 displayRefreshCompositionDirtyFrame<CompositionCase<
1546 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1547 KeepCompositionTypeVariant<
1548 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1549 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001550}
1551
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001552} // namespace
1553} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001554
1555// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001556#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"