blob: 867bb825e3221181bad735bd1a1425054d590e25 [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();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700119 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
120 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
121
122 Mock::VerifyAndClear(mComposer);
123 }
124
Ana Krulecafb45842019-02-13 13:33:03 -0800125 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700126 auto eventThread = std::make_unique<mock::EventThread>();
127 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800128
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700129 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700130 EXPECT_CALL(*eventThread, createEventConnection(_, _))
131 .WillOnce(Return(
132 new EventThreadConnection(eventThread.get(), ResyncCallback(),
133 ISurfaceComposer::eConfigChangedSuppress)));
134
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700135 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700136 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
137 .WillOnce(Return(
138 new EventThreadConnection(sfEventThread.get(), ResyncCallback(),
139 ISurfaceComposer::eConfigChangedSuppress)));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700140
141 auto primaryDispSync = std::make_unique<mock::DispSync>();
142
143 EXPECT_CALL(*primaryDispSync, computeNextRefresh(0)).WillRepeatedly(Return(0));
144 EXPECT_CALL(*primaryDispSync, getPeriod())
145 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE));
146 EXPECT_CALL(*primaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
147
148 mFlinger.setupScheduler(std::move(primaryDispSync),
149 std::make_unique<mock::EventControlThread>(),
150 std::move(eventThread), std::move(sfEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800151 }
152
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700153 void setupForceGeometryDirty() {
154 // TODO: This requires the visible region and other related
155 // state to be set, and is problematic for BufferLayers since they are
156 // not visible without a buffer (and setting up a buffer looks like a
157 // pain)
158 // mFlinger.mutableVisibleRegionsDirty() = true;
159
160 mFlinger.mutableGeometryInvalid() = true;
161 }
162
163 template <typename Case>
164 void displayRefreshCompositionDirtyGeometry();
165
166 template <typename Case>
167 void displayRefreshCompositionDirtyFrame();
168
169 template <typename Case>
170 void captureScreenComposition();
171
172 std::unordered_set<HWC2::Capability> mDefaultCapabilities = {HWC2::Capability::SidebandStream};
173
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800174 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700175 TestableSurfaceFlinger mFlinger;
176 sp<DisplayDevice> mDisplay;
177 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700178 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
179 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700180 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700181
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800182 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
183 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
184
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700185 Hwc2::mock::Composer* mComposer = nullptr;
186 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800187 mock::TimeStats* mTimeStats = new mock::TimeStats();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700188 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700189
190 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
191
192 sp<GraphicBuffer> mCaptureScreenBuffer;
193};
194
195template <typename LayerCase>
196void CompositionTest::displayRefreshCompositionDirtyGeometry() {
197 setupForceGeometryDirty();
198 LayerCase::setupForDirtyGeometry(this);
199
200 // --------------------------------------------------------------------
201 // Invocation
202
203 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
204 mFlinger.onMessageReceived(MessageQueue::REFRESH);
205
206 LayerCase::cleanup(this);
207}
208
209template <typename LayerCase>
210void CompositionTest::displayRefreshCompositionDirtyFrame() {
211 LayerCase::setupForDirtyFrame(this);
212
213 // --------------------------------------------------------------------
214 // Invocation
215
216 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
217 mFlinger.onMessageReceived(MessageQueue::REFRESH);
218
219 LayerCase::cleanup(this);
220}
221
222template <typename LayerCase>
223void CompositionTest::captureScreenComposition() {
224 LayerCase::setupForScreenCapture(this);
225
226 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700227 constexpr bool useIdentityTransform = true;
228 constexpr bool forSystem = true;
229
230 DisplayRenderArea renderArea(mDisplay, sourceCrop, DEFAULT_DISPLAY_WIDTH,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700231 DEFAULT_DISPLAY_HEIGHT, ui::Dataspace::V0_SRGB,
232 ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700233
234 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw0e3479f2018-09-10 16:49:30 -0700235 return mFlinger.traverseLayersInDisplay(mDisplay, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700236 };
237
238 // TODO: Eliminate expensive/real allocation if possible.
239 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
240 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
241 mCaptureScreenBuffer = new GraphicBuffer(renderArea.getReqWidth(), renderArea.getReqHeight(),
242 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage, "screenshot");
243
244 int fd = -1;
245 status_t result =
246 mFlinger.captureScreenImplLocked(renderArea, traverseLayers, mCaptureScreenBuffer.get(),
247 useIdentityTransform, forSystem, &fd);
248 if (fd >= 0) {
249 close(fd);
250 }
251
252 EXPECT_EQ(NO_ERROR, result);
253
254 LayerCase::cleanup(this);
255}
256
257/* ------------------------------------------------------------------------
258 * Variants for each display configuration which can be tested
259 */
260
261template <typename Derived>
262struct BaseDisplayVariant {
263 static constexpr bool IS_SECURE = true;
264 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
265
266 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700267 EXPECT_CALL(*test->mComposer,
268 setPowerMode(HWC_DISPLAY,
269 static_cast<Hwc2::IComposerClient::PowerMode>(
270 Derived::INIT_POWER_MODE)))
271 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700272
Dominik Laskowski075d3172018-05-24 15:50:06 -0700273 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, HWC2::DisplayType::Physical,
274 true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700275 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700276 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700277 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800278 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700279
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800280 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
281 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
282 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
283 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
284 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
285 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
286 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Dominik Laskowski55c85402020-01-21 16:25:47 -0800287 test->mDisplay =
288 FakeDisplayDeviceInjector(test->mFlinger, DEFAULT_DISPLAY_ID,
289 DisplayConnectionType::Internal, true /* isPrimary */)
290 .setDisplaySurface(test->mDisplaySurface)
291 .setNativeWindow(test->mNativeWindow)
292 .setSecure(Derived::IS_SECURE)
293 .setPowerMode(Derived::INIT_POWER_MODE)
294 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800295 Mock::VerifyAndClear(test->mNativeWindow);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700296 test->mDisplay->setLayerStack(DEFAULT_LAYER_STACK);
297 }
298
299 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700300 static void setupPreconditionCallExpectations(CompositionTest* test) {
301 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
302 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
303 Return(Error::NONE)));
304 }
305
306 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700307 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
308 EXPECT_CALL(*test->mComposer,
309 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
310 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700311 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
312 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
313 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
314 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
315
316 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700317
318 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
319 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
320
321 Case::CompositionType::setupHwcSetCallExpectations(test);
322 Case::CompositionType::setupHwcGetCallExpectations(test);
323 }
324
325 template <typename Case>
326 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000327 EXPECT_CALL(*test->mRenderEngine, drawLayers)
328 .WillRepeatedly(
329 [](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800330 const std::vector<const renderengine::LayerSettings*>&,
Ana Krulecfc874ae2020-02-22 15:39:32 -0800331 const sp<GraphicBuffer>&, const bool, base::unique_fd&&,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800332 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000333 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
334 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
335 displaySettings.physicalDisplay);
336 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
337 displaySettings.clip);
338 return NO_ERROR;
339 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700340 }
341
342 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
343 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
344 }
345
346 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
347 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
348 }
349
350 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800351 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
352
Lloyd Pique542307f2018-10-19 13:24:08 -0700353 EXPECT_CALL(*test->mDisplaySurface,
354 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC))
355 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700356 }
357
Lloyd Pique66d68602019-02-13 14:23:31 -0800358 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
359 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
360 }
361
362 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
363 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1);
364 }
365
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700366 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700367 EXPECT_CALL(*test->mDisplaySurface,
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800368 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_GPU))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700369 .Times(1);
370 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
371 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
372
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800373 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
374 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
375 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
376 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000377 EXPECT_CALL(*test->mRenderEngine, drawLayers)
378 .WillRepeatedly(
379 [](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800380 const std::vector<const renderengine::LayerSettings*>&,
Ana Krulecfc874ae2020-02-22 15:39:32 -0800381 const sp<GraphicBuffer>&, const bool, base::unique_fd&&,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800382 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000383 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
384 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
385 displaySettings.physicalDisplay);
386 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
387 displaySettings.clip);
388 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
389 return NO_ERROR;
390 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700391 }
392
393 template <typename Case>
394 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
395 Case::Layer::setupRECompositionCallExpectations(test);
396 }
397
398 template <typename Case>
399 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
400 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700401 }
402};
403
404struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
405
406struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
407 static constexpr bool IS_SECURE = false;
408
409 template <typename Case>
410 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
411 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700412 }
413
414 template <typename Case>
415 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
416 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700417 }
418};
419
420struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
421 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_OFF;
422
423 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700424 static void setupPreconditionCallExpectations(CompositionTest*) {}
425
426 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700427 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800428 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
429
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700430 // TODO: This seems like an unnecessary call if display is powered off.
431 EXPECT_CALL(*test->mComposer,
432 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
433 .Times(1);
434
435 // TODO: This seems like an unnecessary call if display is powered off.
436 Case::CompositionType::setupHwcSetCallExpectations(test);
437 }
438
439 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800440 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
441 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700442
443 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800444 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
445
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700446 // TODO: This seems like an unnecessary call if display is powered off.
447 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
448 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
449 }
450
451 template <typename Case>
452 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
453};
454
455/* ------------------------------------------------------------------------
456 * Variants for each layer configuration which can be tested
457 */
458
459template <typename LayerProperties>
460struct BaseLayerProperties {
461 static constexpr uint32_t WIDTH = 100;
462 static constexpr uint32_t HEIGHT = 100;
463 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
464 static constexpr uint64_t USAGE =
465 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
466 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
467 static constexpr uint32_t SCALING_MODE = 0;
468 static constexpr uint32_t TRANSFORM = 0;
469 static constexpr uint32_t LAYER_FLAGS = 0;
470 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
471 static constexpr IComposerClient::BlendMode BLENDMODE =
472 IComposerClient::BlendMode::PREMULTIPLIED;
473
474 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
475 auto producer = layer->getProducer();
476
477 IGraphicBufferProducer::QueueBufferOutput qbo;
478 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
479 if (result != NO_ERROR) {
480 ALOGE("Failed to connect() (%d)", result);
481 return;
482 }
483
484 int slot;
485 sp<Fence> fence;
486 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
487 LayerProperties::HEIGHT, LayerProperties::FORMAT,
488 LayerProperties::USAGE, nullptr, nullptr);
489 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
490 ALOGE("Failed to dequeueBuffer() (%d)", result);
491 return;
492 }
493
494 sp<GraphicBuffer> buffer;
495 result = producer->requestBuffer(slot, &buffer);
496 if (result != NO_ERROR) {
497 ALOGE("Failed to requestBuffer() (%d)", result);
498 return;
499 }
500
501 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
502 LayerProperties::DATASPACE,
503 Rect(LayerProperties::WIDTH,
504 LayerProperties::HEIGHT),
505 LayerProperties::SCALING_MODE,
506 LayerProperties::TRANSFORM, Fence::NO_FENCE);
507 result = producer->queueBuffer(slot, qbi, &qbo);
508 if (result != NO_ERROR) {
509 ALOGE("Failed to queueBuffer (%d)", result);
510 return;
511 }
512 }
513
514 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
515 // TODO: Eliminate the complexity of actually creating a buffer
516 EXPECT_CALL(*test->mRenderEngine, getMaxTextureSize()).WillOnce(Return(16384));
517 EXPECT_CALL(*test->mRenderEngine, getMaxViewportDims()).WillOnce(Return(16384));
518 status_t err =
519 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
520 LayerProperties::FORMAT);
521 ASSERT_EQ(NO_ERROR, err);
522 Mock::VerifyAndClear(test->mRenderEngine);
523
524 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
525 enqueueBuffer(test, layer);
526 Mock::VerifyAndClear(test->mMessageQueue);
527
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700528 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700529 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700530 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700531 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700532 }
533
534 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
535 setupLatchedBuffer(test, layer);
536 }
537
538 static void setupBufferLayerPostFrameCallExpectations(CompositionTest* test) {
539 // BufferLayer::onPostComposition(), when there is no present fence
540 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY, _))
541 .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE)));
542 }
543
544 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800545 if (!test->mDisplayOff) {
546 // TODO: Coverage of other values
547 EXPECT_CALL(*test->mComposer,
548 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
549 .Times(1);
550 // TODO: Coverage of other values for origin
551 EXPECT_CALL(*test->mComposer,
552 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
553 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
554 LayerProperties::HEIGHT})))
555 .Times(1);
556 EXPECT_CALL(*test->mComposer,
557 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
558 .Times(1);
559 // TODO: Coverage of other values
560 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
561 // TODO: Coverage of other values
562 EXPECT_CALL(*test->mComposer, setLayerInfo(HWC_DISPLAY, HWC_LAYER, 0u, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700563
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800564 // These expectations retire on saturation as the code path these
565 // expectations are for appears to make an extra call to them.
566 // TODO: Investigate this extra call
567 EXPECT_CALL(*test->mComposer,
568 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
569 .Times(AtLeast(1))
570 .RetiresOnSaturation();
571 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700572 }
573
574 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800575 if (!test->mDisplayOff) {
576 EXPECT_CALL(*test->mComposer,
577 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
578 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
579 LayerProperties::HEIGHT})))
580 .Times(1);
581 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700582 }
583
584 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800585 if (!test->mDisplayOff) {
586 EXPECT_CALL(*test->mComposer,
587 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
588 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
589 .Times(1);
590 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700591 }
592
593 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800594 if (!test->mDisplayOff) {
595 EXPECT_CALL(*test->mComposer,
596 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
597 std::vector<IComposerClient::Rect>(
598 {IComposerClient::Rect(
599 {0, 0, LayerProperties::WIDTH,
600 LayerProperties::HEIGHT})})))
601 .Times(1);
602 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700603 }
604
605 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800606 if (!test->mDisplayOff) {
607 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
608 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700609
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800610 // TODO: use COLOR
611 EXPECT_CALL(*test->mComposer,
612 setLayerColor(HWC_DISPLAY, HWC_LAYER,
613 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
614 .Times(1);
615 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700616 }
617
618 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800619 if (!test->mDisplayOff) {
620 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
621 .Times(1);
622 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
623 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700624
625 setupBufferLayerPostFrameCallExpectations(test);
626 }
627
628 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000629 EXPECT_CALL(*test->mRenderEngine, drawLayers)
630 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800631 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Ana Krulecfc874ae2020-02-22 15:39:32 -0800632 const sp<GraphicBuffer>&, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800633 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000634 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
635 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
636 displaySettings.physicalDisplay);
637 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
638 displaySettings.clip);
639 // screen capture adds an additional color layer as an alpha
640 // prefill, so gtet the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800641 if (layerSettings.empty()) {
642 ADD_FAILURE() << "layerSettings was not expected to be empty in "
643 "setupREBufferCompositionCommonCallExpectations "
644 "verification lambda";
645 return NO_ERROR;
646 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800647 const renderengine::LayerSettings* layer = layerSettings.back();
648 EXPECT_THAT(layer->source.buffer.buffer, Not(IsNull()));
649 EXPECT_THAT(layer->source.buffer.fence, Not(IsNull()));
650 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer->source.buffer.textureName);
651 EXPECT_EQ(false, layer->source.buffer.isY410BT2020);
652 EXPECT_EQ(true, layer->source.buffer.usePremultipliedAlpha);
653 EXPECT_EQ(false, layer->source.buffer.isOpaque);
654 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
655 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
656 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000657 return NO_ERROR;
658 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700659 }
660
661 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
662 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700663 }
664
665 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
666 setupREBufferCompositionCallExpectations(test);
667 }
668
669 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
670 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
671 }
672
673 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
674 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
675 }
676
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700677 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000678 EXPECT_CALL(*test->mRenderEngine, drawLayers)
679 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800680 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Ana Krulecfc874ae2020-02-22 15:39:32 -0800681 const sp<GraphicBuffer>&, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800682 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000683 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
684 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
685 displaySettings.physicalDisplay);
686 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
687 displaySettings.clip);
688 // screen capture adds an additional color layer as an alpha
689 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800690 if (layerSettings.empty()) {
691 ADD_FAILURE()
692 << "layerSettings was not expected to be empty in "
693 "setupREColorCompositionCallExpectations verification lambda";
694 return NO_ERROR;
695 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800696 const renderengine::LayerSettings* layer = layerSettings.back();
697 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000698 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
699 LayerProperties::COLOR[2]),
Vishnu Nair9b079a22020-01-21 14:36:08 -0800700 layer->source.solidColor);
701 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
702 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
703 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000704 return NO_ERROR;
705 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700706 }
707
708 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
709 setupREColorCompositionCallExpectations(test);
710 }
711};
712
713struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
714
Vishnu Nairfa247b12020-02-11 08:58:26 -0800715struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800716 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
717};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700718
719struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
720 using Base = BaseLayerProperties<SidebandLayerProperties>;
721 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
722
723 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
724 sp<NativeHandle> stream =
725 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
726 false);
727 test->mFlinger.setLayerSidebandStream(layer, stream);
728 }
729
730 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
731 EXPECT_CALL(*test->mComposer,
732 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
733 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
734 .Times(1);
735 }
736
737 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
738 EXPECT_CALL(*test->mComposer,
739 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
740 reinterpret_cast<native_handle_t*>(
741 DEFAULT_SIDEBAND_STREAM)))
742 .WillOnce(Return(Error::NONE));
743
744 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
745 }
746
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000747 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700748};
749
750struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> {
751 using Base = BaseLayerProperties<SecureLayerProperties>;
752
753 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
754
755 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000756 EXPECT_CALL(*test->mRenderEngine, drawLayers)
757 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800758 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Ana Krulecfc874ae2020-02-22 15:39:32 -0800759 const sp<GraphicBuffer>&, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800760 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000761 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
762 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
763 displaySettings.physicalDisplay);
764 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
765 displaySettings.clip);
766 // screen capture adds an additional color layer as an alpha
767 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800768 if (layerSettings.empty()) {
769 ADD_FAILURE() << "layerSettings was not expected to be empty in "
770 "setupInsecureREBufferCompositionCommonCallExpectations "
771 "verification lambda";
772 return NO_ERROR;
773 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800774 const renderengine::LayerSettings* layer = layerSettings.back();
775 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
776 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer->source.solidColor);
777 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
778 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
779 EXPECT_EQ(1.0f, layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000780 return NO_ERROR;
781 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700782 }
783
784 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
785 setupInsecureREBufferCompositionCommonCallExpectations(test);
786 Base::setupBufferLayerPostFrameCallExpectations(test);
787 }
788
789 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
790 setupInsecureREBufferCompositionCommonCallExpectations(test);
791 }
792};
793
794struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
795 using Base = BaseLayerProperties<CursorLayerProperties>;
796
797 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
798 Base::setupLayerState(test, layer);
799 test->mFlinger.setLayerPotentialCursor(layer, true);
800 }
801};
802
803struct NoLayerVariant {
804 using FlingerLayerType = sp<BufferQueueLayer>;
805
806 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
807 static void injectLayer(CompositionTest*, FlingerLayerType) {}
808 static void cleanupInjectedLayers(CompositionTest*) {}
809
810 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
811 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
812};
813
814template <typename LayerProperties>
815struct BaseLayerVariant {
816 template <typename L, typename F>
817 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
818 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0);
819
820 sp<L> layer = factory();
821
Dominik Laskowski49cea512019-11-12 14:13:23 -0800822 // Layer should be registered with scheduler.
823 EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize());
824
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700825 Mock::VerifyAndClear(test->mComposer);
826 Mock::VerifyAndClear(test->mRenderEngine);
827 Mock::VerifyAndClear(test->mMessageQueue);
828
829 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
830 layerDrawingState.layerStack = DEFAULT_LAYER_STACK;
831 layerDrawingState.active.w = 100;
832 layerDrawingState.active.h = 100;
833 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
834 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700835 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700836
837 return layer;
838 }
839
840 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
841 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
842 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
843
Lloyd Piquede196652020-01-22 17:29:58 -0800844 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
845 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700846 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
847 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700848
849 Mock::VerifyAndClear(test->mComposer);
850
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700851 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
852 }
853
854 static void cleanupInjectedLayers(CompositionTest* test) {
855 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
856 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800857
Lloyd Pique01c77c12019-04-17 12:48:32 -0700858 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700859 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800860
861 // Layer should be unregistered with scheduler.
862 test->mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
863 EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700864 }
865};
866
867template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800868struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700869 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800870 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700871
872 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800873 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
874 return new EffectLayer(
875 LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(), "test-layer",
876 LayerProperties::WIDTH, LayerProperties::HEIGHT,
877 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700878 });
Vishnu Nair60356342018-11-13 13:00:45 -0800879
880 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
881 layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700882 return layer;
883 }
884
885 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700886 LayerProperties::setupREColorCompositionCallExpectations(test);
887 }
888
889 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
890 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
891 }
892
893 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
894 LayerProperties::setupHwcSetGeometryCallExpectations(test);
895 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
896 }
897
898 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
899 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
900 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
901 }
902};
903
904template <typename LayerProperties>
905struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
906 using Base = BaseLayerVariant<LayerProperties>;
907 using FlingerLayerType = sp<BufferQueueLayer>;
908
909 static FlingerLayerType createLayer(CompositionTest* test) {
910 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
911
912 FlingerLayerType layer =
913 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
chaviwb4c6e582019-08-16 14:35:07 -0700914 sp<Client> client;
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700915 LayerCreationArgs args(test->mFlinger.mFlinger.get(), client, "test-layer",
916 LayerProperties::WIDTH, LayerProperties::HEIGHT,
917 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700918 args.textureName = test->mFlinger.mutableTexturePool().back();
919 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700920 });
921
922 LayerProperties::setupLayerState(test, layer);
923
924 return layer;
925 }
926
927 static void cleanupInjectedLayers(CompositionTest* test) {
Dan Stoza67765d82019-05-07 14:58:27 -0700928 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700929 Base::cleanupInjectedLayers(test);
930 }
931
932 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
933 LayerProperties::setupHwcSetGeometryCallExpectations(test);
934 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
935 }
936
937 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
938 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
939 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
940 }
941
942 static void setupRECompositionCallExpectations(CompositionTest* test) {
943 LayerProperties::setupREBufferCompositionCallExpectations(test);
944 }
945
946 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
947 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
948 }
949
950 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
951 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
952 }
953
954 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
955 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
956 }
957};
958
959/* ------------------------------------------------------------------------
960 * Variants to control how the composition type is changed
961 */
962
963struct NoCompositionTypeVariant {
964 static void setupHwcSetCallExpectations(CompositionTest*) {}
965
966 static void setupHwcGetCallExpectations(CompositionTest* test) {
967 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
968 }
969};
970
971template <IComposerClient::Composition CompositionType>
972struct KeepCompositionTypeVariant {
973 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(CompositionType);
974
975 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800976 if (!test->mDisplayOff) {
977 EXPECT_CALL(*test->mComposer,
978 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
979 .Times(1);
980 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700981 }
982
983 static void setupHwcGetCallExpectations(CompositionTest* test) {
984 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
985 }
986};
987
988template <IComposerClient::Composition InitialCompositionType,
989 IComposerClient::Composition FinalCompositionType>
990struct ChangeCompositionTypeVariant {
991 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(FinalCompositionType);
992
993 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800994 if (!test->mDisplayOff) {
995 EXPECT_CALL(*test->mComposer,
996 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
997 .Times(1);
998 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700999 }
1000
1001 static void setupHwcGetCallExpectations(CompositionTest* test) {
1002 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1003 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1004 static_cast<Hwc2::Layer>(HWC_LAYER)}),
1005 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
1006 FinalCompositionType}),
1007 Return(Error::NONE)));
1008 }
1009};
1010
1011/* ------------------------------------------------------------------------
1012 * Variants to select how the composition is expected to be handled
1013 */
1014
1015struct CompositionResultBaseVariant {
1016 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1017
1018 template <typename Case>
1019 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1020 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1021 }
1022
1023 template <typename Case>
1024 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1025 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1026 }
1027};
1028
1029struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1030 template <typename Case>
1031 static void setupCallExpectations(CompositionTest* test) {
1032 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1033 Case::Display::setupHwcCompositionCallExpectations(test);
1034 }
1035};
1036
1037struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1038 template <typename Case>
1039 static void setupCallExpectations(CompositionTest* test) {
1040 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1041 Case::Display::setupHwcCompositionCallExpectations(test);
1042 }
1043};
1044
1045struct RECompositionResultVariant : public CompositionResultBaseVariant {
1046 template <typename Case>
1047 static void setupCallExpectations(CompositionTest* test) {
1048 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001049 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001050 Case::Display::setupRECompositionCallExpectations(test);
1051 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1052 }
1053};
1054
Lloyd Pique66d68602019-02-13 14:23:31 -08001055struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001056 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piquef5275482019-01-29 18:42:42 -08001057 const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay);
1058 LOG_FATAL_IF(!outputLayer);
1059 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001060 }
1061
1062 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001063 static void setupCallExpectations(CompositionTest* test) {
1064 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1065 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1066 Case::Display::setupRECompositionCallExpectations(test);
1067 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1068 }
1069
1070 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001071 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1072
1073 template <typename Case>
1074 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1075};
1076
Lloyd Pique4fe29402019-08-12 16:51:24 -07001077struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1078 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1079 test->mFlinger.mutableDebugDisableHWC() = true;
1080 }
1081
1082 template <typename Case>
1083 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>
1091 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1092
1093 template <typename Case>
1094 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1095};
1096
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001097struct EmptyScreenshotResultVariant {
1098 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1099
1100 template <typename Case>
1101 static void setupCallExpectations(CompositionTest*) {}
1102};
1103
1104struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1105 using Base = EmptyScreenshotResultVariant;
1106
1107 template <typename Case>
1108 static void setupCallExpectations(CompositionTest* test) {
1109 Base::template setupCallExpectations<Case>(test);
1110 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1111 }
1112};
1113
1114/* ------------------------------------------------------------------------
1115 * Composition test case, containing all the variants being tested
1116 */
1117
1118template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1119 typename CompositionResultCase>
1120struct CompositionCase {
1121 using ThisCase =
1122 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1123 using Display = DisplayCase;
1124 using Layer = LayerCase;
1125 using CompositionType = CompositionTypeCase;
1126 using CompositionResult = CompositionResultCase;
1127
1128 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001129 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001130 Display::setupPreconditions(test);
1131
1132 auto layer = Layer::createLayer(test);
1133 Layer::injectLayer(test, layer);
1134 CompositionResult::setupLayerState(test, layer);
1135 }
1136
1137 static void setupForDirtyGeometry(CompositionTest* test) {
1138 setupCommon(test);
1139
1140 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1141 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1142 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1143 CompositionResult::template setupCallExpectations<ThisCase>(test);
1144 }
1145
1146 static void setupForDirtyFrame(CompositionTest* test) {
1147 setupCommon(test);
1148
1149 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1150 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1151 CompositionResult::template setupCallExpectations<ThisCase>(test);
1152 }
1153
1154 static void setupForScreenCapture(CompositionTest* test) {
1155 setupCommon(test);
1156
1157 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1158 CompositionResult::template setupCallExpectations<ThisCase>(test);
1159 }
1160
1161 static void cleanup(CompositionTest* test) {
1162 Layer::cleanupInjectedLayers(test);
1163
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001164 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1165 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1166 ->mutableLayers()
1167 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001168 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001169 }
1170};
1171
1172/* ------------------------------------------------------------------------
1173 * Composition cases to test
1174 */
1175
1176TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1177 displayRefreshCompositionDirtyGeometry<
1178 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1179 NoCompositionResultVariant>>();
1180}
1181
1182TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1183 displayRefreshCompositionDirtyFrame<
1184 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1185 NoCompositionResultVariant>>();
1186}
1187
1188TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1189 captureScreenComposition<
1190 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1191 EmptyScreenshotResultVariant>>();
1192}
1193
1194/* ------------------------------------------------------------------------
1195 * Simple buffer layers
1196 */
1197
1198TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1199 displayRefreshCompositionDirtyGeometry<
1200 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1201 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1202 HwcCompositionResultVariant>>();
1203}
1204
1205TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1206 displayRefreshCompositionDirtyFrame<
1207 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1208 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1209 HwcCompositionResultVariant>>();
1210}
1211
1212TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1213 displayRefreshCompositionDirtyFrame<
1214 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1215 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1216 IComposerClient::Composition::CLIENT>,
1217 RECompositionResultVariant>>();
1218}
1219
1220TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1221 captureScreenComposition<
1222 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1223 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1224}
1225
1226/* ------------------------------------------------------------------------
1227 * Single-color layers
1228 */
1229
Vishnu Nairfa247b12020-02-11 08:58:26 -08001230TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001231 displayRefreshCompositionDirtyGeometry<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001232 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001233 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1234 HwcCompositionResultVariant>>();
1235}
1236
Vishnu Nairfa247b12020-02-11 08:58:26 -08001237TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001238 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001239 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001240 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1241 HwcCompositionResultVariant>>();
1242}
1243
Vishnu Nairfa247b12020-02-11 08:58:26 -08001244TEST_F(CompositionTest, REComposedEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001245 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001246 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001247 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1248 IComposerClient::Composition::CLIENT>,
1249 RECompositionResultVariant>>();
1250}
1251
Vishnu Nairfa247b12020-02-11 08:58:26 -08001252TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001253 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001254 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001255 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1256}
1257
1258/* ------------------------------------------------------------------------
1259 * Layers with sideband buffers
1260 */
1261
1262TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1263 displayRefreshCompositionDirtyGeometry<
1264 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1265 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1266 HwcCompositionResultVariant>>();
1267}
1268
1269TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1270 displayRefreshCompositionDirtyFrame<
1271 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1272 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1273 HwcCompositionResultVariant>>();
1274}
1275
1276TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1277 displayRefreshCompositionDirtyFrame<
1278 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1279 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1280 IComposerClient::Composition::CLIENT>,
1281 RECompositionResultVariant>>();
1282}
1283
1284TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1285 captureScreenComposition<
1286 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1287 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1288}
1289
1290/* ------------------------------------------------------------------------
1291 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1292 */
1293
1294TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1295 displayRefreshCompositionDirtyGeometry<
1296 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1297 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1298 HwcCompositionResultVariant>>();
1299}
1300
1301TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1302 displayRefreshCompositionDirtyFrame<
1303 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1304 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1305 HwcCompositionResultVariant>>();
1306}
1307
1308TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1309 displayRefreshCompositionDirtyFrame<
1310 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1311 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1312 IComposerClient::Composition::CLIENT>,
1313 RECompositionResultVariant>>();
1314}
1315
1316TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1317 captureScreenComposition<
1318 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1319 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1320}
1321
1322/* ------------------------------------------------------------------------
1323 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1324 */
1325
1326TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1327 displayRefreshCompositionDirtyGeometry<
1328 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1329 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1330 ForcedClientCompositionResultVariant>>();
1331}
1332
1333TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1334 displayRefreshCompositionDirtyFrame<
1335 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1336 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1337 ForcedClientCompositionResultVariant>>();
1338}
1339
1340TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1341 captureScreenComposition<
1342 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1343 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1344}
1345
1346/* ------------------------------------------------------------------------
1347 * Cursor layers
1348 */
1349
1350TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1351 displayRefreshCompositionDirtyGeometry<
1352 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1353 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1354 HwcCompositionResultVariant>>();
1355}
1356
1357TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1358 displayRefreshCompositionDirtyFrame<
1359 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1360 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1361 HwcCompositionResultVariant>>();
1362}
1363
1364TEST_F(CompositionTest, REComposedCursorLayer) {
1365 displayRefreshCompositionDirtyFrame<
1366 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1367 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1368 IComposerClient::Composition::CLIENT>,
1369 RECompositionResultVariant>>();
1370}
1371
1372TEST_F(CompositionTest, captureScreenCursorLayer) {
1373 captureScreenComposition<
1374 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1375 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1376}
1377
1378/* ------------------------------------------------------------------------
1379 * Simple buffer layer on a display which is powered off.
1380 */
1381
1382TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001383 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001384 displayRefreshCompositionDirtyGeometry<CompositionCase<
1385 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1386 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1387 HwcCompositionResultVariant>>();
1388}
1389
1390TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001391 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001392 displayRefreshCompositionDirtyFrame<CompositionCase<
1393 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1394 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1395 HwcCompositionResultVariant>>();
1396}
1397
1398TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001399 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001400 displayRefreshCompositionDirtyFrame<CompositionCase<
1401 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1402 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1403 IComposerClient::Composition::CLIENT>,
1404 RECompositionResultVariant>>();
1405}
1406
1407TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1408 captureScreenComposition<CompositionCase<
1409 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1410 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1411}
1412
Lloyd Pique4fe29402019-08-12 16:51:24 -07001413/* ------------------------------------------------------------------------
1414 * Client composition forced through debug/developer settings
1415 */
1416
1417TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
1418 displayRefreshCompositionDirtyGeometry<
1419 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1420 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1421 ForcedClientCompositionViaDebugOptionResultVariant>>();
1422}
1423
1424TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
1425 displayRefreshCompositionDirtyFrame<
1426 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1427 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1428 ForcedClientCompositionViaDebugOptionResultVariant>>();
1429}
1430
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001431} // namespace
1432} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001433
1434// TODO(b/129481165): remove the #pragma below and fix conversion issues
1435#pragma clang diagnostic pop // ignored "-Wconversion"