blob: 27e2e8dba3e0889fafc64214e4143e4f650c2460 [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 Laskowski55c85402020-01-21 16:25:47 -0800289 test->mDisplay =
290 FakeDisplayDeviceInjector(test->mFlinger, DEFAULT_DISPLAY_ID,
291 DisplayConnectionType::Internal, true /* isPrimary */)
292 .setDisplaySurface(test->mDisplaySurface)
293 .setNativeWindow(test->mNativeWindow)
294 .setSecure(Derived::IS_SECURE)
295 .setPowerMode(Derived::INIT_POWER_MODE)
296 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800297 Mock::VerifyAndClear(test->mNativeWindow);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700298 test->mDisplay->setLayerStack(DEFAULT_LAYER_STACK);
299 }
300
301 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700302 static void setupPreconditionCallExpectations(CompositionTest* test) {
303 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
304 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
305 Return(Error::NONE)));
306 }
307
308 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700309 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
310 EXPECT_CALL(*test->mComposer,
311 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
312 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700313 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
314 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
315 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
316 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
317
318 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700319
320 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
321 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
322
323 Case::CompositionType::setupHwcSetCallExpectations(test);
324 Case::CompositionType::setupHwcGetCallExpectations(test);
325 }
326
327 template <typename Case>
328 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000329 EXPECT_CALL(*test->mRenderEngine, drawLayers)
330 .WillRepeatedly(
331 [](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800332 const std::vector<const renderengine::LayerSettings*>&,
333 ANativeWindowBuffer*, const bool, base::unique_fd&&,
334 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000335 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
336 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
337 displaySettings.physicalDisplay);
338 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
339 displaySettings.clip);
340 return NO_ERROR;
341 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700342 }
343
344 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
345 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
346 }
347
348 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
349 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
350 }
351
352 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800353 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
354
Lloyd Pique542307f2018-10-19 13:24:08 -0700355 EXPECT_CALL(*test->mDisplaySurface,
356 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC))
357 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700358 }
359
Lloyd Pique66d68602019-02-13 14:23:31 -0800360 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
361 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
362 }
363
364 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
365 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1);
366 }
367
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700368 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700369 EXPECT_CALL(*test->mDisplaySurface,
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800370 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_GPU))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700371 .Times(1);
372 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
373 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
374
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800375 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
376 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
377 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
378 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000379 EXPECT_CALL(*test->mRenderEngine, drawLayers)
380 .WillRepeatedly(
381 [](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800382 const std::vector<const renderengine::LayerSettings*>&,
383 ANativeWindowBuffer*, const bool, base::unique_fd&&,
384 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000385 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
386 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
387 displaySettings.physicalDisplay);
388 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
389 displaySettings.clip);
390 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
391 return NO_ERROR;
392 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700393 }
394
395 template <typename Case>
396 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
397 Case::Layer::setupRECompositionCallExpectations(test);
398 }
399
400 template <typename Case>
401 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
402 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700403 }
404};
405
406struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
407
408struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
409 static constexpr bool IS_SECURE = false;
410
411 template <typename Case>
412 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
413 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700414 }
415
416 template <typename Case>
417 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
418 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700419 }
420};
421
422struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
423 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_OFF;
424
425 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700426 static void setupPreconditionCallExpectations(CompositionTest*) {}
427
428 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700429 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800430 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
431
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700432 // TODO: This seems like an unnecessary call if display is powered off.
433 EXPECT_CALL(*test->mComposer,
434 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
435 .Times(1);
436
437 // TODO: This seems like an unnecessary call if display is powered off.
438 Case::CompositionType::setupHwcSetCallExpectations(test);
439 }
440
441 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800442 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
443 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700444
445 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800446 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
447
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700448 // TODO: This seems like an unnecessary call if display is powered off.
449 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
450 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
451 }
452
453 template <typename Case>
454 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
455};
456
457/* ------------------------------------------------------------------------
458 * Variants for each layer configuration which can be tested
459 */
460
461template <typename LayerProperties>
462struct BaseLayerProperties {
463 static constexpr uint32_t WIDTH = 100;
464 static constexpr uint32_t HEIGHT = 100;
465 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
466 static constexpr uint64_t USAGE =
467 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
468 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
469 static constexpr uint32_t SCALING_MODE = 0;
470 static constexpr uint32_t TRANSFORM = 0;
471 static constexpr uint32_t LAYER_FLAGS = 0;
472 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
473 static constexpr IComposerClient::BlendMode BLENDMODE =
474 IComposerClient::BlendMode::PREMULTIPLIED;
475
476 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
477 auto producer = layer->getProducer();
478
479 IGraphicBufferProducer::QueueBufferOutput qbo;
480 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
481 if (result != NO_ERROR) {
482 ALOGE("Failed to connect() (%d)", result);
483 return;
484 }
485
486 int slot;
487 sp<Fence> fence;
488 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
489 LayerProperties::HEIGHT, LayerProperties::FORMAT,
490 LayerProperties::USAGE, nullptr, nullptr);
491 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
492 ALOGE("Failed to dequeueBuffer() (%d)", result);
493 return;
494 }
495
496 sp<GraphicBuffer> buffer;
497 result = producer->requestBuffer(slot, &buffer);
498 if (result != NO_ERROR) {
499 ALOGE("Failed to requestBuffer() (%d)", result);
500 return;
501 }
502
503 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
504 LayerProperties::DATASPACE,
505 Rect(LayerProperties::WIDTH,
506 LayerProperties::HEIGHT),
507 LayerProperties::SCALING_MODE,
508 LayerProperties::TRANSFORM, Fence::NO_FENCE);
509 result = producer->queueBuffer(slot, qbi, &qbo);
510 if (result != NO_ERROR) {
511 ALOGE("Failed to queueBuffer (%d)", result);
512 return;
513 }
514 }
515
516 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
517 // TODO: Eliminate the complexity of actually creating a buffer
518 EXPECT_CALL(*test->mRenderEngine, getMaxTextureSize()).WillOnce(Return(16384));
519 EXPECT_CALL(*test->mRenderEngine, getMaxViewportDims()).WillOnce(Return(16384));
520 status_t err =
521 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
522 LayerProperties::FORMAT);
523 ASSERT_EQ(NO_ERROR, err);
524 Mock::VerifyAndClear(test->mRenderEngine);
525
526 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
527 enqueueBuffer(test, layer);
528 Mock::VerifyAndClear(test->mMessageQueue);
529
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700530 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700531 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700532 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700533 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700534 }
535
536 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
537 setupLatchedBuffer(test, layer);
538 }
539
540 static void setupBufferLayerPostFrameCallExpectations(CompositionTest* test) {
541 // BufferLayer::onPostComposition(), when there is no present fence
542 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY, _))
543 .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE)));
544 }
545
546 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800547 if (!test->mDisplayOff) {
548 // TODO: Coverage of other values
549 EXPECT_CALL(*test->mComposer,
550 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
551 .Times(1);
552 // TODO: Coverage of other values for origin
553 EXPECT_CALL(*test->mComposer,
554 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
555 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
556 LayerProperties::HEIGHT})))
557 .Times(1);
558 EXPECT_CALL(*test->mComposer,
559 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
560 .Times(1);
561 // TODO: Coverage of other values
562 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
563 // TODO: Coverage of other values
564 EXPECT_CALL(*test->mComposer, setLayerInfo(HWC_DISPLAY, HWC_LAYER, 0u, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700565
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800566 // These expectations retire on saturation as the code path these
567 // expectations are for appears to make an extra call to them.
568 // TODO: Investigate this extra call
569 EXPECT_CALL(*test->mComposer,
570 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
571 .Times(AtLeast(1))
572 .RetiresOnSaturation();
573 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700574 }
575
576 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800577 if (!test->mDisplayOff) {
578 EXPECT_CALL(*test->mComposer,
579 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
580 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
581 LayerProperties::HEIGHT})))
582 .Times(1);
583 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700584 }
585
586 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800587 if (!test->mDisplayOff) {
588 EXPECT_CALL(*test->mComposer,
589 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
590 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
591 .Times(1);
592 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700593 }
594
595 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800596 if (!test->mDisplayOff) {
597 EXPECT_CALL(*test->mComposer,
598 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
599 std::vector<IComposerClient::Rect>(
600 {IComposerClient::Rect(
601 {0, 0, LayerProperties::WIDTH,
602 LayerProperties::HEIGHT})})))
603 .Times(1);
604 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700605 }
606
607 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800608 if (!test->mDisplayOff) {
609 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
610 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700611
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800612 // TODO: use COLOR
613 EXPECT_CALL(*test->mComposer,
614 setLayerColor(HWC_DISPLAY, HWC_LAYER,
615 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
616 .Times(1);
617 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700618 }
619
620 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800621 if (!test->mDisplayOff) {
622 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
623 .Times(1);
624 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
625 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700626
627 setupBufferLayerPostFrameCallExpectations(test);
628 }
629
630 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000631 EXPECT_CALL(*test->mRenderEngine, drawLayers)
632 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800633 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700634 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800635 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000636 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
637 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
638 displaySettings.physicalDisplay);
639 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
640 displaySettings.clip);
641 // screen capture adds an additional color layer as an alpha
642 // prefill, so gtet the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800643 if (layerSettings.empty()) {
644 ADD_FAILURE() << "layerSettings was not expected to be empty in "
645 "setupREBufferCompositionCommonCallExpectations "
646 "verification lambda";
647 return NO_ERROR;
648 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800649 const renderengine::LayerSettings* layer = layerSettings.back();
650 EXPECT_THAT(layer->source.buffer.buffer, Not(IsNull()));
651 EXPECT_THAT(layer->source.buffer.fence, Not(IsNull()));
652 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer->source.buffer.textureName);
653 EXPECT_EQ(false, layer->source.buffer.isY410BT2020);
654 EXPECT_EQ(true, layer->source.buffer.usePremultipliedAlpha);
655 EXPECT_EQ(false, layer->source.buffer.isOpaque);
656 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
657 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
658 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000659 return NO_ERROR;
660 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700661 }
662
663 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
664 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700665 }
666
667 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
668 setupREBufferCompositionCallExpectations(test);
669 }
670
671 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
672 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
673 }
674
675 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
676 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
677 }
678
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700679 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000680 EXPECT_CALL(*test->mRenderEngine, drawLayers)
681 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800682 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700683 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800684 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000685 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
686 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
687 displaySettings.physicalDisplay);
688 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
689 displaySettings.clip);
690 // screen capture adds an additional color layer as an alpha
691 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800692 if (layerSettings.empty()) {
693 ADD_FAILURE()
694 << "layerSettings was not expected to be empty in "
695 "setupREColorCompositionCallExpectations verification lambda";
696 return NO_ERROR;
697 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800698 const renderengine::LayerSettings* layer = layerSettings.back();
699 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000700 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
701 LayerProperties::COLOR[2]),
Vishnu Nair9b079a22020-01-21 14:36:08 -0800702 layer->source.solidColor);
703 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
704 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
705 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000706 return NO_ERROR;
707 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700708 }
709
710 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
711 setupREColorCompositionCallExpectations(test);
712 }
713};
714
715struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
716
Alec Mourida8a9d12020-01-30 20:00:31 -0800717struct ColorLayerProperties : public BaseLayerProperties<ColorLayerProperties> {
718 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
719};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700720
721struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
722 using Base = BaseLayerProperties<SidebandLayerProperties>;
723 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
724
725 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
726 sp<NativeHandle> stream =
727 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
728 false);
729 test->mFlinger.setLayerSidebandStream(layer, stream);
730 }
731
732 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
733 EXPECT_CALL(*test->mComposer,
734 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
735 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
736 .Times(1);
737 }
738
739 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
740 EXPECT_CALL(*test->mComposer,
741 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
742 reinterpret_cast<native_handle_t*>(
743 DEFAULT_SIDEBAND_STREAM)))
744 .WillOnce(Return(Error::NONE));
745
746 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
747 }
748
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000749 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700750};
751
752struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> {
753 using Base = BaseLayerProperties<SecureLayerProperties>;
754
755 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
756
757 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000758 EXPECT_CALL(*test->mRenderEngine, drawLayers)
759 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800760 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700761 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800762 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000763 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
764 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
765 displaySettings.physicalDisplay);
766 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
767 displaySettings.clip);
768 // screen capture adds an additional color layer as an alpha
769 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800770 if (layerSettings.empty()) {
771 ADD_FAILURE() << "layerSettings was not expected to be empty in "
772 "setupInsecureREBufferCompositionCommonCallExpectations "
773 "verification lambda";
774 return NO_ERROR;
775 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800776 const renderengine::LayerSettings* layer = layerSettings.back();
777 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
778 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer->source.solidColor);
779 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
780 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
781 EXPECT_EQ(1.0f, layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000782 return NO_ERROR;
783 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700784 }
785
786 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
787 setupInsecureREBufferCompositionCommonCallExpectations(test);
788 Base::setupBufferLayerPostFrameCallExpectations(test);
789 }
790
791 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
792 setupInsecureREBufferCompositionCommonCallExpectations(test);
793 }
794};
795
796struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
797 using Base = BaseLayerProperties<CursorLayerProperties>;
798
799 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
800 Base::setupLayerState(test, layer);
801 test->mFlinger.setLayerPotentialCursor(layer, true);
802 }
803};
804
805struct NoLayerVariant {
806 using FlingerLayerType = sp<BufferQueueLayer>;
807
808 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
809 static void injectLayer(CompositionTest*, FlingerLayerType) {}
810 static void cleanupInjectedLayers(CompositionTest*) {}
811
812 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
813 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
814};
815
816template <typename LayerProperties>
817struct BaseLayerVariant {
818 template <typename L, typename F>
819 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
820 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0);
821
822 sp<L> layer = factory();
823
Dominik Laskowski49cea512019-11-12 14:13:23 -0800824 // Layer should be registered with scheduler.
825 EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize());
826
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700827 Mock::VerifyAndClear(test->mComposer);
828 Mock::VerifyAndClear(test->mRenderEngine);
829 Mock::VerifyAndClear(test->mMessageQueue);
830
831 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
832 layerDrawingState.layerStack = DEFAULT_LAYER_STACK;
833 layerDrawingState.active.w = 100;
834 layerDrawingState.active.h = 100;
835 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
836 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700837 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700838
839 return layer;
840 }
841
842 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
843 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
844 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
845
Lloyd Piquede196652020-01-22 17:29:58 -0800846 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
847 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700848 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
849 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700850
851 Mock::VerifyAndClear(test->mComposer);
852
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700853 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
854 }
855
856 static void cleanupInjectedLayers(CompositionTest* test) {
857 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
858 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800859
Lloyd Pique01c77c12019-04-17 12:48:32 -0700860 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700861 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800862
863 // Layer should be unregistered with scheduler.
864 test->mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
865 EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700866 }
867};
868
869template <typename LayerProperties>
870struct ColorLayerVariant : public BaseLayerVariant<LayerProperties> {
871 using Base = BaseLayerVariant<LayerProperties>;
872 using FlingerLayerType = sp<ColorLayer>;
873
874 static FlingerLayerType createLayer(CompositionTest* test) {
875 FlingerLayerType layer = Base::template createLayerWithFactory<ColorLayer>(test, [test]() {
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700876 return new ColorLayer(LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700877 "test-layer", LayerProperties::WIDTH,
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700878 LayerProperties::HEIGHT,
Evan Roskya1f1e152019-01-24 16:17:46 -0800879 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700880 });
Vishnu Nair60356342018-11-13 13:00:45 -0800881
882 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
883 layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700884 return layer;
885 }
886
887 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700888 LayerProperties::setupREColorCompositionCallExpectations(test);
889 }
890
891 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
892 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
893 }
894
895 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
896 LayerProperties::setupHwcSetGeometryCallExpectations(test);
897 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
898 }
899
900 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
901 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
902 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
903 }
904};
905
906template <typename LayerProperties>
907struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
908 using Base = BaseLayerVariant<LayerProperties>;
909 using FlingerLayerType = sp<BufferQueueLayer>;
910
911 static FlingerLayerType createLayer(CompositionTest* test) {
912 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
913
914 FlingerLayerType layer =
915 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
chaviwb4c6e582019-08-16 14:35:07 -0700916 sp<Client> client;
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700917 LayerCreationArgs args(test->mFlinger.mFlinger.get(), client, "test-layer",
918 LayerProperties::WIDTH, LayerProperties::HEIGHT,
919 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700920 args.textureName = test->mFlinger.mutableTexturePool().back();
921 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700922 });
923
924 LayerProperties::setupLayerState(test, layer);
925
926 return layer;
927 }
928
929 static void cleanupInjectedLayers(CompositionTest* test) {
Dan Stoza67765d82019-05-07 14:58:27 -0700930 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700931 Base::cleanupInjectedLayers(test);
932 }
933
934 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
935 LayerProperties::setupHwcSetGeometryCallExpectations(test);
936 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
937 }
938
939 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
940 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
941 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
942 }
943
944 static void setupRECompositionCallExpectations(CompositionTest* test) {
945 LayerProperties::setupREBufferCompositionCallExpectations(test);
946 }
947
948 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
949 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
950 }
951
952 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
953 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
954 }
955
956 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
957 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
958 }
959};
960
961/* ------------------------------------------------------------------------
962 * Variants to control how the composition type is changed
963 */
964
965struct NoCompositionTypeVariant {
966 static void setupHwcSetCallExpectations(CompositionTest*) {}
967
968 static void setupHwcGetCallExpectations(CompositionTest* test) {
969 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
970 }
971};
972
973template <IComposerClient::Composition CompositionType>
974struct KeepCompositionTypeVariant {
975 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(CompositionType);
976
977 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800978 if (!test->mDisplayOff) {
979 EXPECT_CALL(*test->mComposer,
980 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
981 .Times(1);
982 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700983 }
984
985 static void setupHwcGetCallExpectations(CompositionTest* test) {
986 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
987 }
988};
989
990template <IComposerClient::Composition InitialCompositionType,
991 IComposerClient::Composition FinalCompositionType>
992struct ChangeCompositionTypeVariant {
993 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(FinalCompositionType);
994
995 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800996 if (!test->mDisplayOff) {
997 EXPECT_CALL(*test->mComposer,
998 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
999 .Times(1);
1000 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001001 }
1002
1003 static void setupHwcGetCallExpectations(CompositionTest* test) {
1004 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1005 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1006 static_cast<Hwc2::Layer>(HWC_LAYER)}),
1007 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
1008 FinalCompositionType}),
1009 Return(Error::NONE)));
1010 }
1011};
1012
1013/* ------------------------------------------------------------------------
1014 * Variants to select how the composition is expected to be handled
1015 */
1016
1017struct CompositionResultBaseVariant {
1018 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1019
1020 template <typename Case>
1021 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1022 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1023 }
1024
1025 template <typename Case>
1026 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1027 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1028 }
1029};
1030
1031struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1032 template <typename Case>
1033 static void setupCallExpectations(CompositionTest* test) {
1034 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1035 Case::Display::setupHwcCompositionCallExpectations(test);
1036 }
1037};
1038
1039struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1040 template <typename Case>
1041 static void setupCallExpectations(CompositionTest* test) {
1042 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1043 Case::Display::setupHwcCompositionCallExpectations(test);
1044 }
1045};
1046
1047struct RECompositionResultVariant : public CompositionResultBaseVariant {
1048 template <typename Case>
1049 static void setupCallExpectations(CompositionTest* test) {
1050 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001051 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001052 Case::Display::setupRECompositionCallExpectations(test);
1053 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1054 }
1055};
1056
Lloyd Pique66d68602019-02-13 14:23:31 -08001057struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001058 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piquef5275482019-01-29 18:42:42 -08001059 const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay);
1060 LOG_FATAL_IF(!outputLayer);
1061 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001062 }
1063
1064 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001065 static void setupCallExpectations(CompositionTest* test) {
1066 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1067 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1068 Case::Display::setupRECompositionCallExpectations(test);
1069 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1070 }
1071
1072 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001073 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1074
1075 template <typename Case>
1076 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1077};
1078
Lloyd Pique4fe29402019-08-12 16:51:24 -07001079struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1080 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1081 test->mFlinger.mutableDebugDisableHWC() = true;
1082 }
1083
1084 template <typename Case>
1085 static void setupCallExpectations(CompositionTest* test) {
1086 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1087 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1088 Case::Display::setupRECompositionCallExpectations(test);
1089 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1090 }
1091
1092 template <typename Case>
1093 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1094
1095 template <typename Case>
1096 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1097};
1098
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001099struct EmptyScreenshotResultVariant {
1100 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1101
1102 template <typename Case>
1103 static void setupCallExpectations(CompositionTest*) {}
1104};
1105
1106struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1107 using Base = EmptyScreenshotResultVariant;
1108
1109 template <typename Case>
1110 static void setupCallExpectations(CompositionTest* test) {
1111 Base::template setupCallExpectations<Case>(test);
1112 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1113 }
1114};
1115
1116/* ------------------------------------------------------------------------
1117 * Composition test case, containing all the variants being tested
1118 */
1119
1120template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1121 typename CompositionResultCase>
1122struct CompositionCase {
1123 using ThisCase =
1124 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1125 using Display = DisplayCase;
1126 using Layer = LayerCase;
1127 using CompositionType = CompositionTypeCase;
1128 using CompositionResult = CompositionResultCase;
1129
1130 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001131 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001132 Display::setupPreconditions(test);
1133
1134 auto layer = Layer::createLayer(test);
1135 Layer::injectLayer(test, layer);
1136 CompositionResult::setupLayerState(test, layer);
1137 }
1138
1139 static void setupForDirtyGeometry(CompositionTest* test) {
1140 setupCommon(test);
1141
1142 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1143 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1144 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1145 CompositionResult::template setupCallExpectations<ThisCase>(test);
1146 }
1147
1148 static void setupForDirtyFrame(CompositionTest* test) {
1149 setupCommon(test);
1150
1151 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1152 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1153 CompositionResult::template setupCallExpectations<ThisCase>(test);
1154 }
1155
1156 static void setupForScreenCapture(CompositionTest* test) {
1157 setupCommon(test);
1158
1159 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1160 CompositionResult::template setupCallExpectations<ThisCase>(test);
1161 }
1162
1163 static void cleanup(CompositionTest* test) {
1164 Layer::cleanupInjectedLayers(test);
1165
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001166 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1167 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1168 ->mutableLayers()
1169 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001170 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001171 }
1172};
1173
1174/* ------------------------------------------------------------------------
1175 * Composition cases to test
1176 */
1177
1178TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1179 displayRefreshCompositionDirtyGeometry<
1180 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1181 NoCompositionResultVariant>>();
1182}
1183
1184TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1185 displayRefreshCompositionDirtyFrame<
1186 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1187 NoCompositionResultVariant>>();
1188}
1189
1190TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1191 captureScreenComposition<
1192 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1193 EmptyScreenshotResultVariant>>();
1194}
1195
1196/* ------------------------------------------------------------------------
1197 * Simple buffer layers
1198 */
1199
1200TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1201 displayRefreshCompositionDirtyGeometry<
1202 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1203 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1204 HwcCompositionResultVariant>>();
1205}
1206
1207TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1208 displayRefreshCompositionDirtyFrame<
1209 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1210 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1211 HwcCompositionResultVariant>>();
1212}
1213
1214TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1215 displayRefreshCompositionDirtyFrame<
1216 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1217 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1218 IComposerClient::Composition::CLIENT>,
1219 RECompositionResultVariant>>();
1220}
1221
1222TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1223 captureScreenComposition<
1224 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1225 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1226}
1227
1228/* ------------------------------------------------------------------------
1229 * Single-color layers
1230 */
1231
1232TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyGeometry) {
1233 displayRefreshCompositionDirtyGeometry<
1234 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1235 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1236 HwcCompositionResultVariant>>();
1237}
1238
1239TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyFrame) {
1240 displayRefreshCompositionDirtyFrame<
1241 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1242 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1243 HwcCompositionResultVariant>>();
1244}
1245
1246TEST_F(CompositionTest, REComposedColorLayer) {
1247 displayRefreshCompositionDirtyFrame<
1248 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1249 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1250 IComposerClient::Composition::CLIENT>,
1251 RECompositionResultVariant>>();
1252}
1253
1254TEST_F(CompositionTest, captureScreenColorLayer) {
1255 captureScreenComposition<
1256 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1257 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1258}
1259
1260/* ------------------------------------------------------------------------
1261 * Layers with sideband buffers
1262 */
1263
1264TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1265 displayRefreshCompositionDirtyGeometry<
1266 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1267 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1268 HwcCompositionResultVariant>>();
1269}
1270
1271TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1272 displayRefreshCompositionDirtyFrame<
1273 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1274 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1275 HwcCompositionResultVariant>>();
1276}
1277
1278TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1279 displayRefreshCompositionDirtyFrame<
1280 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1281 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1282 IComposerClient::Composition::CLIENT>,
1283 RECompositionResultVariant>>();
1284}
1285
1286TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1287 captureScreenComposition<
1288 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1289 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1290}
1291
1292/* ------------------------------------------------------------------------
1293 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1294 */
1295
1296TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1297 displayRefreshCompositionDirtyGeometry<
1298 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1299 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1300 HwcCompositionResultVariant>>();
1301}
1302
1303TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1304 displayRefreshCompositionDirtyFrame<
1305 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1306 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1307 HwcCompositionResultVariant>>();
1308}
1309
1310TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1311 displayRefreshCompositionDirtyFrame<
1312 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1313 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1314 IComposerClient::Composition::CLIENT>,
1315 RECompositionResultVariant>>();
1316}
1317
1318TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1319 captureScreenComposition<
1320 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1321 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1322}
1323
1324/* ------------------------------------------------------------------------
1325 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1326 */
1327
1328TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1329 displayRefreshCompositionDirtyGeometry<
1330 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1331 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1332 ForcedClientCompositionResultVariant>>();
1333}
1334
1335TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1336 displayRefreshCompositionDirtyFrame<
1337 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1338 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1339 ForcedClientCompositionResultVariant>>();
1340}
1341
1342TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1343 captureScreenComposition<
1344 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1345 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1346}
1347
1348/* ------------------------------------------------------------------------
1349 * Cursor layers
1350 */
1351
1352TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1353 displayRefreshCompositionDirtyGeometry<
1354 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1355 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1356 HwcCompositionResultVariant>>();
1357}
1358
1359TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1360 displayRefreshCompositionDirtyFrame<
1361 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1362 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1363 HwcCompositionResultVariant>>();
1364}
1365
1366TEST_F(CompositionTest, REComposedCursorLayer) {
1367 displayRefreshCompositionDirtyFrame<
1368 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1369 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1370 IComposerClient::Composition::CLIENT>,
1371 RECompositionResultVariant>>();
1372}
1373
1374TEST_F(CompositionTest, captureScreenCursorLayer) {
1375 captureScreenComposition<
1376 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1377 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1378}
1379
1380/* ------------------------------------------------------------------------
1381 * Simple buffer layer on a display which is powered off.
1382 */
1383
1384TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001385 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001386 displayRefreshCompositionDirtyGeometry<CompositionCase<
1387 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1388 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1389 HwcCompositionResultVariant>>();
1390}
1391
1392TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001393 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001394 displayRefreshCompositionDirtyFrame<CompositionCase<
1395 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1396 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1397 HwcCompositionResultVariant>>();
1398}
1399
1400TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001401 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001402 displayRefreshCompositionDirtyFrame<CompositionCase<
1403 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1404 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1405 IComposerClient::Composition::CLIENT>,
1406 RECompositionResultVariant>>();
1407}
1408
1409TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1410 captureScreenComposition<CompositionCase<
1411 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1412 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1413}
1414
Lloyd Pique4fe29402019-08-12 16:51:24 -07001415/* ------------------------------------------------------------------------
1416 * Client composition forced through debug/developer settings
1417 */
1418
1419TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
1420 displayRefreshCompositionDirtyGeometry<
1421 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1422 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1423 ForcedClientCompositionViaDebugOptionResultVariant>>();
1424}
1425
1426TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
1427 displayRefreshCompositionDirtyFrame<
1428 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1429 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1430 ForcedClientCompositionViaDebugOptionResultVariant>>();
1431}
1432
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001433} // namespace
1434} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001435
1436// TODO(b/129481165): remove the #pragma below and fix conversion issues
1437#pragma clang diagnostic pop // ignored "-Wconversion"