blob: a0812912d42919af8c5cbadfb8d5b06c612316a1 [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"
48#include "mock/MockMessageQueue.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080049#include "mock/MockTimeStats.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070050#include "mock/MockVsyncController.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070051#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070052
53namespace android {
54namespace {
55
Peiyong Line9d809e2020-04-14 13:10:48 -070056namespace hal = android::hardware::graphics::composer::hal;
57
Peiyong Lin65248e02020-04-18 21:15:07 -070058using hal::Error;
59using hal::IComposer;
60using hal::IComposerClient;
61using hal::PowerMode;
62using hal::Transform;
63
Lloyd Piqued6b579f2018-04-06 15:29:10 -070064using testing::_;
David Sodman15094112018-10-11 09:39:37 -070065using testing::AtLeast;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070066using testing::DoAll;
67using testing::IsNull;
68using testing::Mock;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070069using testing::Return;
70using testing::ReturnRef;
71using testing::SetArgPointee;
72
Lloyd Piqued6b579f2018-04-06 15:29:10 -070073using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
74using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
75
Peiyong Line9d809e2020-04-14 13:10:48 -070076constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
77constexpr hal::HWLayerId HWC_LAYER = 5000;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070078constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
79
Dominik Laskowskif1833852021-03-23 15:06:50 -070080constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
Lloyd Piqued6b579f2018-04-06 15:29:10 -070081constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
82constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
83
Lloyd Piqued6b579f2018-04-06 15:29:10 -070084constexpr int DEFAULT_TEXTURE_ID = 6000;
Dominik Laskowski29fa1462021-04-27 15:51:50 -070085constexpr ui::LayerStack LAYER_STACK{7000u};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070086
87constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
88
89constexpr int DEFAULT_SIDEBAND_STREAM = 51;
90
91class CompositionTest : public testing::Test {
92public:
93 CompositionTest() {
94 const ::testing::TestInfo* const test_info =
95 ::testing::UnitTest::GetInstance()->current_test_info();
96 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
97
Lloyd Piqued6b579f2018-04-06 15:29:10 -070098 mFlinger.mutableEventQueue().reset(mMessageQueue);
Ana Krulecafb45842019-02-13 13:33:03 -080099 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700100
Alec Mourif6fd29e2018-11-17 04:56:41 +0000101 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
102 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
103 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
104 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700105
106 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800107 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800108
109 mComposer = new Hwc2::mock::Composer();
110 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Garfield Tan9c9c1912021-07-19 12:02:16 -0700111
112 mFlinger.mutableMaxRenderTargetSize() = 16384;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700113 }
114
115 ~CompositionTest() {
116 const ::testing::TestInfo* const test_info =
117 ::testing::UnitTest::GetInstance()->current_test_info();
118 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
119 }
120
Ana Krulecafb45842019-02-13 13:33:03 -0800121 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700122 auto eventThread = std::make_unique<mock::EventThread>();
123 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800124
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700125 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700126 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abraham62f216c2020-10-13 19:07:23 -0700127 .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0,
128 ResyncCallback())));
Dominik Laskowski98041832019-08-01 18:35:59 -0700129
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700130 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700131 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abraham62f216c2020-10-13 19:07:23 -0700132 .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0,
133 ResyncCallback())));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700134
Ady Abraham8cb21882020-08-26 18:22:05 -0700135 auto vsyncController = std::make_unique<mock::VsyncController>();
136 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700137
Ady Abraham8cb21882020-08-26 18:22:05 -0700138 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
139 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100140 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700141 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700142
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700143 constexpr ISchedulerCallback* kCallback = nullptr;
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700144 constexpr bool kHasMultipleConfigs = true;
Ady Abraham8cb21882020-08-26 18:22:05 -0700145 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
146 std::move(eventThread), std::move(sfEventThread), kCallback,
147 kHasMultipleConfigs);
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700148
149 // Layer history should be created if there are multiple configs.
150 ASSERT_TRUE(mFlinger.scheduler()->hasLayerHistory());
Ana Krulecafb45842019-02-13 13:33:03 -0800151 }
152
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700153 void setupForceGeometryDirty() {
154 // TODO: This requires the visible region and other related
155 // state to be set, and is problematic for BufferLayers since they are
156 // not visible without a buffer (and setting up a buffer looks like a
157 // pain)
158 // mFlinger.mutableVisibleRegionsDirty() = true;
159
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700160 mFlinger.mutableGeometryDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700161 }
162
163 template <typename Case>
164 void displayRefreshCompositionDirtyGeometry();
165
166 template <typename Case>
167 void displayRefreshCompositionDirtyFrame();
168
169 template <typename Case>
170 void captureScreenComposition();
171
Peiyong Line9d809e2020-04-14 13:10:48 -0700172 std::unordered_set<hal::Capability> mDefaultCapabilities = {hal::Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700173
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800174 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700175 TestableSurfaceFlinger mFlinger;
176 sp<DisplayDevice> mDisplay;
177 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700178 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
179 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700180 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Garfield Tande619fa2020-10-02 17:13:53 -0700181 std::vector<sp<Layer>> mAuxiliaryLayers;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700182
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800183 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
184 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
185
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700186 Hwc2::mock::Composer* mComposer = nullptr;
187 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800188 mock::TimeStats* mTimeStats = new mock::TimeStats();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700189 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
Lloyd Pique9370a482019-10-03 17:58:30 -0700190 Hwc2::mock::PowerAdvisor mPowerAdvisor;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700191
192 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
193
Alec Mouria90a5702021-04-16 16:36:21 +0000194 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700195};
196
197template <typename LayerCase>
198void CompositionTest::displayRefreshCompositionDirtyGeometry() {
199 setupForceGeometryDirty();
200 LayerCase::setupForDirtyGeometry(this);
201
202 // --------------------------------------------------------------------
203 // Invocation
204
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700205 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700206
207 LayerCase::cleanup(this);
208}
209
210template <typename LayerCase>
211void CompositionTest::displayRefreshCompositionDirtyFrame() {
212 LayerCase::setupForDirtyFrame(this);
213
214 // --------------------------------------------------------------------
215 // Invocation
216
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700217 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700218
219 LayerCase::cleanup(this);
220}
221
222template <typename LayerCase>
223void CompositionTest::captureScreenComposition() {
224 LayerCase::setupForScreenCapture(this);
225
226 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700227 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700228 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700229
Marin Shalamanov1c434292020-06-12 01:47:29 +0200230 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
231 ui::Dataspace::V0_SRGB, ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700232
233 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700234 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
235 CaptureArgs::UNSET_UID, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700236 };
237
238 // TODO: Eliminate expensive/real allocation if possible.
239 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
240 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Alec Mouria90a5702021-04-16 16:36:21 +0000241 mCaptureScreenBuffer = std::make_shared<
242 renderengine::ExternalTexture>(new GraphicBuffer(renderArea->getReqWidth(),
243 renderArea->getReqHeight(),
244 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage,
245 "screenshot"),
246 *mRenderEngine, true);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700247
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700248 status_t result =
Alec Mouria90a5702021-04-16 16:36:21 +0000249 mFlinger.renderScreenImplLocked(*renderArea, traverseLayers, mCaptureScreenBuffer,
Ady Abraham99599942021-01-27 20:27:23 -0800250 forSystem, regionSampling);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700251 EXPECT_EQ(NO_ERROR, result);
252
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,
347 const std::vector<const renderengine::LayerSettings*>&,
348 const std::shared_ptr<renderengine::ExternalTexture>&,
349 const bool, base::unique_fd &&)
350 -> 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,
373 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC))
374 .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,
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800387 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_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,
398 const std::vector<const renderengine::LayerSettings*>&,
399 const std::shared_ptr<renderengine::ExternalTexture>&,
400 const bool, base::unique_fd &&)
401 -> 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
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700532 status_t err =
533 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
534 LayerProperties::FORMAT);
535 ASSERT_EQ(NO_ERROR, err);
536 Mock::VerifyAndClear(test->mRenderEngine);
537
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700538 EXPECT_CALL(*test->mMessageQueue, scheduleCommit()).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700539 enqueueBuffer(test, layer);
Dominik Laskowskidd4ef272020-04-23 14:02:12 -0700540 Mock::VerifyAndClearExpectations(test->mMessageQueue);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700541
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700542 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700543 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700544 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700545 }
546
547 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
548 setupLatchedBuffer(test, layer);
549 }
550
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700551 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800552 if (!test->mDisplayOff) {
553 // TODO: Coverage of other values
554 EXPECT_CALL(*test->mComposer,
555 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
556 .Times(1);
557 // TODO: Coverage of other values for origin
558 EXPECT_CALL(*test->mComposer,
559 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
560 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
561 LayerProperties::HEIGHT})))
562 .Times(1);
563 EXPECT_CALL(*test->mComposer,
564 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
565 .Times(1);
566 // TODO: Coverage of other values
567 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700568
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800569 // These expectations retire on saturation as the code path these
570 // expectations are for appears to make an extra call to them.
571 // TODO: Investigate this extra call
572 EXPECT_CALL(*test->mComposer,
573 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
574 .Times(AtLeast(1))
575 .RetiresOnSaturation();
576 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700577 }
578
579 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800580 if (!test->mDisplayOff) {
581 EXPECT_CALL(*test->mComposer,
582 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
583 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
584 LayerProperties::HEIGHT})))
585 .Times(1);
586 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700587 }
588
589 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800590 if (!test->mDisplayOff) {
591 EXPECT_CALL(*test->mComposer,
592 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
593 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
594 .Times(1);
595 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700596 }
597
598 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800599 if (!test->mDisplayOff) {
600 EXPECT_CALL(*test->mComposer,
601 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
602 std::vector<IComposerClient::Rect>(
603 {IComposerClient::Rect(
604 {0, 0, LayerProperties::WIDTH,
605 LayerProperties::HEIGHT})})))
606 .Times(1);
607 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700608 }
609
610 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800611 if (!test->mDisplayOff) {
612 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
613 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700614
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800615 // TODO: use COLOR
616 EXPECT_CALL(*test->mComposer,
617 setLayerColor(HWC_DISPLAY, HWC_LAYER,
618 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
619 .Times(1);
620 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700621 }
622
623 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800624 if (!test->mDisplayOff) {
625 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
626 .Times(1);
627 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
628 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700629 }
630
631 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000632 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700633 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
634 const std::vector<const renderengine::LayerSettings*>& layerSettings,
635 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
636 base::unique_fd &&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000637 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
638 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
639 displaySettings.physicalDisplay);
640 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
641 displaySettings.clip);
642 // screen capture adds an additional color layer as an alpha
643 // prefill, so gtet the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700644 std::future<renderengine::RenderEngineResult> resultFuture =
645 futureOf<renderengine::RenderEngineResult>(
646 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800647 if (layerSettings.empty()) {
648 ADD_FAILURE() << "layerSettings was not expected to be empty in "
649 "setupREBufferCompositionCommonCallExpectations "
650 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700651 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800652 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800653 const renderengine::LayerSettings* layer = layerSettings.back();
654 EXPECT_THAT(layer->source.buffer.buffer, Not(IsNull()));
655 EXPECT_THAT(layer->source.buffer.fence, Not(IsNull()));
656 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer->source.buffer.textureName);
657 EXPECT_EQ(false, layer->source.buffer.isY410BT2020);
658 EXPECT_EQ(true, layer->source.buffer.usePremultipliedAlpha);
659 EXPECT_EQ(false, layer->source.buffer.isOpaque);
660 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
661 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
662 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700663 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000664 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700665 }
666
667 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
668 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700669 }
670
671 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
672 setupREBufferCompositionCallExpectations(test);
673 }
674
675 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
676 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
677 }
678
679 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
680 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
681 }
682
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700683 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000684 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700685 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
686 const std::vector<const renderengine::LayerSettings*>& layerSettings,
687 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
688 base::unique_fd &&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000689 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
690 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
691 displaySettings.physicalDisplay);
692 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
693 displaySettings.clip);
694 // screen capture adds an additional color layer as an alpha
695 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700696 std::future<renderengine::RenderEngineResult> resultFuture =
697 futureOf<renderengine::RenderEngineResult>(
698 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800699 if (layerSettings.empty()) {
700 ADD_FAILURE()
701 << "layerSettings was not expected to be empty in "
702 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700703 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800704 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800705 const renderengine::LayerSettings* layer = layerSettings.back();
706 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000707 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
708 LayerProperties::COLOR[2]),
Vishnu Nair9b079a22020-01-21 14:36:08 -0800709 layer->source.solidColor);
710 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
711 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
712 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700713 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000714 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700715 }
716
717 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
718 setupREColorCompositionCallExpectations(test);
719 }
720};
721
722struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
723
Vishnu Nairfa247b12020-02-11 08:58:26 -0800724struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800725 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
726};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700727
728struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
729 using Base = BaseLayerProperties<SidebandLayerProperties>;
730 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
731
732 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
733 sp<NativeHandle> stream =
734 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
735 false);
736 test->mFlinger.setLayerSidebandStream(layer, stream);
737 }
738
739 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
740 EXPECT_CALL(*test->mComposer,
741 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
742 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
743 .Times(1);
744 }
745
746 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
747 EXPECT_CALL(*test->mComposer,
748 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
749 reinterpret_cast<native_handle_t*>(
750 DEFAULT_SIDEBAND_STREAM)))
751 .WillOnce(Return(Error::NONE));
752
753 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
754 }
755
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000756 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700757};
758
Garfield Tande619fa2020-10-02 17:13:53 -0700759template <typename LayerProperties>
760struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
761 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700762
763 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000764 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700765 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
766 const std::vector<const renderengine::LayerSettings*>& layerSettings,
767 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
768 base::unique_fd &&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000769 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
770 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
771 displaySettings.physicalDisplay);
772 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
773 displaySettings.clip);
774 // screen capture adds an additional color layer as an alpha
775 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700776 std::future<renderengine::RenderEngineResult> resultFuture =
777 futureOf<renderengine::RenderEngineResult>(
778 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800779 if (layerSettings.empty()) {
780 ADD_FAILURE() << "layerSettings was not expected to be empty in "
781 "setupInsecureREBufferCompositionCommonCallExpectations "
782 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700783 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800784 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800785 const renderengine::LayerSettings* layer = layerSettings.back();
786 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
787 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer->source.solidColor);
788 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
789 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
790 EXPECT_EQ(1.0f, layer->alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700791 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000792 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700793 }
794
795 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
796 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700797 }
798
799 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
800 setupInsecureREBufferCompositionCommonCallExpectations(test);
801 }
802};
803
Garfield Tande619fa2020-10-02 17:13:53 -0700804struct ParentSecureLayerProperties
805 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
806
807struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
808 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
809};
810
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700811struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
812 using Base = BaseLayerProperties<CursorLayerProperties>;
813
814 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
815 Base::setupLayerState(test, layer);
816 test->mFlinger.setLayerPotentialCursor(layer, true);
817 }
818};
819
820struct NoLayerVariant {
821 using FlingerLayerType = sp<BufferQueueLayer>;
822
823 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
824 static void injectLayer(CompositionTest*, FlingerLayerType) {}
825 static void cleanupInjectedLayers(CompositionTest*) {}
826
827 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
828 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
829};
830
831template <typename LayerProperties>
832struct BaseLayerVariant {
833 template <typename L, typename F>
834 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowskidd4ef272020-04-23 14:02:12 -0700835 EXPECT_CALL(*test->mMessageQueue, postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700836
837 sp<L> layer = factory();
838
Dominik Laskowski49cea512019-11-12 14:13:23 -0800839 // Layer should be registered with scheduler.
840 EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize());
841
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700842 Mock::VerifyAndClear(test->mComposer);
843 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowskidd4ef272020-04-23 14:02:12 -0700844 Mock::VerifyAndClearExpectations(test->mMessageQueue);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700845
Garfield Tande619fa2020-10-02 17:13:53 -0700846 initLayerDrawingStateAndComputeBounds(test, layer);
847
848 return layer;
849 }
850
851 template <typename L>
852 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700853 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700854 layerDrawingState.layerStack = LAYER_STACK;
chaviw766c9c52021-02-10 17:36:47 -0800855 layerDrawingState.width = 100;
856 layerDrawingState.height = 100;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700857 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
858 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700859 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700860 }
861
862 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
863 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
864 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
865
Lloyd Piquede196652020-01-22 17:29:58 -0800866 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
867 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700868 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
869 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700870
871 Mock::VerifyAndClear(test->mComposer);
872
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700873 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
874 }
875
876 static void cleanupInjectedLayers(CompositionTest* test) {
877 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
878 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800879
Lloyd Pique01c77c12019-04-17 12:48:32 -0700880 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700881 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800882
883 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700884 test->mFlinger.commit();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800885 EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700886 }
887};
888
889template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800890struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700891 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800892 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700893
894 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800895 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
896 return new EffectLayer(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700897 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800898 LayerProperties::WIDTH, LayerProperties::HEIGHT,
899 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::WIDTH, LayerProperties::HEIGHT,
938 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700939 args.textureName = test->mFlinger.mutableTexturePool().back();
940 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700941 });
942
943 LayerProperties::setupLayerState(test, layer);
944
945 return layer;
946 }
947
948 static void cleanupInjectedLayers(CompositionTest* test) {
Dominik Laskowskidd4ef272020-04-23 14:02:12 -0700949 EXPECT_CALL(*test->mMessageQueue, postMessage(_)).Times(1);
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",
987 LayerProperties::WIDTH, LayerProperties::HEIGHT,
988 LayerProperties::LAYER_FLAGS, LayerMetadata());
989 FlingerLayerType layer = new ContainerLayer(args);
990 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
991 return layer;
992 }
993};
994
995template <typename LayerVariant, typename ParentLayerVariant>
996struct ChildLayerVariant : public LayerVariant {
997 using Base = LayerVariant;
998 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
999 using ParentBase = ParentLayerVariant;
1000
1001 static FlingerLayerType createLayer(CompositionTest* test) {
1002 // Need to create child layer first. Otherwise layer history size will be 2.
1003 FlingerLayerType layer = Base::createLayer(test);
1004
1005 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
1006 parentLayer->addChild(layer);
1007 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
1008
1009 test->mAuxiliaryLayers.push_back(parentLayer);
1010
1011 return layer;
1012 }
1013
1014 static void cleanupInjectedLayers(CompositionTest* test) {
1015 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
1016 // following call.
1017 test->mAuxiliaryLayers.clear();
1018
1019 Base::cleanupInjectedLayers(test);
1020 }
1021};
1022
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001023/* ------------------------------------------------------------------------
1024 * Variants to control how the composition type is changed
1025 */
1026
1027struct NoCompositionTypeVariant {
1028 static void setupHwcSetCallExpectations(CompositionTest*) {}
1029
1030 static void setupHwcGetCallExpectations(CompositionTest* test) {
1031 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1032 }
1033};
1034
1035template <IComposerClient::Composition CompositionType>
1036struct KeepCompositionTypeVariant {
Peiyong Line9d809e2020-04-14 13:10:48 -07001037 static constexpr hal::Composition TYPE = 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
1052template <IComposerClient::Composition InitialCompositionType,
1053 IComposerClient::Composition FinalCompositionType>
1054struct ChangeCompositionTypeVariant {
Peiyong Line9d809e2020-04-14 13:10:48 -07001055 static constexpr hal::Composition TYPE = FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001056
1057 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001058 if (!test->mDisplayOff) {
1059 EXPECT_CALL(*test->mComposer,
1060 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1061 .Times(1);
1062 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001063 }
1064
1065 static void setupHwcGetCallExpectations(CompositionTest* test) {
1066 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1067 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1068 static_cast<Hwc2::Layer>(HWC_LAYER)}),
1069 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
1070 FinalCompositionType}),
1071 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) {
1264 displayRefreshCompositionDirtyGeometry<
1265 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1266 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1267 HwcCompositionResultVariant>>();
1268}
1269
1270TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1271 displayRefreshCompositionDirtyFrame<
1272 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1273 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1274 HwcCompositionResultVariant>>();
1275}
1276
1277TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1278 displayRefreshCompositionDirtyFrame<
1279 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1280 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1281 IComposerClient::Composition::CLIENT>,
1282 RECompositionResultVariant>>();
1283}
1284
1285TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1286 captureScreenComposition<
1287 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1288 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1289}
1290
1291/* ------------------------------------------------------------------------
1292 * Single-color layers
1293 */
1294
Vishnu Nairfa247b12020-02-11 08:58:26 -08001295TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001296 displayRefreshCompositionDirtyGeometry<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001297 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001298 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1299 HwcCompositionResultVariant>>();
1300}
1301
Vishnu Nairfa247b12020-02-11 08:58:26 -08001302TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001303 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001304 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001305 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1306 HwcCompositionResultVariant>>();
1307}
1308
Vishnu Nairfa247b12020-02-11 08:58:26 -08001309TEST_F(CompositionTest, REComposedEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001310 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001311 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001312 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1313 IComposerClient::Composition::CLIENT>,
1314 RECompositionResultVariant>>();
1315}
1316
Vishnu Nairfa247b12020-02-11 08:58:26 -08001317TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001318 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001319 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001320 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1321}
1322
1323/* ------------------------------------------------------------------------
1324 * Layers with sideband buffers
1325 */
1326
1327TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1328 displayRefreshCompositionDirtyGeometry<
1329 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1330 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1331 HwcCompositionResultVariant>>();
1332}
1333
1334TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1335 displayRefreshCompositionDirtyFrame<
1336 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1337 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1338 HwcCompositionResultVariant>>();
1339}
1340
1341TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1342 displayRefreshCompositionDirtyFrame<
1343 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1344 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1345 IComposerClient::Composition::CLIENT>,
1346 RECompositionResultVariant>>();
1347}
1348
1349TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1350 captureScreenComposition<
1351 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1352 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1353}
1354
1355/* ------------------------------------------------------------------------
1356 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1357 */
1358
1359TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1360 displayRefreshCompositionDirtyGeometry<
1361 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1362 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1363 HwcCompositionResultVariant>>();
1364}
1365
1366TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1367 displayRefreshCompositionDirtyFrame<
1368 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1369 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1370 HwcCompositionResultVariant>>();
1371}
1372
1373TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1374 displayRefreshCompositionDirtyFrame<
1375 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1376 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1377 IComposerClient::Composition::CLIENT>,
1378 RECompositionResultVariant>>();
1379}
1380
1381TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1382 captureScreenComposition<
1383 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1384 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1385}
1386
1387/* ------------------------------------------------------------------------
1388 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1389 */
1390
1391TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1392 displayRefreshCompositionDirtyGeometry<
1393 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1394 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1395 ForcedClientCompositionResultVariant>>();
1396}
1397
1398TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1399 displayRefreshCompositionDirtyFrame<
1400 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1401 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1402 ForcedClientCompositionResultVariant>>();
1403}
1404
1405TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1406 captureScreenComposition<
1407 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1408 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1409}
1410
1411/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001412 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1413 */
1414
1415TEST_F(CompositionTest,
1416 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
1417 displayRefreshCompositionDirtyGeometry<
1418 CompositionCase<InsecureDisplaySetupVariant,
1419 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1420 ContainerLayerVariant<SecureLayerProperties>>,
1421 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1422 ForcedClientCompositionResultVariant>>();
1423}
1424
1425TEST_F(CompositionTest,
1426 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
1427 displayRefreshCompositionDirtyFrame<
1428 CompositionCase<InsecureDisplaySetupVariant,
1429 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1430 ContainerLayerVariant<SecureLayerProperties>>,
1431 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1432 ForcedClientCompositionResultVariant>>();
1433}
1434
1435TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1436 captureScreenComposition<
1437 CompositionCase<InsecureDisplaySetupVariant,
1438 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1439 ContainerLayerVariant<SecureLayerProperties>>,
1440 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1441}
1442
1443/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001444 * Cursor layers
1445 */
1446
1447TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1448 displayRefreshCompositionDirtyGeometry<
1449 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1450 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1451 HwcCompositionResultVariant>>();
1452}
1453
1454TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1455 displayRefreshCompositionDirtyFrame<
1456 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1457 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1458 HwcCompositionResultVariant>>();
1459}
1460
1461TEST_F(CompositionTest, REComposedCursorLayer) {
1462 displayRefreshCompositionDirtyFrame<
1463 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1464 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1465 IComposerClient::Composition::CLIENT>,
1466 RECompositionResultVariant>>();
1467}
1468
1469TEST_F(CompositionTest, captureScreenCursorLayer) {
1470 captureScreenComposition<
1471 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1472 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1473}
1474
1475/* ------------------------------------------------------------------------
1476 * Simple buffer layer on a display which is powered off.
1477 */
1478
1479TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001480 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001481 displayRefreshCompositionDirtyGeometry<CompositionCase<
1482 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1483 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1484 HwcCompositionResultVariant>>();
1485}
1486
1487TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001488 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001489 displayRefreshCompositionDirtyFrame<CompositionCase<
1490 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1491 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1492 HwcCompositionResultVariant>>();
1493}
1494
1495TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001496 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001497 displayRefreshCompositionDirtyFrame<CompositionCase<
1498 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1499 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1500 IComposerClient::Composition::CLIENT>,
1501 RECompositionResultVariant>>();
1502}
1503
1504TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1505 captureScreenComposition<CompositionCase<
1506 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1507 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1508}
1509
Lloyd Pique4fe29402019-08-12 16:51:24 -07001510/* ------------------------------------------------------------------------
1511 * Client composition forced through debug/developer settings
1512 */
1513
1514TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
1515 displayRefreshCompositionDirtyGeometry<
1516 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1517 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1518 ForcedClientCompositionViaDebugOptionResultVariant>>();
1519}
1520
1521TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
1522 displayRefreshCompositionDirtyFrame<
1523 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1524 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1525 ForcedClientCompositionViaDebugOptionResultVariant>>();
1526}
1527
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001528} // namespace
1529} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001530
1531// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001532#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"