blob: 6e83166a80dce84e9de8b8642eed77809e0d5bab [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
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Lloyd Piqued6b579f2018-04-06 15:29:10 -070021#undef LOG_TAG
22#define LOG_TAG "CompositionTest"
23
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080024#include <compositionengine/Display.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070025#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070026#include <gmock/gmock.h>
27#include <gtest/gtest.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070028#include <gui/IProducerListener.h>
Evan Roskya1f1e152019-01-24 16:17:46 -080029#include <gui/LayerMetadata.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070030#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070031#include <renderengine/mock/Framebuffer.h>
32#include <renderengine/mock/Image.h>
33#include <renderengine/mock/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070034#include <system/window.h>
35#include <utils/String8.h>
36
37#include "BufferQueueLayer.h"
Vishnu Nairfa247b12020-02-11 08:58:26 -080038#include "EffectLayer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070039#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070040#include "TestableSurfaceFlinger.h"
41#include "mock/DisplayHardware/MockComposer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070042#include "mock/MockDispSync.h"
43#include "mock/MockEventControlThread.h"
44#include "mock/MockEventThread.h"
45#include "mock/MockMessageQueue.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080046#include "mock/MockTimeStats.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070047#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070048
49namespace android {
50namespace {
51
52using testing::_;
David Sodman15094112018-10-11 09:39:37 -070053using testing::AtLeast;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000054using testing::Between;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070055using testing::ByMove;
56using testing::DoAll;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000057using testing::Field;
Alec Mouri0a9c7b82018-11-16 13:05:25 -080058using testing::Invoke;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070059using testing::IsNull;
60using testing::Mock;
61using testing::NotNull;
62using testing::Ref;
63using testing::Return;
64using testing::ReturnRef;
65using testing::SetArgPointee;
66
67using android::Hwc2::Error;
68using android::Hwc2::IComposer;
69using android::Hwc2::IComposerClient;
70using android::Hwc2::Transform;
71
72using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
73using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
74
75constexpr hwc2_display_t HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
76constexpr hwc2_layer_t HWC_LAYER = 5000;
77constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
78
Dominik Laskowski34157762018-10-31 13:07:19 -070079constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070080constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
81constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
82
83constexpr int DEFAULT_CONFIG_ID = 0;
84constexpr int DEFAULT_TEXTURE_ID = 6000;
85constexpr int DEFAULT_LAYER_STACK = 7000;
86
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));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700108 setupComposer(0);
109 }
110
111 ~CompositionTest() {
112 const ::testing::TestInfo* const test_info =
113 ::testing::UnitTest::GetInstance()->current_test_info();
114 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
115 }
116
117 void setupComposer(int virtualDisplayCount) {
118 mComposer = new Hwc2::mock::Composer();
119 EXPECT_CALL(*mComposer, getCapabilities())
120 .WillOnce(Return(std::vector<IComposer::Capability>()));
121 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
122 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
123
124 Mock::VerifyAndClear(mComposer);
125 }
126
Ana Krulecafb45842019-02-13 13:33:03 -0800127 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700128 auto eventThread = std::make_unique<mock::EventThread>();
129 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800130
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700131 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700132 EXPECT_CALL(*eventThread, createEventConnection(_, _))
133 .WillOnce(Return(
134 new EventThreadConnection(eventThread.get(), ResyncCallback(),
135 ISurfaceComposer::eConfigChangedSuppress)));
136
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700137 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700138 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
139 .WillOnce(Return(
140 new EventThreadConnection(sfEventThread.get(), ResyncCallback(),
141 ISurfaceComposer::eConfigChangedSuppress)));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700142
143 auto primaryDispSync = std::make_unique<mock::DispSync>();
144
145 EXPECT_CALL(*primaryDispSync, computeNextRefresh(0)).WillRepeatedly(Return(0));
146 EXPECT_CALL(*primaryDispSync, getPeriod())
147 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE));
148 EXPECT_CALL(*primaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
149
150 mFlinger.setupScheduler(std::move(primaryDispSync),
151 std::make_unique<mock::EventControlThread>(),
152 std::move(eventThread), std::move(sfEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800153 }
154
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700155 void setupForceGeometryDirty() {
156 // TODO: This requires the visible region and other related
157 // state to be set, and is problematic for BufferLayers since they are
158 // not visible without a buffer (and setting up a buffer looks like a
159 // pain)
160 // mFlinger.mutableVisibleRegionsDirty() = true;
161
162 mFlinger.mutableGeometryInvalid() = true;
163 }
164
165 template <typename Case>
166 void displayRefreshCompositionDirtyGeometry();
167
168 template <typename Case>
169 void displayRefreshCompositionDirtyFrame();
170
171 template <typename Case>
172 void captureScreenComposition();
173
174 std::unordered_set<HWC2::Capability> mDefaultCapabilities = {HWC2::Capability::SidebandStream};
175
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800176 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700177 TestableSurfaceFlinger mFlinger;
178 sp<DisplayDevice> mDisplay;
179 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700180 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
181 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700182 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700183
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800184 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
185 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
186
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700187 Hwc2::mock::Composer* mComposer = nullptr;
188 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800189 mock::TimeStats* mTimeStats = new mock::TimeStats();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700190 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700191
192 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
193
194 sp<GraphicBuffer> mCaptureScreenBuffer;
195};
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 useIdentityTransform = true;
230 constexpr bool forSystem = true;
231
232 DisplayRenderArea renderArea(mDisplay, sourceCrop, DEFAULT_DISPLAY_WIDTH,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700233 DEFAULT_DISPLAY_HEIGHT, ui::Dataspace::V0_SRGB,
234 ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700235
236 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw0e3479f2018-09-10 16:49:30 -0700237 return mFlinger.traverseLayersInDisplay(mDisplay, 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;
243 mCaptureScreenBuffer = new GraphicBuffer(renderArea.getReqWidth(), renderArea.getReqHeight(),
244 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage, "screenshot");
245
246 int fd = -1;
247 status_t result =
248 mFlinger.captureScreenImplLocked(renderArea, traverseLayers, mCaptureScreenBuffer.get(),
249 useIdentityTransform, forSystem, &fd);
250 if (fd >= 0) {
251 close(fd);
252 }
253
254 EXPECT_EQ(NO_ERROR, result);
255
256 LayerCase::cleanup(this);
257}
258
259/* ------------------------------------------------------------------------
260 * Variants for each display configuration which can be tested
261 */
262
263template <typename Derived>
264struct BaseDisplayVariant {
265 static constexpr bool IS_SECURE = true;
266 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
267
268 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700269 EXPECT_CALL(*test->mComposer,
270 setPowerMode(HWC_DISPLAY,
271 static_cast<Hwc2::IComposerClient::PowerMode>(
272 Derived::INIT_POWER_MODE)))
273 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700274
Dominik Laskowski075d3172018-05-24 15:50:06 -0700275 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, HWC2::DisplayType::Physical,
276 true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700277 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700278 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700279 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800280 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700281
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800282 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
283 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
284 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
285 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
286 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
287 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
288 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700289 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, DEFAULT_DISPLAY_ID,
290 false /* isVirtual */, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700291 .setDisplaySurface(test->mDisplaySurface)
Alec Mouriba013fa2018-10-16 12:43:11 -0700292 .setNativeWindow(test->mNativeWindow)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700293 .setSecure(Derived::IS_SECURE)
294 .setPowerMode(Derived::INIT_POWER_MODE)
295 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800296 Mock::VerifyAndClear(test->mNativeWindow);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700297 test->mDisplay->setLayerStack(DEFAULT_LAYER_STACK);
298 }
299
300 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700301 static void setupPreconditionCallExpectations(CompositionTest* test) {
302 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
303 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
304 Return(Error::NONE)));
305 }
306
307 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700308 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
309 EXPECT_CALL(*test->mComposer,
310 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
311 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700312 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
313 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
314 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
315 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
316
317 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700318
319 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
320 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
321
322 Case::CompositionType::setupHwcSetCallExpectations(test);
323 Case::CompositionType::setupHwcGetCallExpectations(test);
324 }
325
326 template <typename Case>
327 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000328 EXPECT_CALL(*test->mRenderEngine, drawLayers)
329 .WillRepeatedly(
330 [](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800331 const std::vector<const renderengine::LayerSettings*>&,
332 ANativeWindowBuffer*, const bool, base::unique_fd&&,
333 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000334 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
335 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
336 displaySettings.physicalDisplay);
337 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
338 displaySettings.clip);
339 return NO_ERROR;
340 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700341 }
342
343 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
344 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
345 }
346
347 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
348 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
349 }
350
351 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800352 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
353
Lloyd Pique542307f2018-10-19 13:24:08 -0700354 EXPECT_CALL(*test->mDisplaySurface,
355 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC))
356 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700357 }
358
Lloyd Pique66d68602019-02-13 14:23:31 -0800359 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
360 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
361 }
362
363 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
364 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1);
365 }
366
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700367 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700368 EXPECT_CALL(*test->mDisplaySurface,
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800369 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_GPU))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700370 .Times(1);
371 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
372 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
373
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800374 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
375 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
376 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
377 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000378 EXPECT_CALL(*test->mRenderEngine, drawLayers)
379 .WillRepeatedly(
380 [](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800381 const std::vector<const renderengine::LayerSettings*>&,
382 ANativeWindowBuffer*, const bool, base::unique_fd&&,
383 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000384 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
385 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
386 displaySettings.physicalDisplay);
387 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
388 displaySettings.clip);
389 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
390 return NO_ERROR;
391 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700392 }
393
394 template <typename Case>
395 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
396 Case::Layer::setupRECompositionCallExpectations(test);
397 }
398
399 template <typename Case>
400 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
401 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700402 }
403};
404
405struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
406
407struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
408 static constexpr bool IS_SECURE = false;
409
410 template <typename Case>
411 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
412 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700413 }
414
415 template <typename Case>
416 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
417 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700418 }
419};
420
421struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
422 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_OFF;
423
424 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700425 static void setupPreconditionCallExpectations(CompositionTest*) {}
426
427 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700428 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800429 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
430
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700431 // TODO: This seems like an unnecessary call if display is powered off.
432 EXPECT_CALL(*test->mComposer,
433 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
434 .Times(1);
435
436 // TODO: This seems like an unnecessary call if display is powered off.
437 Case::CompositionType::setupHwcSetCallExpectations(test);
438 }
439
440 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800441 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
442 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700443
444 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800445 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
446
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700447 // TODO: This seems like an unnecessary call if display is powered off.
448 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
449 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
450 }
451
452 template <typename Case>
453 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
454};
455
456/* ------------------------------------------------------------------------
457 * Variants for each layer configuration which can be tested
458 */
459
460template <typename LayerProperties>
461struct BaseLayerProperties {
462 static constexpr uint32_t WIDTH = 100;
463 static constexpr uint32_t HEIGHT = 100;
464 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
465 static constexpr uint64_t USAGE =
466 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
467 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
468 static constexpr uint32_t SCALING_MODE = 0;
469 static constexpr uint32_t TRANSFORM = 0;
470 static constexpr uint32_t LAYER_FLAGS = 0;
471 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
472 static constexpr IComposerClient::BlendMode BLENDMODE =
473 IComposerClient::BlendMode::PREMULTIPLIED;
474
475 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
476 auto producer = layer->getProducer();
477
478 IGraphicBufferProducer::QueueBufferOutput qbo;
479 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
480 if (result != NO_ERROR) {
481 ALOGE("Failed to connect() (%d)", result);
482 return;
483 }
484
485 int slot;
486 sp<Fence> fence;
487 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
488 LayerProperties::HEIGHT, LayerProperties::FORMAT,
489 LayerProperties::USAGE, nullptr, nullptr);
490 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
491 ALOGE("Failed to dequeueBuffer() (%d)", result);
492 return;
493 }
494
495 sp<GraphicBuffer> buffer;
496 result = producer->requestBuffer(slot, &buffer);
497 if (result != NO_ERROR) {
498 ALOGE("Failed to requestBuffer() (%d)", result);
499 return;
500 }
501
502 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
503 LayerProperties::DATASPACE,
504 Rect(LayerProperties::WIDTH,
505 LayerProperties::HEIGHT),
506 LayerProperties::SCALING_MODE,
507 LayerProperties::TRANSFORM, Fence::NO_FENCE);
508 result = producer->queueBuffer(slot, qbi, &qbo);
509 if (result != NO_ERROR) {
510 ALOGE("Failed to queueBuffer (%d)", result);
511 return;
512 }
513 }
514
515 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
516 // TODO: Eliminate the complexity of actually creating a buffer
517 EXPECT_CALL(*test->mRenderEngine, getMaxTextureSize()).WillOnce(Return(16384));
518 EXPECT_CALL(*test->mRenderEngine, getMaxViewportDims()).WillOnce(Return(16384));
519 status_t err =
520 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
521 LayerProperties::FORMAT);
522 ASSERT_EQ(NO_ERROR, err);
523 Mock::VerifyAndClear(test->mRenderEngine);
524
525 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
526 enqueueBuffer(test, layer);
527 Mock::VerifyAndClear(test->mMessageQueue);
528
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700529 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700530 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700531 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700532 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700533 }
534
535 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
536 setupLatchedBuffer(test, layer);
537 }
538
539 static void setupBufferLayerPostFrameCallExpectations(CompositionTest* test) {
540 // BufferLayer::onPostComposition(), when there is no present fence
541 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY, _))
542 .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE)));
543 }
544
545 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800546 if (!test->mDisplayOff) {
547 // TODO: Coverage of other values
548 EXPECT_CALL(*test->mComposer,
549 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
550 .Times(1);
551 // TODO: Coverage of other values for origin
552 EXPECT_CALL(*test->mComposer,
553 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
554 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
555 LayerProperties::HEIGHT})))
556 .Times(1);
557 EXPECT_CALL(*test->mComposer,
558 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
559 .Times(1);
560 // TODO: Coverage of other values
561 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
562 // TODO: Coverage of other values
563 EXPECT_CALL(*test->mComposer, setLayerInfo(HWC_DISPLAY, HWC_LAYER, 0u, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700564
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800565 // These expectations retire on saturation as the code path these
566 // expectations are for appears to make an extra call to them.
567 // TODO: Investigate this extra call
568 EXPECT_CALL(*test->mComposer,
569 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
570 .Times(AtLeast(1))
571 .RetiresOnSaturation();
572 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700573 }
574
575 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800576 if (!test->mDisplayOff) {
577 EXPECT_CALL(*test->mComposer,
578 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
579 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
580 LayerProperties::HEIGHT})))
581 .Times(1);
582 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700583 }
584
585 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800586 if (!test->mDisplayOff) {
587 EXPECT_CALL(*test->mComposer,
588 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
589 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
590 .Times(1);
591 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700592 }
593
594 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800595 if (!test->mDisplayOff) {
596 EXPECT_CALL(*test->mComposer,
597 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
598 std::vector<IComposerClient::Rect>(
599 {IComposerClient::Rect(
600 {0, 0, LayerProperties::WIDTH,
601 LayerProperties::HEIGHT})})))
602 .Times(1);
603 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700604 }
605
606 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800607 if (!test->mDisplayOff) {
608 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
609 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700610
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800611 // TODO: use COLOR
612 EXPECT_CALL(*test->mComposer,
613 setLayerColor(HWC_DISPLAY, HWC_LAYER,
614 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
615 .Times(1);
616 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700617 }
618
619 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800620 if (!test->mDisplayOff) {
621 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
622 .Times(1);
623 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
624 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700625
626 setupBufferLayerPostFrameCallExpectations(test);
627 }
628
629 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000630 EXPECT_CALL(*test->mRenderEngine, drawLayers)
631 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800632 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700633 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800634 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000635 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
636 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
637 displaySettings.physicalDisplay);
638 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
639 displaySettings.clip);
640 // screen capture adds an additional color layer as an alpha
641 // prefill, so gtet the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800642 if (layerSettings.empty()) {
643 ADD_FAILURE() << "layerSettings was not expected to be empty in "
644 "setupREBufferCompositionCommonCallExpectations "
645 "verification lambda";
646 return NO_ERROR;
647 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800648 const renderengine::LayerSettings* layer = layerSettings.back();
649 EXPECT_THAT(layer->source.buffer.buffer, Not(IsNull()));
650 EXPECT_THAT(layer->source.buffer.fence, Not(IsNull()));
651 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer->source.buffer.textureName);
652 EXPECT_EQ(false, layer->source.buffer.isY410BT2020);
653 EXPECT_EQ(true, layer->source.buffer.usePremultipliedAlpha);
654 EXPECT_EQ(false, layer->source.buffer.isOpaque);
655 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
656 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
657 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000658 return NO_ERROR;
659 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700660 }
661
662 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
663 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700664 }
665
666 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
667 setupREBufferCompositionCallExpectations(test);
668 }
669
670 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
671 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
672 }
673
674 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
675 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
676 }
677
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700678 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000679 EXPECT_CALL(*test->mRenderEngine, drawLayers)
680 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800681 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700682 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800683 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000684 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
685 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
686 displaySettings.physicalDisplay);
687 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
688 displaySettings.clip);
689 // screen capture adds an additional color layer as an alpha
690 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800691 if (layerSettings.empty()) {
692 ADD_FAILURE()
693 << "layerSettings was not expected to be empty in "
694 "setupREColorCompositionCallExpectations verification lambda";
695 return NO_ERROR;
696 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800697 const renderengine::LayerSettings* layer = layerSettings.back();
698 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000699 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
700 LayerProperties::COLOR[2]),
Vishnu Nair9b079a22020-01-21 14:36:08 -0800701 layer->source.solidColor);
702 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
703 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
704 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000705 return NO_ERROR;
706 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700707 }
708
709 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
710 setupREColorCompositionCallExpectations(test);
711 }
712};
713
714struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
715
Vishnu Nairfa247b12020-02-11 08:58:26 -0800716struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800717 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
718};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700719
720struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
721 using Base = BaseLayerProperties<SidebandLayerProperties>;
722 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
723
724 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
725 sp<NativeHandle> stream =
726 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
727 false);
728 test->mFlinger.setLayerSidebandStream(layer, stream);
729 }
730
731 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
732 EXPECT_CALL(*test->mComposer,
733 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
734 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
735 .Times(1);
736 }
737
738 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
739 EXPECT_CALL(*test->mComposer,
740 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
741 reinterpret_cast<native_handle_t*>(
742 DEFAULT_SIDEBAND_STREAM)))
743 .WillOnce(Return(Error::NONE));
744
745 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
746 }
747
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000748 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700749};
750
751struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> {
752 using Base = BaseLayerProperties<SecureLayerProperties>;
753
754 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
755
756 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000757 EXPECT_CALL(*test->mRenderEngine, drawLayers)
758 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800759 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700760 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800761 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000762 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
763 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
764 displaySettings.physicalDisplay);
765 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
766 displaySettings.clip);
767 // screen capture adds an additional color layer as an alpha
768 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800769 if (layerSettings.empty()) {
770 ADD_FAILURE() << "layerSettings was not expected to be empty in "
771 "setupInsecureREBufferCompositionCommonCallExpectations "
772 "verification lambda";
773 return NO_ERROR;
774 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800775 const renderengine::LayerSettings* layer = layerSettings.back();
776 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
777 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer->source.solidColor);
778 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
779 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
780 EXPECT_EQ(1.0f, layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000781 return NO_ERROR;
782 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700783 }
784
785 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
786 setupInsecureREBufferCompositionCommonCallExpectations(test);
787 Base::setupBufferLayerPostFrameCallExpectations(test);
788 }
789
790 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
791 setupInsecureREBufferCompositionCommonCallExpectations(test);
792 }
793};
794
795struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
796 using Base = BaseLayerProperties<CursorLayerProperties>;
797
798 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
799 Base::setupLayerState(test, layer);
800 test->mFlinger.setLayerPotentialCursor(layer, true);
801 }
802};
803
804struct NoLayerVariant {
805 using FlingerLayerType = sp<BufferQueueLayer>;
806
807 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
808 static void injectLayer(CompositionTest*, FlingerLayerType) {}
809 static void cleanupInjectedLayers(CompositionTest*) {}
810
811 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
812 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
813};
814
815template <typename LayerProperties>
816struct BaseLayerVariant {
817 template <typename L, typename F>
818 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
819 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0);
820
821 sp<L> layer = factory();
822
Dominik Laskowski49cea512019-11-12 14:13:23 -0800823 // Layer should be registered with scheduler.
824 EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize());
825
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700826 Mock::VerifyAndClear(test->mComposer);
827 Mock::VerifyAndClear(test->mRenderEngine);
828 Mock::VerifyAndClear(test->mMessageQueue);
829
830 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
831 layerDrawingState.layerStack = DEFAULT_LAYER_STACK;
832 layerDrawingState.active.w = 100;
833 layerDrawingState.active.h = 100;
834 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
835 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700836 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700837
838 return layer;
839 }
840
841 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
842 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
843 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
844
Lloyd Piquede196652020-01-22 17:29:58 -0800845 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
846 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700847 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
848 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700849
850 Mock::VerifyAndClear(test->mComposer);
851
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700852 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
853 }
854
855 static void cleanupInjectedLayers(CompositionTest* test) {
856 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
857 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800858
Lloyd Pique01c77c12019-04-17 12:48:32 -0700859 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700860 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800861
862 // Layer should be unregistered with scheduler.
863 test->mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
864 EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700865 }
866};
867
868template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800869struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700870 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800871 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700872
873 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800874 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
875 return new EffectLayer(
876 LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(), "test-layer",
877 LayerProperties::WIDTH, LayerProperties::HEIGHT,
878 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700879 });
Vishnu Nair60356342018-11-13 13:00:45 -0800880
881 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
882 layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700883 return layer;
884 }
885
886 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700887 LayerProperties::setupREColorCompositionCallExpectations(test);
888 }
889
890 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
891 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
892 }
893
894 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
895 LayerProperties::setupHwcSetGeometryCallExpectations(test);
896 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
897 }
898
899 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
900 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
901 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
902 }
903};
904
905template <typename LayerProperties>
906struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
907 using Base = BaseLayerVariant<LayerProperties>;
908 using FlingerLayerType = sp<BufferQueueLayer>;
909
910 static FlingerLayerType createLayer(CompositionTest* test) {
911 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
912
913 FlingerLayerType layer =
914 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
chaviwb4c6e582019-08-16 14:35:07 -0700915 sp<Client> client;
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700916 LayerCreationArgs args(test->mFlinger.mFlinger.get(), client, "test-layer",
917 LayerProperties::WIDTH, LayerProperties::HEIGHT,
918 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700919 args.textureName = test->mFlinger.mutableTexturePool().back();
920 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700921 });
922
923 LayerProperties::setupLayerState(test, layer);
924
925 return layer;
926 }
927
928 static void cleanupInjectedLayers(CompositionTest* test) {
Dan Stoza67765d82019-05-07 14:58:27 -0700929 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700930 Base::cleanupInjectedLayers(test);
931 }
932
933 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
934 LayerProperties::setupHwcSetGeometryCallExpectations(test);
935 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
936 }
937
938 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
939 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
940 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
941 }
942
943 static void setupRECompositionCallExpectations(CompositionTest* test) {
944 LayerProperties::setupREBufferCompositionCallExpectations(test);
945 }
946
947 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
948 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
949 }
950
951 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
952 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
953 }
954
955 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
956 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
957 }
958};
959
960/* ------------------------------------------------------------------------
961 * Variants to control how the composition type is changed
962 */
963
964struct NoCompositionTypeVariant {
965 static void setupHwcSetCallExpectations(CompositionTest*) {}
966
967 static void setupHwcGetCallExpectations(CompositionTest* test) {
968 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
969 }
970};
971
972template <IComposerClient::Composition CompositionType>
973struct KeepCompositionTypeVariant {
974 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(CompositionType);
975
976 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800977 if (!test->mDisplayOff) {
978 EXPECT_CALL(*test->mComposer,
979 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
980 .Times(1);
981 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700982 }
983
984 static void setupHwcGetCallExpectations(CompositionTest* test) {
985 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
986 }
987};
988
989template <IComposerClient::Composition InitialCompositionType,
990 IComposerClient::Composition FinalCompositionType>
991struct ChangeCompositionTypeVariant {
992 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(FinalCompositionType);
993
994 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800995 if (!test->mDisplayOff) {
996 EXPECT_CALL(*test->mComposer,
997 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
998 .Times(1);
999 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001000 }
1001
1002 static void setupHwcGetCallExpectations(CompositionTest* test) {
1003 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1004 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1005 static_cast<Hwc2::Layer>(HWC_LAYER)}),
1006 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
1007 FinalCompositionType}),
1008 Return(Error::NONE)));
1009 }
1010};
1011
1012/* ------------------------------------------------------------------------
1013 * Variants to select how the composition is expected to be handled
1014 */
1015
1016struct CompositionResultBaseVariant {
1017 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1018
1019 template <typename Case>
1020 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1021 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1022 }
1023
1024 template <typename Case>
1025 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1026 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1027 }
1028};
1029
1030struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1031 template <typename Case>
1032 static void setupCallExpectations(CompositionTest* test) {
1033 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1034 Case::Display::setupHwcCompositionCallExpectations(test);
1035 }
1036};
1037
1038struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1039 template <typename Case>
1040 static void setupCallExpectations(CompositionTest* test) {
1041 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1042 Case::Display::setupHwcCompositionCallExpectations(test);
1043 }
1044};
1045
1046struct RECompositionResultVariant : public CompositionResultBaseVariant {
1047 template <typename Case>
1048 static void setupCallExpectations(CompositionTest* test) {
1049 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001050 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001051 Case::Display::setupRECompositionCallExpectations(test);
1052 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1053 }
1054};
1055
Lloyd Pique66d68602019-02-13 14:23:31 -08001056struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001057 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piquef5275482019-01-29 18:42:42 -08001058 const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay);
1059 LOG_FATAL_IF(!outputLayer);
1060 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001061 }
1062
1063 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001064 static void setupCallExpectations(CompositionTest* test) {
1065 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1066 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1067 Case::Display::setupRECompositionCallExpectations(test);
1068 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1069 }
1070
1071 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001072 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1073
1074 template <typename Case>
1075 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1076};
1077
Lloyd Pique4fe29402019-08-12 16:51:24 -07001078struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1079 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1080 test->mFlinger.mutableDebugDisableHWC() = true;
1081 }
1082
1083 template <typename Case>
1084 static void setupCallExpectations(CompositionTest* test) {
1085 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1086 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1087 Case::Display::setupRECompositionCallExpectations(test);
1088 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1089 }
1090
1091 template <typename Case>
1092 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1093
1094 template <typename Case>
1095 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1096};
1097
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001098struct EmptyScreenshotResultVariant {
1099 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1100
1101 template <typename Case>
1102 static void setupCallExpectations(CompositionTest*) {}
1103};
1104
1105struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1106 using Base = EmptyScreenshotResultVariant;
1107
1108 template <typename Case>
1109 static void setupCallExpectations(CompositionTest* test) {
1110 Base::template setupCallExpectations<Case>(test);
1111 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1112 }
1113};
1114
1115/* ------------------------------------------------------------------------
1116 * Composition test case, containing all the variants being tested
1117 */
1118
1119template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1120 typename CompositionResultCase>
1121struct CompositionCase {
1122 using ThisCase =
1123 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1124 using Display = DisplayCase;
1125 using Layer = LayerCase;
1126 using CompositionType = CompositionTypeCase;
1127 using CompositionResult = CompositionResultCase;
1128
1129 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001130 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001131 Display::setupPreconditions(test);
1132
1133 auto layer = Layer::createLayer(test);
1134 Layer::injectLayer(test, layer);
1135 CompositionResult::setupLayerState(test, layer);
1136 }
1137
1138 static void setupForDirtyGeometry(CompositionTest* test) {
1139 setupCommon(test);
1140
1141 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1142 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1143 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1144 CompositionResult::template setupCallExpectations<ThisCase>(test);
1145 }
1146
1147 static void setupForDirtyFrame(CompositionTest* test) {
1148 setupCommon(test);
1149
1150 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1151 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1152 CompositionResult::template setupCallExpectations<ThisCase>(test);
1153 }
1154
1155 static void setupForScreenCapture(CompositionTest* test) {
1156 setupCommon(test);
1157
1158 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1159 CompositionResult::template setupCallExpectations<ThisCase>(test);
1160 }
1161
1162 static void cleanup(CompositionTest* test) {
1163 Layer::cleanupInjectedLayers(test);
1164
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001165 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1166 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1167 ->mutableLayers()
1168 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001169 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001170 }
1171};
1172
1173/* ------------------------------------------------------------------------
1174 * Composition cases to test
1175 */
1176
1177TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1178 displayRefreshCompositionDirtyGeometry<
1179 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1180 NoCompositionResultVariant>>();
1181}
1182
1183TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1184 displayRefreshCompositionDirtyFrame<
1185 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1186 NoCompositionResultVariant>>();
1187}
1188
1189TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1190 captureScreenComposition<
1191 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1192 EmptyScreenshotResultVariant>>();
1193}
1194
1195/* ------------------------------------------------------------------------
1196 * Simple buffer layers
1197 */
1198
1199TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1200 displayRefreshCompositionDirtyGeometry<
1201 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1202 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1203 HwcCompositionResultVariant>>();
1204}
1205
1206TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1207 displayRefreshCompositionDirtyFrame<
1208 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1209 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1210 HwcCompositionResultVariant>>();
1211}
1212
1213TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1214 displayRefreshCompositionDirtyFrame<
1215 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1216 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1217 IComposerClient::Composition::CLIENT>,
1218 RECompositionResultVariant>>();
1219}
1220
1221TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1222 captureScreenComposition<
1223 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1224 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1225}
1226
1227/* ------------------------------------------------------------------------
1228 * Single-color layers
1229 */
1230
Vishnu Nairfa247b12020-02-11 08:58:26 -08001231TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001232 displayRefreshCompositionDirtyGeometry<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001233 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001234 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1235 HwcCompositionResultVariant>>();
1236}
1237
Vishnu Nairfa247b12020-02-11 08:58:26 -08001238TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001239 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001240 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001241 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1242 HwcCompositionResultVariant>>();
1243}
1244
Vishnu Nairfa247b12020-02-11 08:58:26 -08001245TEST_F(CompositionTest, REComposedEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001246 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001247 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001248 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1249 IComposerClient::Composition::CLIENT>,
1250 RECompositionResultVariant>>();
1251}
1252
Vishnu Nairfa247b12020-02-11 08:58:26 -08001253TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001254 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001255 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001256 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1257}
1258
1259/* ------------------------------------------------------------------------
1260 * Layers with sideband buffers
1261 */
1262
1263TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1264 displayRefreshCompositionDirtyGeometry<
1265 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1266 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1267 HwcCompositionResultVariant>>();
1268}
1269
1270TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1271 displayRefreshCompositionDirtyFrame<
1272 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1273 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1274 HwcCompositionResultVariant>>();
1275}
1276
1277TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1278 displayRefreshCompositionDirtyFrame<
1279 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1280 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1281 IComposerClient::Composition::CLIENT>,
1282 RECompositionResultVariant>>();
1283}
1284
1285TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1286 captureScreenComposition<
1287 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1288 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1289}
1290
1291/* ------------------------------------------------------------------------
1292 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1293 */
1294
1295TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1296 displayRefreshCompositionDirtyGeometry<
1297 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1298 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1299 HwcCompositionResultVariant>>();
1300}
1301
1302TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1303 displayRefreshCompositionDirtyFrame<
1304 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1305 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1306 HwcCompositionResultVariant>>();
1307}
1308
1309TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1310 displayRefreshCompositionDirtyFrame<
1311 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1312 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1313 IComposerClient::Composition::CLIENT>,
1314 RECompositionResultVariant>>();
1315}
1316
1317TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1318 captureScreenComposition<
1319 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1320 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1321}
1322
1323/* ------------------------------------------------------------------------
1324 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1325 */
1326
1327TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1328 displayRefreshCompositionDirtyGeometry<
1329 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1330 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1331 ForcedClientCompositionResultVariant>>();
1332}
1333
1334TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1335 displayRefreshCompositionDirtyFrame<
1336 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1337 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1338 ForcedClientCompositionResultVariant>>();
1339}
1340
1341TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1342 captureScreenComposition<
1343 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1344 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1345}
1346
1347/* ------------------------------------------------------------------------
1348 * Cursor layers
1349 */
1350
1351TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1352 displayRefreshCompositionDirtyGeometry<
1353 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1354 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1355 HwcCompositionResultVariant>>();
1356}
1357
1358TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1359 displayRefreshCompositionDirtyFrame<
1360 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1361 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1362 HwcCompositionResultVariant>>();
1363}
1364
1365TEST_F(CompositionTest, REComposedCursorLayer) {
1366 displayRefreshCompositionDirtyFrame<
1367 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1368 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1369 IComposerClient::Composition::CLIENT>,
1370 RECompositionResultVariant>>();
1371}
1372
1373TEST_F(CompositionTest, captureScreenCursorLayer) {
1374 captureScreenComposition<
1375 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1376 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1377}
1378
1379/* ------------------------------------------------------------------------
1380 * Simple buffer layer on a display which is powered off.
1381 */
1382
1383TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001384 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001385 displayRefreshCompositionDirtyGeometry<CompositionCase<
1386 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1387 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1388 HwcCompositionResultVariant>>();
1389}
1390
1391TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001392 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001393 displayRefreshCompositionDirtyFrame<CompositionCase<
1394 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1395 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1396 HwcCompositionResultVariant>>();
1397}
1398
1399TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001400 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001401 displayRefreshCompositionDirtyFrame<CompositionCase<
1402 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1403 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1404 IComposerClient::Composition::CLIENT>,
1405 RECompositionResultVariant>>();
1406}
1407
1408TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1409 captureScreenComposition<CompositionCase<
1410 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1411 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1412}
1413
Lloyd Pique4fe29402019-08-12 16:51:24 -07001414/* ------------------------------------------------------------------------
1415 * Client composition forced through debug/developer settings
1416 */
1417
1418TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
1419 displayRefreshCompositionDirtyGeometry<
1420 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1421 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1422 ForcedClientCompositionViaDebugOptionResultVariant>>();
1423}
1424
1425TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
1426 displayRefreshCompositionDirtyFrame<
1427 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1428 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1429 ForcedClientCompositionViaDebugOptionResultVariant>>();
1430}
1431
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001432} // namespace
1433} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001434
1435// TODO(b/129481165): remove the #pragma below and fix conversion issues
1436#pragma clang diagnostic pop // ignored "-Wconversion"