blob: 93a609aac2b917ba0ee7bb2d587347b8078d4d30 [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 Piqueaad4ebf2019-10-03 17:58:30 -070042#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070043#include "mock/MockDispSync.h"
44#include "mock/MockEventControlThread.h"
45#include "mock/MockEventThread.h"
46#include "mock/MockMessageQueue.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080047#include "mock/MockTimeStats.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070048#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070049
50namespace android {
51namespace {
52
Peiyong Line9d809e2020-04-14 13:10:48 -070053namespace hal = android::hardware::graphics::composer::hal;
54
Lloyd Piqued6b579f2018-04-06 15:29:10 -070055using testing::_;
David Sodman15094112018-10-11 09:39:37 -070056using testing::AtLeast;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000057using testing::Between;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070058using testing::ByMove;
59using testing::DoAll;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000060using testing::Field;
Alec Mouri0a9c7b82018-11-16 13:05:25 -080061using testing::Invoke;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070062using testing::IsNull;
63using testing::Mock;
64using testing::NotNull;
65using testing::Ref;
66using testing::Return;
67using testing::ReturnRef;
68using testing::SetArgPointee;
69
70using android::Hwc2::Error;
71using android::Hwc2::IComposer;
72using android::Hwc2::IComposerClient;
73using android::Hwc2::Transform;
74
75using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
76using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
77
Peiyong Line9d809e2020-04-14 13:10:48 -070078constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
79constexpr hal::HWLayerId HWC_LAYER = 5000;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070080constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
81
Dominik Laskowski34157762018-10-31 13:07:19 -070082constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070083constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
84constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
85
86constexpr int DEFAULT_CONFIG_ID = 0;
87constexpr int DEFAULT_TEXTURE_ID = 6000;
88constexpr int DEFAULT_LAYER_STACK = 7000;
89
90constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
91
92constexpr int DEFAULT_SIDEBAND_STREAM = 51;
93
94class CompositionTest : public testing::Test {
95public:
96 CompositionTest() {
97 const ::testing::TestInfo* const test_info =
98 ::testing::UnitTest::GetInstance()->current_test_info();
99 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
100
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700101 mFlinger.mutableEventQueue().reset(mMessageQueue);
Ana Krulecafb45842019-02-13 13:33:03 -0800102 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700103
Alec Mourif6fd29e2018-11-17 04:56:41 +0000104 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
105 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
106 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
107 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700108
109 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800110 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700111 setupComposer(0);
112 }
113
114 ~CompositionTest() {
115 const ::testing::TestInfo* const test_info =
116 ::testing::UnitTest::GetInstance()->current_test_info();
117 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
118 }
119
120 void setupComposer(int virtualDisplayCount) {
121 mComposer = new Hwc2::mock::Composer();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700122 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
123 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
124
125 Mock::VerifyAndClear(mComposer);
126 }
127
Ana Krulecafb45842019-02-13 13:33:03 -0800128 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700129 auto eventThread = std::make_unique<mock::EventThread>();
130 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800131
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700132 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700133 EXPECT_CALL(*eventThread, createEventConnection(_, _))
134 .WillOnce(Return(
135 new EventThreadConnection(eventThread.get(), ResyncCallback(),
136 ISurfaceComposer::eConfigChangedSuppress)));
137
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700138 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700139 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
140 .WillOnce(Return(
141 new EventThreadConnection(sfEventThread.get(), ResyncCallback(),
142 ISurfaceComposer::eConfigChangedSuppress)));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700143
144 auto primaryDispSync = std::make_unique<mock::DispSync>();
145
146 EXPECT_CALL(*primaryDispSync, computeNextRefresh(0)).WillRepeatedly(Return(0));
147 EXPECT_CALL(*primaryDispSync, getPeriod())
148 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE));
149 EXPECT_CALL(*primaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
150
151 mFlinger.setupScheduler(std::move(primaryDispSync),
152 std::make_unique<mock::EventControlThread>(),
153 std::move(eventThread), std::move(sfEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800154 }
155
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700156 void setupForceGeometryDirty() {
157 // TODO: This requires the visible region and other related
158 // state to be set, and is problematic for BufferLayers since they are
159 // not visible without a buffer (and setting up a buffer looks like a
160 // pain)
161 // mFlinger.mutableVisibleRegionsDirty() = true;
162
163 mFlinger.mutableGeometryInvalid() = true;
164 }
165
166 template <typename Case>
167 void displayRefreshCompositionDirtyGeometry();
168
169 template <typename Case>
170 void displayRefreshCompositionDirtyFrame();
171
172 template <typename Case>
173 void captureScreenComposition();
174
Peiyong Line9d809e2020-04-14 13:10:48 -0700175 std::unordered_set<hal::Capability> mDefaultCapabilities = {hal::Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700176
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800177 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700178 TestableSurfaceFlinger mFlinger;
179 sp<DisplayDevice> mDisplay;
180 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700181 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
182 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700183 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700184
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800185 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
186 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
187
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700188 Hwc2::mock::Composer* mComposer = nullptr;
189 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800190 mock::TimeStats* mTimeStats = new mock::TimeStats();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700191 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700192 Hwc2::mock::PowerAdvisor mPowerAdvisor;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700193
194 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
195
196 sp<GraphicBuffer> mCaptureScreenBuffer;
197};
198
199template <typename LayerCase>
200void CompositionTest::displayRefreshCompositionDirtyGeometry() {
201 setupForceGeometryDirty();
202 LayerCase::setupForDirtyGeometry(this);
203
204 // --------------------------------------------------------------------
205 // Invocation
206
207 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
208 mFlinger.onMessageReceived(MessageQueue::REFRESH);
209
210 LayerCase::cleanup(this);
211}
212
213template <typename LayerCase>
214void CompositionTest::displayRefreshCompositionDirtyFrame() {
215 LayerCase::setupForDirtyFrame(this);
216
217 // --------------------------------------------------------------------
218 // Invocation
219
220 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
221 mFlinger.onMessageReceived(MessageQueue::REFRESH);
222
223 LayerCase::cleanup(this);
224}
225
226template <typename LayerCase>
227void CompositionTest::captureScreenComposition() {
228 LayerCase::setupForScreenCapture(this);
229
230 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700231 constexpr bool useIdentityTransform = true;
232 constexpr bool forSystem = true;
233
234 DisplayRenderArea renderArea(mDisplay, sourceCrop, DEFAULT_DISPLAY_WIDTH,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700235 DEFAULT_DISPLAY_HEIGHT, ui::Dataspace::V0_SRGB,
236 ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700237
238 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw0e3479f2018-09-10 16:49:30 -0700239 return mFlinger.traverseLayersInDisplay(mDisplay, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700240 };
241
242 // TODO: Eliminate expensive/real allocation if possible.
243 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
244 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
245 mCaptureScreenBuffer = new GraphicBuffer(renderArea.getReqWidth(), renderArea.getReqHeight(),
246 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage, "screenshot");
247
248 int fd = -1;
249 status_t result =
250 mFlinger.captureScreenImplLocked(renderArea, traverseLayers, mCaptureScreenBuffer.get(),
251 useIdentityTransform, forSystem, &fd);
252 if (fd >= 0) {
253 close(fd);
254 }
255
256 EXPECT_EQ(NO_ERROR, result);
257
258 LayerCase::cleanup(this);
259}
260
261/* ------------------------------------------------------------------------
262 * Variants for each display configuration which can be tested
263 */
264
265template <typename Derived>
266struct BaseDisplayVariant {
267 static constexpr bool IS_SECURE = true;
268 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
269
270 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700271 EXPECT_CALL(*test->mComposer,
272 setPowerMode(HWC_DISPLAY,
273 static_cast<Hwc2::IComposerClient::PowerMode>(
274 Derived::INIT_POWER_MODE)))
275 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700276
Peiyong Line9d809e2020-04-14 13:10:48 -0700277 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700278 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700279 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700280 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800281 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700282
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800283 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
284 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
285 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
286 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
287 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
288 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
289 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700290
291 const ::testing::TestInfo* const test_info =
292 ::testing::UnitTest::GetInstance()->current_test_info();
293
294 auto ceDisplayArgs =
295 compositionengine::DisplayCreationArgsBuilder()
296 .setPhysical({DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal})
297 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
298 .setIsSecure(Derived::IS_SECURE)
299 .setLayerStackId(DEFAULT_LAYER_STACK)
300 .setPowerAdvisor(&test->mPowerAdvisor)
301 .setName(std::string("Injected display for ") +
302 test_info->test_case_name() + "." + test_info->name())
303 .build();
304
305 auto compositionDisplay =
306 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
307 ceDisplayArgs);
308
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100309 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
310 DisplayConnectionType::Internal, HWC_DISPLAY,
311 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);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700318 test->mDisplay->setLayerStack(DEFAULT_LAYER_STACK);
319 }
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
338 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700339
340 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
341 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
342
343 Case::CompositionType::setupHwcSetCallExpectations(test);
344 Case::CompositionType::setupHwcGetCallExpectations(test);
345 }
346
347 template <typename Case>
348 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000349 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700350 .WillRepeatedly([](const renderengine::DisplaySettings& displaySettings,
351 const std::vector<const renderengine::LayerSettings*>&,
352 ANativeWindowBuffer*, const bool, base::unique_fd&&,
353 base::unique_fd*) -> status_t {
354 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
355 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
356 displaySettings.physicalDisplay);
357 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
358 displaySettings.clip);
359 return NO_ERROR;
360 });
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)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700399 .WillRepeatedly([](const renderengine::DisplaySettings& displaySettings,
400 const std::vector<const renderengine::LayerSettings*>&,
401 ANativeWindowBuffer*, const bool, base::unique_fd&&,
402 base::unique_fd*) -> status_t {
403 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
404 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
405 displaySettings.physicalDisplay);
406 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
407 displaySettings.clip);
408 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
409 return NO_ERROR;
410 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700411 }
412
413 template <typename Case>
414 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
415 Case::Layer::setupRECompositionCallExpectations(test);
416 }
417
418 template <typename Case>
419 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
420 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700421 }
422};
423
424struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
425
426struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
427 static constexpr bool IS_SECURE = false;
428
429 template <typename Case>
430 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
431 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700432 }
433
434 template <typename Case>
435 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
436 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700437 }
438};
439
440struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
441 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_OFF;
442
443 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700444 static void setupPreconditionCallExpectations(CompositionTest*) {}
445
446 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700447 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800448 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
449
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700450 // 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) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800464 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
465
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700466 // TODO: This seems like an unnecessary call if display is powered off.
467 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
468 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
469 }
470
471 template <typename Case>
472 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
473};
474
475/* ------------------------------------------------------------------------
476 * Variants for each layer configuration which can be tested
477 */
478
479template <typename LayerProperties>
480struct BaseLayerProperties {
481 static constexpr uint32_t WIDTH = 100;
482 static constexpr uint32_t HEIGHT = 100;
483 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
484 static constexpr uint64_t USAGE =
485 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
486 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
487 static constexpr uint32_t SCALING_MODE = 0;
488 static constexpr uint32_t TRANSFORM = 0;
489 static constexpr uint32_t LAYER_FLAGS = 0;
490 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
491 static constexpr IComposerClient::BlendMode BLENDMODE =
492 IComposerClient::BlendMode::PREMULTIPLIED;
493
494 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
495 auto producer = layer->getProducer();
496
497 IGraphicBufferProducer::QueueBufferOutput qbo;
498 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
499 if (result != NO_ERROR) {
500 ALOGE("Failed to connect() (%d)", result);
501 return;
502 }
503
504 int slot;
505 sp<Fence> fence;
506 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
507 LayerProperties::HEIGHT, LayerProperties::FORMAT,
508 LayerProperties::USAGE, nullptr, nullptr);
509 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
510 ALOGE("Failed to dequeueBuffer() (%d)", result);
511 return;
512 }
513
514 sp<GraphicBuffer> buffer;
515 result = producer->requestBuffer(slot, &buffer);
516 if (result != NO_ERROR) {
517 ALOGE("Failed to requestBuffer() (%d)", result);
518 return;
519 }
520
521 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
522 LayerProperties::DATASPACE,
523 Rect(LayerProperties::WIDTH,
524 LayerProperties::HEIGHT),
525 LayerProperties::SCALING_MODE,
526 LayerProperties::TRANSFORM, Fence::NO_FENCE);
527 result = producer->queueBuffer(slot, qbi, &qbo);
528 if (result != NO_ERROR) {
529 ALOGE("Failed to queueBuffer (%d)", result);
530 return;
531 }
532 }
533
534 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
535 // TODO: Eliminate the complexity of actually creating a buffer
536 EXPECT_CALL(*test->mRenderEngine, getMaxTextureSize()).WillOnce(Return(16384));
537 EXPECT_CALL(*test->mRenderEngine, getMaxViewportDims()).WillOnce(Return(16384));
538 status_t err =
539 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
540 LayerProperties::FORMAT);
541 ASSERT_EQ(NO_ERROR, err);
542 Mock::VerifyAndClear(test->mRenderEngine);
543
544 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
545 enqueueBuffer(test, layer);
546 Mock::VerifyAndClear(test->mMessageQueue);
547
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700548 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700549 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700550 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700551 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700552 }
553
554 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
555 setupLatchedBuffer(test, layer);
556 }
557
558 static void setupBufferLayerPostFrameCallExpectations(CompositionTest* test) {
559 // BufferLayer::onPostComposition(), when there is no present fence
560 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY, _))
561 .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE)));
562 }
563
564 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800565 if (!test->mDisplayOff) {
566 // TODO: Coverage of other values
567 EXPECT_CALL(*test->mComposer,
568 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
569 .Times(1);
570 // TODO: Coverage of other values for origin
571 EXPECT_CALL(*test->mComposer,
572 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
573 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
574 LayerProperties::HEIGHT})))
575 .Times(1);
576 EXPECT_CALL(*test->mComposer,
577 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
578 .Times(1);
579 // TODO: Coverage of other values
580 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
581 // TODO: Coverage of other values
582 EXPECT_CALL(*test->mComposer, setLayerInfo(HWC_DISPLAY, HWC_LAYER, 0u, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700583
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800584 // These expectations retire on saturation as the code path these
585 // expectations are for appears to make an extra call to them.
586 // TODO: Investigate this extra call
587 EXPECT_CALL(*test->mComposer,
588 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
589 .Times(AtLeast(1))
590 .RetiresOnSaturation();
591 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700592 }
593
594 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800595 if (!test->mDisplayOff) {
596 EXPECT_CALL(*test->mComposer,
597 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
598 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
599 LayerProperties::HEIGHT})))
600 .Times(1);
601 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700602 }
603
604 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800605 if (!test->mDisplayOff) {
606 EXPECT_CALL(*test->mComposer,
607 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
608 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
609 .Times(1);
610 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700611 }
612
613 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800614 if (!test->mDisplayOff) {
615 EXPECT_CALL(*test->mComposer,
616 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
617 std::vector<IComposerClient::Rect>(
618 {IComposerClient::Rect(
619 {0, 0, LayerProperties::WIDTH,
620 LayerProperties::HEIGHT})})))
621 .Times(1);
622 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700623 }
624
625 static void setupHwcSetPerFrameColorCallExpectations(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);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700629
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800630 // TODO: use COLOR
631 EXPECT_CALL(*test->mComposer,
632 setLayerColor(HWC_DISPLAY, HWC_LAYER,
633 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
634 .Times(1);
635 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700636 }
637
638 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800639 if (!test->mDisplayOff) {
640 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
641 .Times(1);
642 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
643 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700644
645 setupBufferLayerPostFrameCallExpectations(test);
646 }
647
648 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000649 EXPECT_CALL(*test->mRenderEngine, drawLayers)
650 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800651 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700652 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800653 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000654 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
655 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
656 displaySettings.physicalDisplay);
657 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
658 displaySettings.clip);
659 // screen capture adds an additional color layer as an alpha
660 // prefill, so gtet the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800661 if (layerSettings.empty()) {
662 ADD_FAILURE() << "layerSettings was not expected to be empty in "
663 "setupREBufferCompositionCommonCallExpectations "
664 "verification lambda";
665 return NO_ERROR;
666 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800667 const renderengine::LayerSettings* layer = layerSettings.back();
668 EXPECT_THAT(layer->source.buffer.buffer, Not(IsNull()));
669 EXPECT_THAT(layer->source.buffer.fence, Not(IsNull()));
670 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer->source.buffer.textureName);
671 EXPECT_EQ(false, layer->source.buffer.isY410BT2020);
672 EXPECT_EQ(true, layer->source.buffer.usePremultipliedAlpha);
673 EXPECT_EQ(false, layer->source.buffer.isOpaque);
674 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
675 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
676 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000677 return NO_ERROR;
678 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700679 }
680
681 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
682 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700683 }
684
685 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
686 setupREBufferCompositionCallExpectations(test);
687 }
688
689 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
690 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
691 }
692
693 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
694 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
695 }
696
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700697 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000698 EXPECT_CALL(*test->mRenderEngine, drawLayers)
699 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800700 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700701 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800702 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000703 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
704 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
705 displaySettings.physicalDisplay);
706 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
707 displaySettings.clip);
708 // screen capture adds an additional color layer as an alpha
709 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800710 if (layerSettings.empty()) {
711 ADD_FAILURE()
712 << "layerSettings was not expected to be empty in "
713 "setupREColorCompositionCallExpectations verification lambda";
714 return NO_ERROR;
715 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800716 const renderengine::LayerSettings* layer = layerSettings.back();
717 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000718 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
719 LayerProperties::COLOR[2]),
Vishnu Nair9b079a22020-01-21 14:36:08 -0800720 layer->source.solidColor);
721 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
722 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
723 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000724 return NO_ERROR;
725 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700726 }
727
728 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
729 setupREColorCompositionCallExpectations(test);
730 }
731};
732
733struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
734
Vishnu Nairfa247b12020-02-11 08:58:26 -0800735struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800736 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
737};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700738
739struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
740 using Base = BaseLayerProperties<SidebandLayerProperties>;
741 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
742
743 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
744 sp<NativeHandle> stream =
745 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
746 false);
747 test->mFlinger.setLayerSidebandStream(layer, stream);
748 }
749
750 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
751 EXPECT_CALL(*test->mComposer,
752 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
753 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
754 .Times(1);
755 }
756
757 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
758 EXPECT_CALL(*test->mComposer,
759 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
760 reinterpret_cast<native_handle_t*>(
761 DEFAULT_SIDEBAND_STREAM)))
762 .WillOnce(Return(Error::NONE));
763
764 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
765 }
766
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000767 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700768};
769
770struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> {
771 using Base = BaseLayerProperties<SecureLayerProperties>;
772
773 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
774
775 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000776 EXPECT_CALL(*test->mRenderEngine, drawLayers)
777 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800778 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700779 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800780 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000781 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
782 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
783 displaySettings.physicalDisplay);
784 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
785 displaySettings.clip);
786 // screen capture adds an additional color layer as an alpha
787 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800788 if (layerSettings.empty()) {
789 ADD_FAILURE() << "layerSettings was not expected to be empty in "
790 "setupInsecureREBufferCompositionCommonCallExpectations "
791 "verification lambda";
792 return NO_ERROR;
793 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800794 const renderengine::LayerSettings* layer = layerSettings.back();
795 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
796 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer->source.solidColor);
797 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
798 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
799 EXPECT_EQ(1.0f, layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000800 return NO_ERROR;
801 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700802 }
803
804 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
805 setupInsecureREBufferCompositionCommonCallExpectations(test);
806 Base::setupBufferLayerPostFrameCallExpectations(test);
807 }
808
809 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
810 setupInsecureREBufferCompositionCommonCallExpectations(test);
811 }
812};
813
814struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
815 using Base = BaseLayerProperties<CursorLayerProperties>;
816
817 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
818 Base::setupLayerState(test, layer);
819 test->mFlinger.setLayerPotentialCursor(layer, true);
820 }
821};
822
823struct NoLayerVariant {
824 using FlingerLayerType = sp<BufferQueueLayer>;
825
826 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
827 static void injectLayer(CompositionTest*, FlingerLayerType) {}
828 static void cleanupInjectedLayers(CompositionTest*) {}
829
830 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
831 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
832};
833
834template <typename LayerProperties>
835struct BaseLayerVariant {
836 template <typename L, typename F>
837 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
838 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0);
839
840 sp<L> layer = factory();
841
Dominik Laskowski49cea512019-11-12 14:13:23 -0800842 // Layer should be registered with scheduler.
843 EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize());
844
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700845 Mock::VerifyAndClear(test->mComposer);
846 Mock::VerifyAndClear(test->mRenderEngine);
847 Mock::VerifyAndClear(test->mMessageQueue);
848
849 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
850 layerDrawingState.layerStack = DEFAULT_LAYER_STACK;
851 layerDrawingState.active.w = 100;
852 layerDrawingState.active.h = 100;
853 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
854 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700855 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700856
857 return layer;
858 }
859
860 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
861 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
862 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
863
Lloyd Piquede196652020-01-22 17:29:58 -0800864 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
865 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700866 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
867 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700868
869 Mock::VerifyAndClear(test->mComposer);
870
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700871 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
872 }
873
874 static void cleanupInjectedLayers(CompositionTest* test) {
875 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
876 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800877
Lloyd Pique01c77c12019-04-17 12:48:32 -0700878 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700879 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800880
881 // Layer should be unregistered with scheduler.
882 test->mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
883 EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700884 }
885};
886
887template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800888struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700889 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800890 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700891
892 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800893 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
894 return new EffectLayer(
895 LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(), "test-layer",
896 LayerProperties::WIDTH, LayerProperties::HEIGHT,
897 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700898 });
Vishnu Nair60356342018-11-13 13:00:45 -0800899
900 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
901 layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700902 return layer;
903 }
904
905 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700906 LayerProperties::setupREColorCompositionCallExpectations(test);
907 }
908
909 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
910 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
911 }
912
913 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
914 LayerProperties::setupHwcSetGeometryCallExpectations(test);
915 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
916 }
917
918 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
919 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
920 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
921 }
922};
923
924template <typename LayerProperties>
925struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
926 using Base = BaseLayerVariant<LayerProperties>;
927 using FlingerLayerType = sp<BufferQueueLayer>;
928
929 static FlingerLayerType createLayer(CompositionTest* test) {
930 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
931
932 FlingerLayerType layer =
933 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
chaviwb4c6e582019-08-16 14:35:07 -0700934 sp<Client> client;
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700935 LayerCreationArgs args(test->mFlinger.mFlinger.get(), client, "test-layer",
936 LayerProperties::WIDTH, LayerProperties::HEIGHT,
937 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700938 args.textureName = test->mFlinger.mutableTexturePool().back();
939 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700940 });
941
942 LayerProperties::setupLayerState(test, layer);
943
944 return layer;
945 }
946
947 static void cleanupInjectedLayers(CompositionTest* test) {
Dan Stoza67765d82019-05-07 14:58:27 -0700948 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700949 Base::cleanupInjectedLayers(test);
950 }
951
952 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
953 LayerProperties::setupHwcSetGeometryCallExpectations(test);
954 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
955 }
956
957 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
958 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
959 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
960 }
961
962 static void setupRECompositionCallExpectations(CompositionTest* test) {
963 LayerProperties::setupREBufferCompositionCallExpectations(test);
964 }
965
966 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
967 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
968 }
969
970 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
971 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
972 }
973
974 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
975 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
976 }
977};
978
979/* ------------------------------------------------------------------------
980 * Variants to control how the composition type is changed
981 */
982
983struct NoCompositionTypeVariant {
984 static void setupHwcSetCallExpectations(CompositionTest*) {}
985
986 static void setupHwcGetCallExpectations(CompositionTest* test) {
987 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
988 }
989};
990
991template <IComposerClient::Composition CompositionType>
992struct KeepCompositionTypeVariant {
Peiyong Line9d809e2020-04-14 13:10:48 -0700993 static constexpr hal::Composition TYPE = CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700994
995 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800996 if (!test->mDisplayOff) {
997 EXPECT_CALL(*test->mComposer,
998 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
999 .Times(1);
1000 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001001 }
1002
1003 static void setupHwcGetCallExpectations(CompositionTest* test) {
1004 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1005 }
1006};
1007
1008template <IComposerClient::Composition InitialCompositionType,
1009 IComposerClient::Composition FinalCompositionType>
1010struct ChangeCompositionTypeVariant {
Peiyong Line9d809e2020-04-14 13:10:48 -07001011 static constexpr hal::Composition TYPE = FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001012
1013 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001014 if (!test->mDisplayOff) {
1015 EXPECT_CALL(*test->mComposer,
1016 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1017 .Times(1);
1018 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001019 }
1020
1021 static void setupHwcGetCallExpectations(CompositionTest* test) {
1022 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1023 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1024 static_cast<Hwc2::Layer>(HWC_LAYER)}),
1025 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
1026 FinalCompositionType}),
1027 Return(Error::NONE)));
1028 }
1029};
1030
1031/* ------------------------------------------------------------------------
1032 * Variants to select how the composition is expected to be handled
1033 */
1034
1035struct CompositionResultBaseVariant {
1036 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1037
1038 template <typename Case>
1039 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1040 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1041 }
1042
1043 template <typename Case>
1044 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1045 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1046 }
1047};
1048
1049struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1050 template <typename Case>
1051 static void setupCallExpectations(CompositionTest* test) {
1052 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1053 Case::Display::setupHwcCompositionCallExpectations(test);
1054 }
1055};
1056
1057struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1058 template <typename Case>
1059 static void setupCallExpectations(CompositionTest* test) {
1060 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1061 Case::Display::setupHwcCompositionCallExpectations(test);
1062 }
1063};
1064
1065struct RECompositionResultVariant : public CompositionResultBaseVariant {
1066 template <typename Case>
1067 static void setupCallExpectations(CompositionTest* test) {
1068 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001069 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001070 Case::Display::setupRECompositionCallExpectations(test);
1071 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1072 }
1073};
1074
Lloyd Pique66d68602019-02-13 14:23:31 -08001075struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001076 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piquef5275482019-01-29 18:42:42 -08001077 const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay);
1078 LOG_FATAL_IF(!outputLayer);
1079 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001080 }
1081
1082 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001083 static void setupCallExpectations(CompositionTest* test) {
1084 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1085 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1086 Case::Display::setupRECompositionCallExpectations(test);
1087 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1088 }
1089
1090 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001091 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1092
1093 template <typename Case>
1094 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1095};
1096
Lloyd Pique4fe29402019-08-12 16:51:24 -07001097struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1098 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1099 test->mFlinger.mutableDebugDisableHWC() = true;
1100 }
1101
1102 template <typename Case>
1103 static void setupCallExpectations(CompositionTest* test) {
1104 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1105 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1106 Case::Display::setupRECompositionCallExpectations(test);
1107 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1108 }
1109
1110 template <typename Case>
1111 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1112
1113 template <typename Case>
1114 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1115};
1116
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001117struct EmptyScreenshotResultVariant {
1118 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1119
1120 template <typename Case>
1121 static void setupCallExpectations(CompositionTest*) {}
1122};
1123
1124struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1125 using Base = EmptyScreenshotResultVariant;
1126
1127 template <typename Case>
1128 static void setupCallExpectations(CompositionTest* test) {
1129 Base::template setupCallExpectations<Case>(test);
1130 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1131 }
1132};
1133
1134/* ------------------------------------------------------------------------
1135 * Composition test case, containing all the variants being tested
1136 */
1137
1138template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1139 typename CompositionResultCase>
1140struct CompositionCase {
1141 using ThisCase =
1142 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1143 using Display = DisplayCase;
1144 using Layer = LayerCase;
1145 using CompositionType = CompositionTypeCase;
1146 using CompositionResult = CompositionResultCase;
1147
1148 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001149 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001150 Display::setupPreconditions(test);
1151
1152 auto layer = Layer::createLayer(test);
1153 Layer::injectLayer(test, layer);
1154 CompositionResult::setupLayerState(test, layer);
1155 }
1156
1157 static void setupForDirtyGeometry(CompositionTest* test) {
1158 setupCommon(test);
1159
1160 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1161 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1162 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1163 CompositionResult::template setupCallExpectations<ThisCase>(test);
1164 }
1165
1166 static void setupForDirtyFrame(CompositionTest* test) {
1167 setupCommon(test);
1168
1169 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1170 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1171 CompositionResult::template setupCallExpectations<ThisCase>(test);
1172 }
1173
1174 static void setupForScreenCapture(CompositionTest* test) {
1175 setupCommon(test);
1176
1177 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1178 CompositionResult::template setupCallExpectations<ThisCase>(test);
1179 }
1180
1181 static void cleanup(CompositionTest* test) {
1182 Layer::cleanupInjectedLayers(test);
1183
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001184 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1185 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1186 ->mutableLayers()
1187 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001188 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001189 }
1190};
1191
1192/* ------------------------------------------------------------------------
1193 * Composition cases to test
1194 */
1195
1196TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1197 displayRefreshCompositionDirtyGeometry<
1198 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1199 NoCompositionResultVariant>>();
1200}
1201
1202TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1203 displayRefreshCompositionDirtyFrame<
1204 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1205 NoCompositionResultVariant>>();
1206}
1207
1208TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1209 captureScreenComposition<
1210 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1211 EmptyScreenshotResultVariant>>();
1212}
1213
1214/* ------------------------------------------------------------------------
1215 * Simple buffer layers
1216 */
1217
1218TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1219 displayRefreshCompositionDirtyGeometry<
1220 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1221 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1222 HwcCompositionResultVariant>>();
1223}
1224
1225TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1226 displayRefreshCompositionDirtyFrame<
1227 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1228 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1229 HwcCompositionResultVariant>>();
1230}
1231
1232TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1233 displayRefreshCompositionDirtyFrame<
1234 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1235 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1236 IComposerClient::Composition::CLIENT>,
1237 RECompositionResultVariant>>();
1238}
1239
1240TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1241 captureScreenComposition<
1242 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1243 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1244}
1245
1246/* ------------------------------------------------------------------------
1247 * Single-color layers
1248 */
1249
Vishnu Nairfa247b12020-02-11 08:58:26 -08001250TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001251 displayRefreshCompositionDirtyGeometry<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001252 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001253 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1254 HwcCompositionResultVariant>>();
1255}
1256
Vishnu Nairfa247b12020-02-11 08:58:26 -08001257TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001258 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001259 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001260 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1261 HwcCompositionResultVariant>>();
1262}
1263
Vishnu Nairfa247b12020-02-11 08:58:26 -08001264TEST_F(CompositionTest, REComposedEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001265 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001266 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001267 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1268 IComposerClient::Composition::CLIENT>,
1269 RECompositionResultVariant>>();
1270}
1271
Vishnu Nairfa247b12020-02-11 08:58:26 -08001272TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001273 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001274 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001275 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1276}
1277
1278/* ------------------------------------------------------------------------
1279 * Layers with sideband buffers
1280 */
1281
1282TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1283 displayRefreshCompositionDirtyGeometry<
1284 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1285 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1286 HwcCompositionResultVariant>>();
1287}
1288
1289TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1290 displayRefreshCompositionDirtyFrame<
1291 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1292 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1293 HwcCompositionResultVariant>>();
1294}
1295
1296TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1297 displayRefreshCompositionDirtyFrame<
1298 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1299 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1300 IComposerClient::Composition::CLIENT>,
1301 RECompositionResultVariant>>();
1302}
1303
1304TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1305 captureScreenComposition<
1306 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1307 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1308}
1309
1310/* ------------------------------------------------------------------------
1311 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1312 */
1313
1314TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1315 displayRefreshCompositionDirtyGeometry<
1316 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1317 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1318 HwcCompositionResultVariant>>();
1319}
1320
1321TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1322 displayRefreshCompositionDirtyFrame<
1323 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1324 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1325 HwcCompositionResultVariant>>();
1326}
1327
1328TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1329 displayRefreshCompositionDirtyFrame<
1330 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1331 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1332 IComposerClient::Composition::CLIENT>,
1333 RECompositionResultVariant>>();
1334}
1335
1336TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1337 captureScreenComposition<
1338 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1339 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1340}
1341
1342/* ------------------------------------------------------------------------
1343 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1344 */
1345
1346TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1347 displayRefreshCompositionDirtyGeometry<
1348 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1349 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1350 ForcedClientCompositionResultVariant>>();
1351}
1352
1353TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1354 displayRefreshCompositionDirtyFrame<
1355 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1356 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1357 ForcedClientCompositionResultVariant>>();
1358}
1359
1360TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1361 captureScreenComposition<
1362 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1363 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1364}
1365
1366/* ------------------------------------------------------------------------
1367 * Cursor layers
1368 */
1369
1370TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1371 displayRefreshCompositionDirtyGeometry<
1372 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1373 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1374 HwcCompositionResultVariant>>();
1375}
1376
1377TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1378 displayRefreshCompositionDirtyFrame<
1379 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1380 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1381 HwcCompositionResultVariant>>();
1382}
1383
1384TEST_F(CompositionTest, REComposedCursorLayer) {
1385 displayRefreshCompositionDirtyFrame<
1386 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1387 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1388 IComposerClient::Composition::CLIENT>,
1389 RECompositionResultVariant>>();
1390}
1391
1392TEST_F(CompositionTest, captureScreenCursorLayer) {
1393 captureScreenComposition<
1394 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1395 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1396}
1397
1398/* ------------------------------------------------------------------------
1399 * Simple buffer layer on a display which is powered off.
1400 */
1401
1402TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001403 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001404 displayRefreshCompositionDirtyGeometry<CompositionCase<
1405 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1406 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1407 HwcCompositionResultVariant>>();
1408}
1409
1410TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001411 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001412 displayRefreshCompositionDirtyFrame<CompositionCase<
1413 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1414 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1415 HwcCompositionResultVariant>>();
1416}
1417
1418TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001419 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001420 displayRefreshCompositionDirtyFrame<CompositionCase<
1421 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1422 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1423 IComposerClient::Composition::CLIENT>,
1424 RECompositionResultVariant>>();
1425}
1426
1427TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1428 captureScreenComposition<CompositionCase<
1429 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1430 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1431}
1432
Lloyd Pique4fe29402019-08-12 16:51:24 -07001433/* ------------------------------------------------------------------------
1434 * Client composition forced through debug/developer settings
1435 */
1436
1437TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
1438 displayRefreshCompositionDirtyGeometry<
1439 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1440 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1441 ForcedClientCompositionViaDebugOptionResultVariant>>();
1442}
1443
1444TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
1445 displayRefreshCompositionDirtyFrame<
1446 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1447 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1448 ForcedClientCompositionViaDebugOptionResultVariant>>();
1449}
1450
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001451} // namespace
1452} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001453
1454// TODO(b/129481165): remove the #pragma below and fix conversion issues
1455#pragma clang diagnostic pop // ignored "-Wconversion"