blob: 7174f5852202194bd7ea8e8c68672481c106c01f [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) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800370 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
371 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800372
Lloyd Pique542307f2018-10-19 13:24:08 -0700373 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700374 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700375 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700376 }
377
Lloyd Pique66d68602019-02-13 14:23:31 -0800378 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800379 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
380 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800381 }
382
383 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800384 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800385 }
386
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700387 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700388 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700389 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700390 .Times(1);
391 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
392 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
393
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800394 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
395 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
396 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
397 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000398 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700399 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000400 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700401 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000402 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700403 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700404 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
405 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
406 displaySettings.physicalDisplay);
407 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
408 displaySettings.clip);
409 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Sally Qi4cabdd02021-08-05 16:45:57 -0700410 return futureOf<renderengine::RenderEngineResult>(
411 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700412 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700413 }
414
415 template <typename Case>
416 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
417 Case::Layer::setupRECompositionCallExpectations(test);
418 }
419
420 template <typename Case>
421 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
422 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700423 }
424};
425
426struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
427
428struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
429 static constexpr bool IS_SECURE = false;
430
431 template <typename Case>
432 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
433 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700434 }
435
436 template <typename Case>
437 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
438 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700439 }
440};
441
442struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700443 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700444
445 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700446 static void setupPreconditionCallExpectations(CompositionTest*) {}
447
448 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700449 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
450 // TODO: This seems like an unnecessary call if display is powered off.
451 EXPECT_CALL(*test->mComposer,
452 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
453 .Times(1);
454
455 // TODO: This seems like an unnecessary call if display is powered off.
456 Case::CompositionType::setupHwcSetCallExpectations(test);
457 }
458
459 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800460 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
461 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700462
463 static void setupRECompositionCallExpectations(CompositionTest* test) {
464 // TODO: This seems like an unnecessary call if display is powered off.
465 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
466 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
467 }
468
469 template <typename Case>
470 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
471};
472
473/* ------------------------------------------------------------------------
474 * Variants for each layer configuration which can be tested
475 */
476
477template <typename LayerProperties>
478struct BaseLayerProperties {
479 static constexpr uint32_t WIDTH = 100;
480 static constexpr uint32_t HEIGHT = 100;
481 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
482 static constexpr uint64_t USAGE =
483 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
484 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
485 static constexpr uint32_t SCALING_MODE = 0;
486 static constexpr uint32_t TRANSFORM = 0;
487 static constexpr uint32_t LAYER_FLAGS = 0;
488 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
489 static constexpr IComposerClient::BlendMode BLENDMODE =
490 IComposerClient::BlendMode::PREMULTIPLIED;
491
492 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
493 auto producer = layer->getProducer();
494
495 IGraphicBufferProducer::QueueBufferOutput qbo;
496 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
497 if (result != NO_ERROR) {
498 ALOGE("Failed to connect() (%d)", result);
499 return;
500 }
501
502 int slot;
503 sp<Fence> fence;
504 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
505 LayerProperties::HEIGHT, LayerProperties::FORMAT,
506 LayerProperties::USAGE, nullptr, nullptr);
507 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
508 ALOGE("Failed to dequeueBuffer() (%d)", result);
509 return;
510 }
511
512 sp<GraphicBuffer> buffer;
513 result = producer->requestBuffer(slot, &buffer);
514 if (result != NO_ERROR) {
515 ALOGE("Failed to requestBuffer() (%d)", result);
516 return;
517 }
518
519 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
520 LayerProperties::DATASPACE,
521 Rect(LayerProperties::WIDTH,
522 LayerProperties::HEIGHT),
523 LayerProperties::SCALING_MODE,
524 LayerProperties::TRANSFORM, Fence::NO_FENCE);
525 result = producer->queueBuffer(slot, qbi, &qbo);
526 if (result != NO_ERROR) {
527 ALOGE("Failed to queueBuffer (%d)", result);
528 return;
529 }
530 }
531
532 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
533 // TODO: Eliminate the complexity of actually creating a buffer
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -0800534 layer->setSizeForTest(LayerProperties::WIDTH, LayerProperties::HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700535 status_t err =
536 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
537 LayerProperties::FORMAT);
538 ASSERT_EQ(NO_ERROR, err);
539 Mock::VerifyAndClear(test->mRenderEngine);
540
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700541 EXPECT_CALL(*test->mFlinger.scheduler(), scheduleFrame()).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700542 enqueueBuffer(test, layer);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700543 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700544
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700545 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700546 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700547 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700548 }
549
550 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
551 setupLatchedBuffer(test, layer);
552 }
553
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700554 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800555 if (!test->mDisplayOff) {
556 // TODO: Coverage of other values
557 EXPECT_CALL(*test->mComposer,
558 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
559 .Times(1);
560 // TODO: Coverage of other values for origin
561 EXPECT_CALL(*test->mComposer,
562 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
563 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
564 LayerProperties::HEIGHT})))
565 .Times(1);
566 EXPECT_CALL(*test->mComposer,
567 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
568 .Times(1);
569 // TODO: Coverage of other values
570 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700571
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800572 // These expectations retire on saturation as the code path these
573 // expectations are for appears to make an extra call to them.
574 // TODO: Investigate this extra call
575 EXPECT_CALL(*test->mComposer,
576 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
577 .Times(AtLeast(1))
578 .RetiresOnSaturation();
579 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700580 }
581
582 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800583 if (!test->mDisplayOff) {
584 EXPECT_CALL(*test->mComposer,
585 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
586 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
587 LayerProperties::HEIGHT})))
588 .Times(1);
589 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700590 }
591
592 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800593 if (!test->mDisplayOff) {
594 EXPECT_CALL(*test->mComposer,
595 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
596 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
597 .Times(1);
598 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700599 }
600
601 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800602 if (!test->mDisplayOff) {
603 EXPECT_CALL(*test->mComposer,
604 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
605 std::vector<IComposerClient::Rect>(
606 {IComposerClient::Rect(
607 {0, 0, LayerProperties::WIDTH,
608 LayerProperties::HEIGHT})})))
609 .Times(1);
610 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700611 }
612
613 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800614 if (!test->mDisplayOff) {
615 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
616 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700617
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800618 // TODO: use COLOR
619 EXPECT_CALL(*test->mComposer,
620 setLayerColor(HWC_DISPLAY, HWC_LAYER,
621 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
622 .Times(1);
623 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700624 }
625
626 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800627 if (!test->mDisplayOff) {
628 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
629 .Times(1);
630 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
631 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700632 }
633
634 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000635 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700636 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000637 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700638 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000639 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000640 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
641 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
642 displaySettings.physicalDisplay);
643 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
644 displaySettings.clip);
645 // screen capture adds an additional color layer as an alpha
646 // prefill, so gtet the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700647 std::future<renderengine::RenderEngineResult> resultFuture =
648 futureOf<renderengine::RenderEngineResult>(
649 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800650 if (layerSettings.empty()) {
651 ADD_FAILURE() << "layerSettings was not expected to be empty in "
652 "setupREBufferCompositionCommonCallExpectations "
653 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700654 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800655 }
Sally Qi59a9f502021-10-12 18:53:23 +0000656 const renderengine::LayerSettings layer = layerSettings.back();
657 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
658 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
659 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
660 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
661 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
662 EXPECT_EQ(false, layer.source.buffer.isOpaque);
663 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
664 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
665 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700666 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000667 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700668 }
669
670 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
671 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700672 }
673
674 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
675 setupREBufferCompositionCallExpectations(test);
676 }
677
678 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
679 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
680 }
681
682 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
683 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
684 }
685
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700686 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000687 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700688 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000689 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700690 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000691 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000692 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
693 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
694 displaySettings.physicalDisplay);
695 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
696 displaySettings.clip);
697 // screen capture adds an additional color layer as an alpha
698 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700699 std::future<renderengine::RenderEngineResult> resultFuture =
700 futureOf<renderengine::RenderEngineResult>(
701 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800702 if (layerSettings.empty()) {
703 ADD_FAILURE()
704 << "layerSettings was not expected to be empty in "
705 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700706 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800707 }
Sally Qi59a9f502021-10-12 18:53:23 +0000708 const renderengine::LayerSettings layer = layerSettings.back();
709 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000710 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
711 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000712 layer.source.solidColor);
713 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
714 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
715 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700716 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000717 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700718 }
719
720 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
721 setupREColorCompositionCallExpectations(test);
722 }
723};
724
725struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
726
Vishnu Nairfa247b12020-02-11 08:58:26 -0800727struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800728 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
729};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700730
731struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
732 using Base = BaseLayerProperties<SidebandLayerProperties>;
733 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
734
735 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
736 sp<NativeHandle> stream =
737 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
738 false);
739 test->mFlinger.setLayerSidebandStream(layer, stream);
740 }
741
742 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
743 EXPECT_CALL(*test->mComposer,
744 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
745 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
746 .Times(1);
747 }
748
749 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
750 EXPECT_CALL(*test->mComposer,
751 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
752 reinterpret_cast<native_handle_t*>(
753 DEFAULT_SIDEBAND_STREAM)))
754 .WillOnce(Return(Error::NONE));
755
756 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
757 }
758
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000759 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700760};
761
Garfield Tande619fa2020-10-02 17:13:53 -0700762template <typename LayerProperties>
763struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
764 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700765
766 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000767 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700768 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000769 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700770 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000771 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000772 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
773 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
774 displaySettings.physicalDisplay);
775 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
776 displaySettings.clip);
777 // screen capture adds an additional color layer as an alpha
778 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700779 std::future<renderengine::RenderEngineResult> resultFuture =
780 futureOf<renderengine::RenderEngineResult>(
781 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800782 if (layerSettings.empty()) {
783 ADD_FAILURE() << "layerSettings was not expected to be empty in "
784 "setupInsecureREBufferCompositionCommonCallExpectations "
785 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700786 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800787 }
Sally Qi59a9f502021-10-12 18:53:23 +0000788 const renderengine::LayerSettings layer = layerSettings.back();
789 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
790 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
791 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
792 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
793 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700794 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000795 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700796 }
797
798 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
799 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700800 }
801
802 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
803 setupInsecureREBufferCompositionCommonCallExpectations(test);
804 }
805};
806
Garfield Tande619fa2020-10-02 17:13:53 -0700807struct ParentSecureLayerProperties
808 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
809
810struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
811 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
812};
813
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700814struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
815 using Base = BaseLayerProperties<CursorLayerProperties>;
816
817 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
818 Base::setupLayerState(test, layer);
819 test->mFlinger.setLayerPotentialCursor(layer, true);
820 }
821};
822
823struct NoLayerVariant {
824 using FlingerLayerType = sp<BufferQueueLayer>;
825
826 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
827 static void injectLayer(CompositionTest*, FlingerLayerType) {}
828 static void cleanupInjectedLayers(CompositionTest*) {}
829
830 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
831 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
832};
833
834template <typename LayerProperties>
835struct BaseLayerVariant {
836 template <typename L, typename F>
837 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700838 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700839
840 sp<L> layer = factory();
841
Dominik Laskowski49cea512019-11-12 14:13:23 -0800842 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700843 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800844
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700845 Mock::VerifyAndClear(test->mComposer);
846 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700847 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700848
Garfield Tande619fa2020-10-02 17:13:53 -0700849 initLayerDrawingStateAndComputeBounds(test, layer);
850
851 return layer;
852 }
853
854 template <typename L>
855 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700856 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700857 layerDrawingState.layerStack = LAYER_STACK;
chaviw766c9c52021-02-10 17:36:47 -0800858 layerDrawingState.width = 100;
859 layerDrawingState.height = 100;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700860 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
861 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700862 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700863 }
864
865 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
866 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
867 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
868
Lloyd Piquede196652020-01-22 17:29:58 -0800869 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
870 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700871 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
872 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700873
874 Mock::VerifyAndClear(test->mComposer);
875
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700876 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
877 }
878
879 static void cleanupInjectedLayers(CompositionTest* test) {
880 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
881 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800882
Lloyd Pique01c77c12019-04-17 12:48:32 -0700883 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700884 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800885
886 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700887 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700888 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700889 }
890};
891
892template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800893struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700894 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800895 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700896
897 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800898 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
899 return new EffectLayer(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700900 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800901 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700902 });
Vishnu Nair60356342018-11-13 13:00:45 -0800903
904 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800905 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700906 return layer;
907 }
908
909 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700910 LayerProperties::setupREColorCompositionCallExpectations(test);
911 }
912
913 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
914 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
915 }
916
917 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
918 LayerProperties::setupHwcSetGeometryCallExpectations(test);
919 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
920 }
921
922 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
923 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
924 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
925 }
926};
927
928template <typename LayerProperties>
929struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
930 using Base = BaseLayerVariant<LayerProperties>;
931 using FlingerLayerType = sp<BufferQueueLayer>;
932
933 static FlingerLayerType createLayer(CompositionTest* test) {
934 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
935
936 FlingerLayerType layer =
937 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700938 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700939 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700940 args.textureName = test->mFlinger.mutableTexturePool().back();
941 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700942 });
943
944 LayerProperties::setupLayerState(test, layer);
945
946 return layer;
947 }
948
949 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700950 Base::cleanupInjectedLayers(test);
951 }
952
953 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
954 LayerProperties::setupHwcSetGeometryCallExpectations(test);
955 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
956 }
957
958 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
959 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
960 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
961 }
962
963 static void setupRECompositionCallExpectations(CompositionTest* test) {
964 LayerProperties::setupREBufferCompositionCallExpectations(test);
965 }
966
967 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
968 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
969 }
970
971 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
972 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
973 }
974
975 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
976 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
977 }
978};
979
Garfield Tande619fa2020-10-02 17:13:53 -0700980template <typename LayerProperties>
981struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
982 using Base = BaseLayerVariant<LayerProperties>;
983 using FlingerLayerType = sp<ContainerLayer>;
984
985 static FlingerLayerType createLayer(CompositionTest* test) {
986 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700987 LayerProperties::LAYER_FLAGS, LayerMetadata());
988 FlingerLayerType layer = new ContainerLayer(args);
989 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
990 return layer;
991 }
992};
993
994template <typename LayerVariant, typename ParentLayerVariant>
995struct ChildLayerVariant : public LayerVariant {
996 using Base = LayerVariant;
997 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
998 using ParentBase = ParentLayerVariant;
999
1000 static FlingerLayerType createLayer(CompositionTest* test) {
1001 // Need to create child layer first. Otherwise layer history size will be 2.
1002 FlingerLayerType layer = Base::createLayer(test);
1003
1004 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
1005 parentLayer->addChild(layer);
1006 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
1007
1008 test->mAuxiliaryLayers.push_back(parentLayer);
1009
1010 return layer;
1011 }
1012
1013 static void cleanupInjectedLayers(CompositionTest* test) {
1014 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
1015 // following call.
1016 test->mAuxiliaryLayers.clear();
1017
1018 Base::cleanupInjectedLayers(test);
1019 }
1020};
1021
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001022/* ------------------------------------------------------------------------
1023 * Variants to control how the composition type is changed
1024 */
1025
1026struct NoCompositionTypeVariant {
1027 static void setupHwcSetCallExpectations(CompositionTest*) {}
1028
1029 static void setupHwcGetCallExpectations(CompositionTest* test) {
1030 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1031 }
1032};
1033
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001034template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001035struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001036 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1037 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001038
1039 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001040 if (!test->mDisplayOff) {
1041 EXPECT_CALL(*test->mComposer,
1042 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1043 .Times(1);
1044 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001045 }
1046
1047 static void setupHwcGetCallExpectations(CompositionTest* test) {
1048 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1049 }
1050};
1051
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001052template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
1053 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001054struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001055 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1056 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001057
1058 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001059 if (!test->mDisplayOff) {
1060 EXPECT_CALL(*test->mComposer,
1061 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1062 .Times(1);
1063 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001064 }
1065
1066 static void setupHwcGetCallExpectations(CompositionTest* test) {
1067 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1068 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1069 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001070 SetArgPointee<2>(
1071 std::vector<aidl::android::hardware::graphics::composer3::
1072 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001073 Return(Error::NONE)));
1074 }
1075};
1076
1077/* ------------------------------------------------------------------------
1078 * Variants to select how the composition is expected to be handled
1079 */
1080
1081struct CompositionResultBaseVariant {
1082 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1083
1084 template <typename Case>
1085 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1086 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1087 }
1088
1089 template <typename Case>
1090 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1091 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1092 }
1093};
1094
1095struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1096 template <typename Case>
1097 static void setupCallExpectations(CompositionTest* test) {
1098 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1099 Case::Display::setupHwcCompositionCallExpectations(test);
1100 }
1101};
1102
1103struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1104 template <typename Case>
1105 static void setupCallExpectations(CompositionTest* test) {
1106 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1107 Case::Display::setupHwcCompositionCallExpectations(test);
1108 }
1109};
1110
1111struct RECompositionResultVariant : public CompositionResultBaseVariant {
1112 template <typename Case>
1113 static void setupCallExpectations(CompositionTest* test) {
1114 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001115 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001116 Case::Display::setupRECompositionCallExpectations(test);
1117 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1118 }
1119};
1120
Lloyd Pique66d68602019-02-13 14:23:31 -08001121struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001122 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001123 const auto outputLayer =
1124 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001125 LOG_FATAL_IF(!outputLayer);
1126 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001127 }
1128
1129 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001130 static void setupCallExpectations(CompositionTest* test) {
1131 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1132 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1133 Case::Display::setupRECompositionCallExpectations(test);
1134 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1135 }
1136
1137 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001138 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1139
1140 template <typename Case>
1141 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1142};
1143
Lloyd Pique4fe29402019-08-12 16:51:24 -07001144struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1145 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1146 test->mFlinger.mutableDebugDisableHWC() = true;
1147 }
1148
1149 template <typename Case>
1150 static void setupCallExpectations(CompositionTest* test) {
1151 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1152 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1153 Case::Display::setupRECompositionCallExpectations(test);
1154 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1155 }
1156
1157 template <typename Case>
1158 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1159
1160 template <typename Case>
1161 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1162};
1163
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001164struct EmptyScreenshotResultVariant {
1165 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1166
1167 template <typename Case>
1168 static void setupCallExpectations(CompositionTest*) {}
1169};
1170
1171struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1172 using Base = EmptyScreenshotResultVariant;
1173
1174 template <typename Case>
1175 static void setupCallExpectations(CompositionTest* test) {
1176 Base::template setupCallExpectations<Case>(test);
1177 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1178 }
1179};
1180
1181/* ------------------------------------------------------------------------
1182 * Composition test case, containing all the variants being tested
1183 */
1184
1185template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1186 typename CompositionResultCase>
1187struct CompositionCase {
1188 using ThisCase =
1189 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1190 using Display = DisplayCase;
1191 using Layer = LayerCase;
1192 using CompositionType = CompositionTypeCase;
1193 using CompositionResult = CompositionResultCase;
1194
1195 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001196 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001197 Display::setupPreconditions(test);
1198
1199 auto layer = Layer::createLayer(test);
1200 Layer::injectLayer(test, layer);
1201 CompositionResult::setupLayerState(test, layer);
1202 }
1203
1204 static void setupForDirtyGeometry(CompositionTest* test) {
1205 setupCommon(test);
1206
1207 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1208 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1209 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1210 CompositionResult::template setupCallExpectations<ThisCase>(test);
1211 }
1212
1213 static void setupForDirtyFrame(CompositionTest* test) {
1214 setupCommon(test);
1215
1216 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1217 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1218 CompositionResult::template setupCallExpectations<ThisCase>(test);
1219 }
1220
1221 static void setupForScreenCapture(CompositionTest* test) {
1222 setupCommon(test);
1223
1224 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1225 CompositionResult::template setupCallExpectations<ThisCase>(test);
1226 }
1227
1228 static void cleanup(CompositionTest* test) {
1229 Layer::cleanupInjectedLayers(test);
1230
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001231 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1232 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1233 ->mutableLayers()
1234 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001235 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001236 }
1237};
1238
1239/* ------------------------------------------------------------------------
1240 * Composition cases to test
1241 */
1242
1243TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1244 displayRefreshCompositionDirtyGeometry<
1245 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1246 NoCompositionResultVariant>>();
1247}
1248
1249TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1250 displayRefreshCompositionDirtyFrame<
1251 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1252 NoCompositionResultVariant>>();
1253}
1254
1255TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1256 captureScreenComposition<
1257 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1258 EmptyScreenshotResultVariant>>();
1259}
1260
1261/* ------------------------------------------------------------------------
1262 * Simple buffer layers
1263 */
1264
1265TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001266 displayRefreshCompositionDirtyGeometry<CompositionCase<
1267 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1268 KeepCompositionTypeVariant<
1269 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1270 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001271}
1272
1273TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001274 displayRefreshCompositionDirtyFrame<CompositionCase<
1275 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1276 KeepCompositionTypeVariant<
1277 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1278 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001279}
1280
1281TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001282 displayRefreshCompositionDirtyFrame<CompositionCase<
1283 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1284 ChangeCompositionTypeVariant<
1285 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1286 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1287 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001288}
1289
1290TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1291 captureScreenComposition<
1292 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1293 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1294}
1295
1296/* ------------------------------------------------------------------------
1297 * Single-color layers
1298 */
1299
Vishnu Nairfa247b12020-02-11 08:58:26 -08001300TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001301 displayRefreshCompositionDirtyGeometry<CompositionCase<
1302 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1303 KeepCompositionTypeVariant<
1304 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1305 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001306}
1307
Vishnu Nairfa247b12020-02-11 08:58:26 -08001308TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001309 displayRefreshCompositionDirtyFrame<CompositionCase<
1310 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1311 KeepCompositionTypeVariant<
1312 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1313 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001314}
1315
Vishnu Nairfa247b12020-02-11 08:58:26 -08001316TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001317 displayRefreshCompositionDirtyFrame<CompositionCase<
1318 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1319 ChangeCompositionTypeVariant<
1320 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1321 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1322 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001323}
1324
Vishnu Nairfa247b12020-02-11 08:58:26 -08001325TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001326 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001327 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001328 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1329}
1330
1331/* ------------------------------------------------------------------------
1332 * Layers with sideband buffers
1333 */
1334
1335TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001336 displayRefreshCompositionDirtyGeometry<CompositionCase<
1337 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1338 KeepCompositionTypeVariant<
1339 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1340 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001341}
1342
1343TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001344 displayRefreshCompositionDirtyFrame<CompositionCase<
1345 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1346 KeepCompositionTypeVariant<
1347 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1348 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001349}
1350
1351TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001352 displayRefreshCompositionDirtyFrame<CompositionCase<
1353 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1354 ChangeCompositionTypeVariant<
1355 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1356 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1357 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001358}
1359
1360TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1361 captureScreenComposition<
1362 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1363 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1364}
1365
1366/* ------------------------------------------------------------------------
1367 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1368 */
1369
1370TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001371 displayRefreshCompositionDirtyGeometry<CompositionCase<
1372 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1373 KeepCompositionTypeVariant<
1374 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1375 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001376}
1377
1378TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001379 displayRefreshCompositionDirtyFrame<CompositionCase<
1380 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1381 KeepCompositionTypeVariant<
1382 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1383 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001384}
1385
1386TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001387 displayRefreshCompositionDirtyFrame<CompositionCase<
1388 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1389 ChangeCompositionTypeVariant<
1390 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1391 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1392 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001393}
1394
1395TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1396 captureScreenComposition<
1397 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1398 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1399}
1400
1401/* ------------------------------------------------------------------------
1402 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1403 */
1404
1405TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001406 displayRefreshCompositionDirtyGeometry<CompositionCase<
1407 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1408 KeepCompositionTypeVariant<
1409 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1410 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001411}
1412
1413TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001414 displayRefreshCompositionDirtyFrame<CompositionCase<
1415 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1416 KeepCompositionTypeVariant<
1417 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1418 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001419}
1420
1421TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1422 captureScreenComposition<
1423 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1424 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1425}
1426
1427/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001428 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1429 */
1430
1431TEST_F(CompositionTest,
1432 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001433 displayRefreshCompositionDirtyGeometry<CompositionCase<
1434 InsecureDisplaySetupVariant,
1435 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1436 ContainerLayerVariant<SecureLayerProperties>>,
1437 KeepCompositionTypeVariant<
1438 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1439 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001440}
1441
1442TEST_F(CompositionTest,
1443 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001444 displayRefreshCompositionDirtyFrame<CompositionCase<
1445 InsecureDisplaySetupVariant,
1446 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1447 ContainerLayerVariant<SecureLayerProperties>>,
1448 KeepCompositionTypeVariant<
1449 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1450 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001451}
1452
1453TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1454 captureScreenComposition<
1455 CompositionCase<InsecureDisplaySetupVariant,
1456 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1457 ContainerLayerVariant<SecureLayerProperties>>,
1458 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1459}
1460
1461/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001462 * Cursor layers
1463 */
1464
1465TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001466 displayRefreshCompositionDirtyGeometry<CompositionCase<
1467 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1468 KeepCompositionTypeVariant<
1469 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1470 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001471}
1472
1473TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001474 displayRefreshCompositionDirtyFrame<CompositionCase<
1475 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1476 KeepCompositionTypeVariant<
1477 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1478 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001479}
1480
1481TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001482 displayRefreshCompositionDirtyFrame<CompositionCase<
1483 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1484 ChangeCompositionTypeVariant<
1485 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1486 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1487 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001488}
1489
1490TEST_F(CompositionTest, captureScreenCursorLayer) {
1491 captureScreenComposition<
1492 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1493 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1494}
1495
1496/* ------------------------------------------------------------------------
1497 * Simple buffer layer on a display which is powered off.
1498 */
1499
1500TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001501 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001502 displayRefreshCompositionDirtyGeometry<CompositionCase<
1503 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001504 KeepCompositionTypeVariant<
1505 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001506 HwcCompositionResultVariant>>();
1507}
1508
1509TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001510 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001511 displayRefreshCompositionDirtyFrame<CompositionCase<
1512 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001513 KeepCompositionTypeVariant<
1514 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001515 HwcCompositionResultVariant>>();
1516}
1517
1518TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001519 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001520 displayRefreshCompositionDirtyFrame<CompositionCase<
1521 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001522 ChangeCompositionTypeVariant<
1523 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1524 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001525 RECompositionResultVariant>>();
1526}
1527
1528TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1529 captureScreenComposition<CompositionCase<
1530 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1531 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1532}
1533
Lloyd Pique4fe29402019-08-12 16:51:24 -07001534/* ------------------------------------------------------------------------
1535 * Client composition forced through debug/developer settings
1536 */
1537
1538TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001539 displayRefreshCompositionDirtyGeometry<CompositionCase<
1540 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1541 KeepCompositionTypeVariant<
1542 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1543 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001544}
1545
1546TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001547 displayRefreshCompositionDirtyFrame<CompositionCase<
1548 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1549 KeepCompositionTypeVariant<
1550 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1551 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001552}
1553
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001554} // namespace
1555} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001556
1557// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001558#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"