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