blob: 5135ff952fa02a09cc5b25d13cfd413a3ed41ceb [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
205 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
206 mFlinger.onMessageReceived(MessageQueue::REFRESH);
207
208 LayerCase::cleanup(this);
209}
210
211template <typename LayerCase>
212void CompositionTest::displayRefreshCompositionDirtyFrame() {
213 LayerCase::setupForDirtyFrame(this);
214
215 // --------------------------------------------------------------------
216 // Invocation
217
218 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
219 mFlinger.onMessageReceived(MessageQueue::REFRESH);
220
221 LayerCase::cleanup(this);
222}
223
224template <typename LayerCase>
225void CompositionTest::captureScreenComposition() {
226 LayerCase::setupForScreenCapture(this);
227
228 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700229 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700230 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700231
Marin Shalamanov1c434292020-06-12 01:47:29 +0200232 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
233 ui::Dataspace::V0_SRGB, ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700234
235 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700236 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
237 CaptureArgs::UNSET_UID, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700238 };
239
240 // TODO: Eliminate expensive/real allocation if possible.
241 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
242 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Alec Mouria90a5702021-04-16 16:36:21 +0000243 mCaptureScreenBuffer = std::make_shared<
244 renderengine::ExternalTexture>(new GraphicBuffer(renderArea->getReqWidth(),
245 renderArea->getReqHeight(),
246 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage,
247 "screenshot"),
248 *mRenderEngine, true);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700249
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700250 status_t result =
Alec Mouria90a5702021-04-16 16:36:21 +0000251 mFlinger.renderScreenImplLocked(*renderArea, traverseLayers, mCaptureScreenBuffer,
Ady Abraham99599942021-01-27 20:27:23 -0800252 forSystem, regionSampling);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700253 EXPECT_EQ(NO_ERROR, result);
254
255 LayerCase::cleanup(this);
256}
257
Sally Qi4cabdd02021-08-05 16:45:57 -0700258template <class T>
259std::future<T> futureOf(T obj) {
260 std::promise<T> resultPromise;
261 std::future<T> resultFuture = resultPromise.get_future();
262 resultPromise.set_value(std::move(obj));
263 return resultFuture;
264}
265
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700266/* ------------------------------------------------------------------------
267 * Variants for each display configuration which can be tested
268 */
269
270template <typename Derived>
271struct BaseDisplayVariant {
272 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700273 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700274
275 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700276 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700277 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700278
Peiyong Line9d809e2020-04-14 13:10:48 -0700279 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700280 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700281 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700282 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800283 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700284
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800285 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
286 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
287 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
288 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
289 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
290 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
291 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique9370a482019-10-03 17:58:30 -0700292
293 const ::testing::TestInfo* const test_info =
294 ::testing::UnitTest::GetInstance()->current_test_info();
295
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800296 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
297 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800298 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
299 .setIsSecure(Derived::IS_SECURE)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800300 .setPowerAdvisor(&test->mPowerAdvisor)
301 .setName(std::string("Injected display for ") +
302 test_info->test_case_name() + "." + test_info->name())
303 .build();
Lloyd Pique9370a482019-10-03 17:58:30 -0700304
305 auto compositionDisplay =
306 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
307 ceDisplayArgs);
308
Marin Shalamanov700e6392020-02-12 20:22:26 +0100309 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100310 ui::DisplayConnectionType::Internal, HWC_DISPLAY,
Marin Shalamanov700e6392020-02-12 20:22:26 +0100311 true /* isPrimary */)
312 .setDisplaySurface(test->mDisplaySurface)
313 .setNativeWindow(test->mNativeWindow)
314 .setSecure(Derived::IS_SECURE)
315 .setPowerMode(Derived::INIT_POWER_MODE)
316 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800317 Mock::VerifyAndClear(test->mNativeWindow);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700318 test->mDisplay->setLayerStack(LAYER_STACK);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700319 }
320
321 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700322 static void setupPreconditionCallExpectations(CompositionTest* test) {
323 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
324 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
325 Return(Error::NONE)));
326 }
327
328 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700329 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
330 EXPECT_CALL(*test->mComposer,
331 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
332 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700333 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
334 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
335 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
336 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
337
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700338 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
339 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
340
341 Case::CompositionType::setupHwcSetCallExpectations(test);
342 Case::CompositionType::setupHwcGetCallExpectations(test);
343 }
344
345 template <typename Case>
346 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000347 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700348 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
349 const std::vector<const renderengine::LayerSettings*>&,
350 const std::shared_ptr<renderengine::ExternalTexture>&,
351 const bool, base::unique_fd &&)
352 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700353 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
354 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
355 displaySettings.physicalDisplay);
356 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
357 displaySettings.clip);
Sally Qi4cabdd02021-08-05 16:45:57 -0700358 return futureOf<renderengine::RenderEngineResult>(
359 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700360 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700361 }
362
363 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
364 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
365 }
366
367 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
368 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
369 }
370
371 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800372 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
373
Lloyd Pique542307f2018-10-19 13:24:08 -0700374 EXPECT_CALL(*test->mDisplaySurface,
375 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC))
376 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700377 }
378
Lloyd Pique66d68602019-02-13 14:23:31 -0800379 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
380 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
381 }
382
383 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
384 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1);
385 }
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,
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800389 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_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,
400 const std::vector<const renderengine::LayerSettings*>&,
401 const std::shared_ptr<renderengine::ExternalTexture>&,
402 const bool, base::unique_fd &&)
403 -> 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
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700534 status_t err =
535 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
536 LayerProperties::FORMAT);
537 ASSERT_EQ(NO_ERROR, err);
538 Mock::VerifyAndClear(test->mRenderEngine);
539
540 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
541 enqueueBuffer(test, layer);
Dominik Laskowskidd4ef272020-04-23 14:02:12 -0700542 Mock::VerifyAndClearExpectations(test->mMessageQueue);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700543
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700544 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700545 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700546 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700547 }
548
549 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
550 setupLatchedBuffer(test, layer);
551 }
552
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700553 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800554 if (!test->mDisplayOff) {
555 // TODO: Coverage of other values
556 EXPECT_CALL(*test->mComposer,
557 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
558 .Times(1);
559 // TODO: Coverage of other values for origin
560 EXPECT_CALL(*test->mComposer,
561 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
562 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
563 LayerProperties::HEIGHT})))
564 .Times(1);
565 EXPECT_CALL(*test->mComposer,
566 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
567 .Times(1);
568 // TODO: Coverage of other values
569 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700570
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800571 // These expectations retire on saturation as the code path these
572 // expectations are for appears to make an extra call to them.
573 // TODO: Investigate this extra call
574 EXPECT_CALL(*test->mComposer,
575 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
576 .Times(AtLeast(1))
577 .RetiresOnSaturation();
578 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700579 }
580
581 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800582 if (!test->mDisplayOff) {
583 EXPECT_CALL(*test->mComposer,
584 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
585 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
586 LayerProperties::HEIGHT})))
587 .Times(1);
588 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700589 }
590
591 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800592 if (!test->mDisplayOff) {
593 EXPECT_CALL(*test->mComposer,
594 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
595 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
596 .Times(1);
597 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700598 }
599
600 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800601 if (!test->mDisplayOff) {
602 EXPECT_CALL(*test->mComposer,
603 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
604 std::vector<IComposerClient::Rect>(
605 {IComposerClient::Rect(
606 {0, 0, LayerProperties::WIDTH,
607 LayerProperties::HEIGHT})})))
608 .Times(1);
609 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700610 }
611
612 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800613 if (!test->mDisplayOff) {
614 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
615 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700616
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800617 // TODO: use COLOR
618 EXPECT_CALL(*test->mComposer,
619 setLayerColor(HWC_DISPLAY, HWC_LAYER,
620 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
621 .Times(1);
622 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700623 }
624
625 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800626 if (!test->mDisplayOff) {
627 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
628 .Times(1);
629 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
630 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700631 }
632
633 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000634 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700635 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
636 const std::vector<const renderengine::LayerSettings*>& layerSettings,
637 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
638 base::unique_fd &&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000639 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
640 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
641 displaySettings.physicalDisplay);
642 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
643 displaySettings.clip);
644 // screen capture adds an additional color layer as an alpha
645 // prefill, so gtet the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700646 std::future<renderengine::RenderEngineResult> resultFuture =
647 futureOf<renderengine::RenderEngineResult>(
648 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800649 if (layerSettings.empty()) {
650 ADD_FAILURE() << "layerSettings was not expected to be empty in "
651 "setupREBufferCompositionCommonCallExpectations "
652 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700653 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800654 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800655 const renderengine::LayerSettings* layer = layerSettings.back();
656 EXPECT_THAT(layer->source.buffer.buffer, Not(IsNull()));
657 EXPECT_THAT(layer->source.buffer.fence, Not(IsNull()));
658 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer->source.buffer.textureName);
659 EXPECT_EQ(false, layer->source.buffer.isY410BT2020);
660 EXPECT_EQ(true, layer->source.buffer.usePremultipliedAlpha);
661 EXPECT_EQ(false, layer->source.buffer.isOpaque);
662 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
663 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
664 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700665 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000666 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700667 }
668
669 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
670 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700671 }
672
673 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
674 setupREBufferCompositionCallExpectations(test);
675 }
676
677 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
678 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
679 }
680
681 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
682 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
683 }
684
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700685 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000686 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700687 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
688 const std::vector<const renderengine::LayerSettings*>& layerSettings,
689 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
690 base::unique_fd &&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000691 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
692 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
693 displaySettings.physicalDisplay);
694 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
695 displaySettings.clip);
696 // screen capture adds an additional color layer as an alpha
697 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700698 std::future<renderengine::RenderEngineResult> resultFuture =
699 futureOf<renderengine::RenderEngineResult>(
700 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800701 if (layerSettings.empty()) {
702 ADD_FAILURE()
703 << "layerSettings was not expected to be empty in "
704 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700705 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800706 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800707 const renderengine::LayerSettings* layer = layerSettings.back();
708 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000709 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
710 LayerProperties::COLOR[2]),
Vishnu Nair9b079a22020-01-21 14:36:08 -0800711 layer->source.solidColor);
712 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
713 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
714 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700715 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000716 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700717 }
718
719 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
720 setupREColorCompositionCallExpectations(test);
721 }
722};
723
724struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
725
Vishnu Nairfa247b12020-02-11 08:58:26 -0800726struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800727 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
728};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700729
730struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
731 using Base = BaseLayerProperties<SidebandLayerProperties>;
732 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
733
734 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
735 sp<NativeHandle> stream =
736 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
737 false);
738 test->mFlinger.setLayerSidebandStream(layer, stream);
739 }
740
741 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
742 EXPECT_CALL(*test->mComposer,
743 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
744 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
745 .Times(1);
746 }
747
748 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
749 EXPECT_CALL(*test->mComposer,
750 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
751 reinterpret_cast<native_handle_t*>(
752 DEFAULT_SIDEBAND_STREAM)))
753 .WillOnce(Return(Error::NONE));
754
755 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
756 }
757
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000758 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700759};
760
Garfield Tande619fa2020-10-02 17:13:53 -0700761template <typename LayerProperties>
762struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
763 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700764
765 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000766 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700767 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
768 const std::vector<const renderengine::LayerSettings*>& layerSettings,
769 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
770 base::unique_fd &&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000771 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
772 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
773 displaySettings.physicalDisplay);
774 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
775 displaySettings.clip);
776 // screen capture adds an additional color layer as an alpha
777 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700778 std::future<renderengine::RenderEngineResult> resultFuture =
779 futureOf<renderengine::RenderEngineResult>(
780 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800781 if (layerSettings.empty()) {
782 ADD_FAILURE() << "layerSettings was not expected to be empty in "
783 "setupInsecureREBufferCompositionCommonCallExpectations "
784 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700785 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800786 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800787 const renderengine::LayerSettings* layer = layerSettings.back();
788 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
789 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer->source.solidColor);
790 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
791 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
792 EXPECT_EQ(1.0f, layer->alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700793 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000794 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700795 }
796
797 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
798 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700799 }
800
801 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
802 setupInsecureREBufferCompositionCommonCallExpectations(test);
803 }
804};
805
Garfield Tande619fa2020-10-02 17:13:53 -0700806struct ParentSecureLayerProperties
807 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
808
809struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
810 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
811};
812
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700813struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
814 using Base = BaseLayerProperties<CursorLayerProperties>;
815
816 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
817 Base::setupLayerState(test, layer);
818 test->mFlinger.setLayerPotentialCursor(layer, true);
819 }
820};
821
822struct NoLayerVariant {
823 using FlingerLayerType = sp<BufferQueueLayer>;
824
825 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
826 static void injectLayer(CompositionTest*, FlingerLayerType) {}
827 static void cleanupInjectedLayers(CompositionTest*) {}
828
829 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
830 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
831};
832
833template <typename LayerProperties>
834struct BaseLayerVariant {
835 template <typename L, typename F>
836 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowskidd4ef272020-04-23 14:02:12 -0700837 EXPECT_CALL(*test->mMessageQueue, postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700838
839 sp<L> layer = factory();
840
Dominik Laskowski49cea512019-11-12 14:13:23 -0800841 // Layer should be registered with scheduler.
842 EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize());
843
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700844 Mock::VerifyAndClear(test->mComposer);
845 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowskidd4ef272020-04-23 14:02:12 -0700846 Mock::VerifyAndClearExpectations(test->mMessageQueue);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700847
Garfield Tande619fa2020-10-02 17:13:53 -0700848 initLayerDrawingStateAndComputeBounds(test, layer);
849
850 return layer;
851 }
852
853 template <typename L>
854 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700855 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700856 layerDrawingState.layerStack = LAYER_STACK;
chaviw766c9c52021-02-10 17:36:47 -0800857 layerDrawingState.width = 100;
858 layerDrawingState.height = 100;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700859 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
860 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700861 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700862 }
863
864 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
865 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
866 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
867
Lloyd Piquede196652020-01-22 17:29:58 -0800868 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
869 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700870 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
871 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700872
873 Mock::VerifyAndClear(test->mComposer);
874
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700875 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
876 }
877
878 static void cleanupInjectedLayers(CompositionTest* test) {
879 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
880 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800881
Lloyd Pique01c77c12019-04-17 12:48:32 -0700882 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700883 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800884
885 // Layer should be unregistered with scheduler.
886 test->mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
887 EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700888 }
889};
890
891template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800892struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700893 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800894 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700895
896 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800897 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
898 return new EffectLayer(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700899 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800900 LayerProperties::WIDTH, LayerProperties::HEIGHT,
901 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::WIDTH, LayerProperties::HEIGHT,
940 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700941 args.textureName = test->mFlinger.mutableTexturePool().back();
942 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700943 });
944
945 LayerProperties::setupLayerState(test, layer);
946
947 return layer;
948 }
949
950 static void cleanupInjectedLayers(CompositionTest* test) {
Dominik Laskowskidd4ef272020-04-23 14:02:12 -0700951 EXPECT_CALL(*test->mMessageQueue, postMessage(_)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700952 Base::cleanupInjectedLayers(test);
953 }
954
955 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
956 LayerProperties::setupHwcSetGeometryCallExpectations(test);
957 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
958 }
959
960 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
961 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
962 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
963 }
964
965 static void setupRECompositionCallExpectations(CompositionTest* test) {
966 LayerProperties::setupREBufferCompositionCallExpectations(test);
967 }
968
969 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
970 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
971 }
972
973 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
974 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
975 }
976
977 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
978 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
979 }
980};
981
Garfield Tande619fa2020-10-02 17:13:53 -0700982template <typename LayerProperties>
983struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
984 using Base = BaseLayerVariant<LayerProperties>;
985 using FlingerLayerType = sp<ContainerLayer>;
986
987 static FlingerLayerType createLayer(CompositionTest* test) {
988 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
989 LayerProperties::WIDTH, LayerProperties::HEIGHT,
990 LayerProperties::LAYER_FLAGS, LayerMetadata());
991 FlingerLayerType layer = new ContainerLayer(args);
992 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
993 return layer;
994 }
995};
996
997template <typename LayerVariant, typename ParentLayerVariant>
998struct ChildLayerVariant : public LayerVariant {
999 using Base = LayerVariant;
1000 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
1001 using ParentBase = ParentLayerVariant;
1002
1003 static FlingerLayerType createLayer(CompositionTest* test) {
1004 // Need to create child layer first. Otherwise layer history size will be 2.
1005 FlingerLayerType layer = Base::createLayer(test);
1006
1007 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
1008 parentLayer->addChild(layer);
1009 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
1010
1011 test->mAuxiliaryLayers.push_back(parentLayer);
1012
1013 return layer;
1014 }
1015
1016 static void cleanupInjectedLayers(CompositionTest* test) {
1017 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
1018 // following call.
1019 test->mAuxiliaryLayers.clear();
1020
1021 Base::cleanupInjectedLayers(test);
1022 }
1023};
1024
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001025/* ------------------------------------------------------------------------
1026 * Variants to control how the composition type is changed
1027 */
1028
1029struct NoCompositionTypeVariant {
1030 static void setupHwcSetCallExpectations(CompositionTest*) {}
1031
1032 static void setupHwcGetCallExpectations(CompositionTest* test) {
1033 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1034 }
1035};
1036
1037template <IComposerClient::Composition CompositionType>
1038struct KeepCompositionTypeVariant {
Peiyong Line9d809e2020-04-14 13:10:48 -07001039 static constexpr hal::Composition TYPE = CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001040
1041 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001042 if (!test->mDisplayOff) {
1043 EXPECT_CALL(*test->mComposer,
1044 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1045 .Times(1);
1046 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001047 }
1048
1049 static void setupHwcGetCallExpectations(CompositionTest* test) {
1050 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1051 }
1052};
1053
1054template <IComposerClient::Composition InitialCompositionType,
1055 IComposerClient::Composition FinalCompositionType>
1056struct ChangeCompositionTypeVariant {
Peiyong Line9d809e2020-04-14 13:10:48 -07001057 static constexpr hal::Composition TYPE = FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001058
1059 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001060 if (!test->mDisplayOff) {
1061 EXPECT_CALL(*test->mComposer,
1062 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1063 .Times(1);
1064 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001065 }
1066
1067 static void setupHwcGetCallExpectations(CompositionTest* test) {
1068 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1069 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1070 static_cast<Hwc2::Layer>(HWC_LAYER)}),
1071 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
1072 FinalCompositionType}),
1073 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) {
1266 displayRefreshCompositionDirtyGeometry<
1267 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1268 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1269 HwcCompositionResultVariant>>();
1270}
1271
1272TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1273 displayRefreshCompositionDirtyFrame<
1274 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1275 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1276 HwcCompositionResultVariant>>();
1277}
1278
1279TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1280 displayRefreshCompositionDirtyFrame<
1281 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1282 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1283 IComposerClient::Composition::CLIENT>,
1284 RECompositionResultVariant>>();
1285}
1286
1287TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1288 captureScreenComposition<
1289 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1290 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1291}
1292
1293/* ------------------------------------------------------------------------
1294 * Single-color layers
1295 */
1296
Vishnu Nairfa247b12020-02-11 08:58:26 -08001297TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001298 displayRefreshCompositionDirtyGeometry<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001299 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001300 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1301 HwcCompositionResultVariant>>();
1302}
1303
Vishnu Nairfa247b12020-02-11 08:58:26 -08001304TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001305 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001306 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001307 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1308 HwcCompositionResultVariant>>();
1309}
1310
Vishnu Nairfa247b12020-02-11 08:58:26 -08001311TEST_F(CompositionTest, REComposedEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001312 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001313 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001314 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1315 IComposerClient::Composition::CLIENT>,
1316 RECompositionResultVariant>>();
1317}
1318
Vishnu Nairfa247b12020-02-11 08:58:26 -08001319TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001320 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001321 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001322 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1323}
1324
1325/* ------------------------------------------------------------------------
1326 * Layers with sideband buffers
1327 */
1328
1329TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1330 displayRefreshCompositionDirtyGeometry<
1331 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1332 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1333 HwcCompositionResultVariant>>();
1334}
1335
1336TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1337 displayRefreshCompositionDirtyFrame<
1338 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1339 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1340 HwcCompositionResultVariant>>();
1341}
1342
1343TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1344 displayRefreshCompositionDirtyFrame<
1345 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1346 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1347 IComposerClient::Composition::CLIENT>,
1348 RECompositionResultVariant>>();
1349}
1350
1351TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1352 captureScreenComposition<
1353 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1354 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1355}
1356
1357/* ------------------------------------------------------------------------
1358 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1359 */
1360
1361TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1362 displayRefreshCompositionDirtyGeometry<
1363 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1364 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1365 HwcCompositionResultVariant>>();
1366}
1367
1368TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1369 displayRefreshCompositionDirtyFrame<
1370 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1371 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1372 HwcCompositionResultVariant>>();
1373}
1374
1375TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1376 displayRefreshCompositionDirtyFrame<
1377 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1378 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1379 IComposerClient::Composition::CLIENT>,
1380 RECompositionResultVariant>>();
1381}
1382
1383TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1384 captureScreenComposition<
1385 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1386 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1387}
1388
1389/* ------------------------------------------------------------------------
1390 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1391 */
1392
1393TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1394 displayRefreshCompositionDirtyGeometry<
1395 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1396 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1397 ForcedClientCompositionResultVariant>>();
1398}
1399
1400TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1401 displayRefreshCompositionDirtyFrame<
1402 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1403 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1404 ForcedClientCompositionResultVariant>>();
1405}
1406
1407TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1408 captureScreenComposition<
1409 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1410 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1411}
1412
1413/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001414 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1415 */
1416
1417TEST_F(CompositionTest,
1418 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
1419 displayRefreshCompositionDirtyGeometry<
1420 CompositionCase<InsecureDisplaySetupVariant,
1421 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1422 ContainerLayerVariant<SecureLayerProperties>>,
1423 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1424 ForcedClientCompositionResultVariant>>();
1425}
1426
1427TEST_F(CompositionTest,
1428 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
1429 displayRefreshCompositionDirtyFrame<
1430 CompositionCase<InsecureDisplaySetupVariant,
1431 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1432 ContainerLayerVariant<SecureLayerProperties>>,
1433 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1434 ForcedClientCompositionResultVariant>>();
1435}
1436
1437TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1438 captureScreenComposition<
1439 CompositionCase<InsecureDisplaySetupVariant,
1440 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1441 ContainerLayerVariant<SecureLayerProperties>>,
1442 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1443}
1444
1445/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001446 * Cursor layers
1447 */
1448
1449TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1450 displayRefreshCompositionDirtyGeometry<
1451 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1452 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1453 HwcCompositionResultVariant>>();
1454}
1455
1456TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1457 displayRefreshCompositionDirtyFrame<
1458 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1459 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1460 HwcCompositionResultVariant>>();
1461}
1462
1463TEST_F(CompositionTest, REComposedCursorLayer) {
1464 displayRefreshCompositionDirtyFrame<
1465 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1466 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1467 IComposerClient::Composition::CLIENT>,
1468 RECompositionResultVariant>>();
1469}
1470
1471TEST_F(CompositionTest, captureScreenCursorLayer) {
1472 captureScreenComposition<
1473 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1474 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1475}
1476
1477/* ------------------------------------------------------------------------
1478 * Simple buffer layer on a display which is powered off.
1479 */
1480
1481TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001482 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001483 displayRefreshCompositionDirtyGeometry<CompositionCase<
1484 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1485 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1486 HwcCompositionResultVariant>>();
1487}
1488
1489TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001490 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001491 displayRefreshCompositionDirtyFrame<CompositionCase<
1492 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1493 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1494 HwcCompositionResultVariant>>();
1495}
1496
1497TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001498 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001499 displayRefreshCompositionDirtyFrame<CompositionCase<
1500 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1501 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1502 IComposerClient::Composition::CLIENT>,
1503 RECompositionResultVariant>>();
1504}
1505
1506TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1507 captureScreenComposition<CompositionCase<
1508 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1509 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1510}
1511
Lloyd Pique4fe29402019-08-12 16:51:24 -07001512/* ------------------------------------------------------------------------
1513 * Client composition forced through debug/developer settings
1514 */
1515
1516TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
1517 displayRefreshCompositionDirtyGeometry<
1518 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1519 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1520 ForcedClientCompositionViaDebugOptionResultVariant>>();
1521}
1522
1523TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
1524 displayRefreshCompositionDirtyFrame<
1525 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1526 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1527 ForcedClientCompositionViaDebugOptionResultVariant>>();
1528}
1529
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001530} // namespace
1531} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001532
1533// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001534#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"