blob: d002f78958131212b20bea179cf9c28da4222147 [file] [log] [blame]
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Lloyd Piqued6b579f2018-04-06 15:29:10 -070021#undef LOG_TAG
22#define LOG_TAG "CompositionTest"
23
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080024#include <compositionengine/Display.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070025#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070026#include <gmock/gmock.h>
27#include <gtest/gtest.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070028#include <gui/IProducerListener.h>
Evan Roskya1f1e152019-01-24 16:17:46 -080029#include <gui/LayerMetadata.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070030#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070031#include <renderengine/mock/Framebuffer.h>
32#include <renderengine/mock/Image.h>
33#include <renderengine/mock/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070034#include <system/window.h>
35#include <utils/String8.h>
36
37#include "BufferQueueLayer.h"
Vishnu Nairfa247b12020-02-11 08:58:26 -080038#include "EffectLayer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070039#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070040#include "TestableSurfaceFlinger.h"
41#include "mock/DisplayHardware/MockComposer.h"
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070042#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070043#include "mock/MockDispSync.h"
44#include "mock/MockEventControlThread.h"
45#include "mock/MockEventThread.h"
46#include "mock/MockMessageQueue.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080047#include "mock/MockTimeStats.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070048#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070049
50namespace android {
51namespace {
52
Peiyong Line9d809e2020-04-14 13:10:48 -070053namespace hal = android::hardware::graphics::composer::hal;
54
Peiyong Lin65248e02020-04-18 21:15:07 -070055using hal::Error;
56using hal::IComposer;
57using hal::IComposerClient;
58using hal::PowerMode;
59using hal::Transform;
60
Lloyd Piqued6b579f2018-04-06 15:29:10 -070061using testing::_;
David Sodman15094112018-10-11 09:39:37 -070062using testing::AtLeast;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000063using testing::Between;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070064using testing::ByMove;
65using testing::DoAll;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000066using testing::Field;
Alec Mouri0a9c7b82018-11-16 13:05:25 -080067using testing::Invoke;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070068using testing::IsNull;
69using testing::Mock;
70using testing::NotNull;
71using testing::Ref;
72using testing::Return;
73using testing::ReturnRef;
74using testing::SetArgPointee;
75
Lloyd Piqued6b579f2018-04-06 15:29:10 -070076using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
77using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
78
Peiyong Line9d809e2020-04-14 13:10:48 -070079constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
80constexpr hal::HWLayerId HWC_LAYER = 5000;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070081constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
82
Dominik Laskowski34157762018-10-31 13:07:19 -070083constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070084constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
85constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
86
87constexpr int DEFAULT_CONFIG_ID = 0;
88constexpr int DEFAULT_TEXTURE_ID = 6000;
89constexpr int DEFAULT_LAYER_STACK = 7000;
90
91constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
92
93constexpr int DEFAULT_SIDEBAND_STREAM = 51;
94
95class CompositionTest : public testing::Test {
96public:
97 CompositionTest() {
98 const ::testing::TestInfo* const test_info =
99 ::testing::UnitTest::GetInstance()->current_test_info();
100 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
101
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700102 mFlinger.mutableEventQueue().reset(mMessageQueue);
Ana Krulecafb45842019-02-13 13:33:03 -0800103 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700104
Alec Mourif6fd29e2018-11-17 04:56:41 +0000105 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
106 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
107 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
108 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700109
110 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800111 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700112 setupComposer(0);
113 }
114
115 ~CompositionTest() {
116 const ::testing::TestInfo* const test_info =
117 ::testing::UnitTest::GetInstance()->current_test_info();
118 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
119 }
120
121 void setupComposer(int virtualDisplayCount) {
122 mComposer = new Hwc2::mock::Composer();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700123 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
124 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
125
126 Mock::VerifyAndClear(mComposer);
127 }
128
Ana Krulecafb45842019-02-13 13:33:03 -0800129 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700130 auto eventThread = std::make_unique<mock::EventThread>();
131 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800132
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700133 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700134 EXPECT_CALL(*eventThread, createEventConnection(_, _))
135 .WillOnce(Return(
136 new EventThreadConnection(eventThread.get(), ResyncCallback(),
137 ISurfaceComposer::eConfigChangedSuppress)));
138
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700139 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700140 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
141 .WillOnce(Return(
142 new EventThreadConnection(sfEventThread.get(), ResyncCallback(),
143 ISurfaceComposer::eConfigChangedSuppress)));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700144
145 auto primaryDispSync = std::make_unique<mock::DispSync>();
146
147 EXPECT_CALL(*primaryDispSync, computeNextRefresh(0)).WillRepeatedly(Return(0));
148 EXPECT_CALL(*primaryDispSync, getPeriod())
149 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE));
150 EXPECT_CALL(*primaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
151
152 mFlinger.setupScheduler(std::move(primaryDispSync),
153 std::make_unique<mock::EventControlThread>(),
154 std::move(eventThread), std::move(sfEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800155 }
156
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700157 void setupForceGeometryDirty() {
158 // TODO: This requires the visible region and other related
159 // state to be set, and is problematic for BufferLayers since they are
160 // not visible without a buffer (and setting up a buffer looks like a
161 // pain)
162 // mFlinger.mutableVisibleRegionsDirty() = true;
163
164 mFlinger.mutableGeometryInvalid() = true;
165 }
166
167 template <typename Case>
168 void displayRefreshCompositionDirtyGeometry();
169
170 template <typename Case>
171 void displayRefreshCompositionDirtyFrame();
172
173 template <typename Case>
174 void captureScreenComposition();
175
Peiyong Line9d809e2020-04-14 13:10:48 -0700176 std::unordered_set<hal::Capability> mDefaultCapabilities = {hal::Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700177
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800178 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700179 TestableSurfaceFlinger mFlinger;
180 sp<DisplayDevice> mDisplay;
181 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700182 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
183 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700184 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700185
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800186 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
187 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
188
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700189 Hwc2::mock::Composer* mComposer = nullptr;
190 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800191 mock::TimeStats* mTimeStats = new mock::TimeStats();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700192 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700193 Hwc2::mock::PowerAdvisor mPowerAdvisor;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700194
195 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
196
197 sp<GraphicBuffer> mCaptureScreenBuffer;
198};
199
200template <typename LayerCase>
201void CompositionTest::displayRefreshCompositionDirtyGeometry() {
202 setupForceGeometryDirty();
203 LayerCase::setupForDirtyGeometry(this);
204
205 // --------------------------------------------------------------------
206 // Invocation
207
208 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
209 mFlinger.onMessageReceived(MessageQueue::REFRESH);
210
211 LayerCase::cleanup(this);
212}
213
214template <typename LayerCase>
215void CompositionTest::displayRefreshCompositionDirtyFrame() {
216 LayerCase::setupForDirtyFrame(this);
217
218 // --------------------------------------------------------------------
219 // Invocation
220
221 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
222 mFlinger.onMessageReceived(MessageQueue::REFRESH);
223
224 LayerCase::cleanup(this);
225}
226
227template <typename LayerCase>
228void CompositionTest::captureScreenComposition() {
229 LayerCase::setupForScreenCapture(this);
230
231 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700232 constexpr bool useIdentityTransform = true;
233 constexpr bool forSystem = true;
234
235 DisplayRenderArea renderArea(mDisplay, sourceCrop, DEFAULT_DISPLAY_WIDTH,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700236 DEFAULT_DISPLAY_HEIGHT, ui::Dataspace::V0_SRGB,
237 ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700238
239 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw0e3479f2018-09-10 16:49:30 -0700240 return mFlinger.traverseLayersInDisplay(mDisplay, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700241 };
242
243 // TODO: Eliminate expensive/real allocation if possible.
244 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
245 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
246 mCaptureScreenBuffer = new GraphicBuffer(renderArea.getReqWidth(), renderArea.getReqHeight(),
247 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage, "screenshot");
248
249 int fd = -1;
250 status_t result =
251 mFlinger.captureScreenImplLocked(renderArea, traverseLayers, mCaptureScreenBuffer.get(),
252 useIdentityTransform, forSystem, &fd);
253 if (fd >= 0) {
254 close(fd);
255 }
256
257 EXPECT_EQ(NO_ERROR, result);
258
259 LayerCase::cleanup(this);
260}
261
262/* ------------------------------------------------------------------------
263 * Variants for each display configuration which can be tested
264 */
265
266template <typename Derived>
267struct BaseDisplayVariant {
268 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700269 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700270
271 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700272 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700273 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700274
Peiyong Line9d809e2020-04-14 13:10:48 -0700275 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700276 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700277 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700278 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800279 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700280
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800281 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
282 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
283 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
284 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
285 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
286 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
287 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700288
289 const ::testing::TestInfo* const test_info =
290 ::testing::UnitTest::GetInstance()->current_test_info();
291
292 auto ceDisplayArgs =
293 compositionengine::DisplayCreationArgsBuilder()
294 .setPhysical({DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal})
295 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
296 .setIsSecure(Derived::IS_SECURE)
297 .setLayerStackId(DEFAULT_LAYER_STACK)
298 .setPowerAdvisor(&test->mPowerAdvisor)
299 .setName(std::string("Injected display for ") +
300 test_info->test_case_name() + "." + test_info->name())
301 .build();
302
303 auto compositionDisplay =
304 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
305 ceDisplayArgs);
306
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100307 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
308 DisplayConnectionType::Internal, HWC_DISPLAY,
309 true /* isPrimary */)
310 .setDisplaySurface(test->mDisplaySurface)
311 .setNativeWindow(test->mNativeWindow)
312 .setSecure(Derived::IS_SECURE)
313 .setPowerMode(Derived::INIT_POWER_MODE)
314 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800315 Mock::VerifyAndClear(test->mNativeWindow);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700316 test->mDisplay->setLayerStack(DEFAULT_LAYER_STACK);
317 }
318
319 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700320 static void setupPreconditionCallExpectations(CompositionTest* test) {
321 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
322 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
323 Return(Error::NONE)));
324 }
325
326 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700327 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
328 EXPECT_CALL(*test->mComposer,
329 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
330 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700331 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
332 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
333 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
334 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
335
336 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700337
338 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
339 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
340
341 Case::CompositionType::setupHwcSetCallExpectations(test);
342 Case::CompositionType::setupHwcGetCallExpectations(test);
343 }
344
345 template <typename Case>
346 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000347 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700348 .WillRepeatedly([](const renderengine::DisplaySettings& displaySettings,
349 const std::vector<const renderengine::LayerSettings*>&,
350 ANativeWindowBuffer*, const bool, base::unique_fd&&,
351 base::unique_fd*) -> status_t {
352 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
353 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
354 displaySettings.physicalDisplay);
355 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
356 displaySettings.clip);
357 return NO_ERROR;
358 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700359 }
360
361 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
362 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
363 }
364
365 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
366 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
367 }
368
369 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800370 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
371
Lloyd Pique542307f2018-10-19 13:24:08 -0700372 EXPECT_CALL(*test->mDisplaySurface,
373 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC))
374 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700375 }
376
Lloyd Pique66d68602019-02-13 14:23:31 -0800377 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
378 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
379 }
380
381 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
382 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1);
383 }
384
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700385 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700386 EXPECT_CALL(*test->mDisplaySurface,
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800387 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_GPU))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700388 .Times(1);
389 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
390 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
391
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800392 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
393 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
394 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
395 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000396 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700397 .WillRepeatedly([](const renderengine::DisplaySettings& displaySettings,
398 const std::vector<const renderengine::LayerSettings*>&,
399 ANativeWindowBuffer*, const bool, base::unique_fd&&,
400 base::unique_fd*) -> status_t {
401 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
402 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
403 displaySettings.physicalDisplay);
404 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
405 displaySettings.clip);
406 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
407 return NO_ERROR;
408 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700409 }
410
411 template <typename Case>
412 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
413 Case::Layer::setupRECompositionCallExpectations(test);
414 }
415
416 template <typename Case>
417 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
418 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700419 }
420};
421
422struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
423
424struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
425 static constexpr bool IS_SECURE = false;
426
427 template <typename Case>
428 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
429 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700430 }
431
432 template <typename Case>
433 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
434 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700435 }
436};
437
438struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700439 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700440
441 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700442 static void setupPreconditionCallExpectations(CompositionTest*) {}
443
444 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700445 static void setupCommonCompositionCallExpectations(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->mComposer,
450 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
451 .Times(1);
452
453 // TODO: This seems like an unnecessary call if display is powered off.
454 Case::CompositionType::setupHwcSetCallExpectations(test);
455 }
456
457 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800458 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
459 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700460
461 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800462 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
463
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700464 // TODO: This seems like an unnecessary call if display is powered off.
465 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
466 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
467 }
468
469 template <typename Case>
470 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
471};
472
473/* ------------------------------------------------------------------------
474 * Variants for each layer configuration which can be tested
475 */
476
477template <typename LayerProperties>
478struct BaseLayerProperties {
479 static constexpr uint32_t WIDTH = 100;
480 static constexpr uint32_t HEIGHT = 100;
481 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
482 static constexpr uint64_t USAGE =
483 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
484 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
485 static constexpr uint32_t SCALING_MODE = 0;
486 static constexpr uint32_t TRANSFORM = 0;
487 static constexpr uint32_t LAYER_FLAGS = 0;
488 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
489 static constexpr IComposerClient::BlendMode BLENDMODE =
490 IComposerClient::BlendMode::PREMULTIPLIED;
491
492 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
493 auto producer = layer->getProducer();
494
495 IGraphicBufferProducer::QueueBufferOutput qbo;
496 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
497 if (result != NO_ERROR) {
498 ALOGE("Failed to connect() (%d)", result);
499 return;
500 }
501
502 int slot;
503 sp<Fence> fence;
504 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
505 LayerProperties::HEIGHT, LayerProperties::FORMAT,
506 LayerProperties::USAGE, nullptr, nullptr);
507 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
508 ALOGE("Failed to dequeueBuffer() (%d)", result);
509 return;
510 }
511
512 sp<GraphicBuffer> buffer;
513 result = producer->requestBuffer(slot, &buffer);
514 if (result != NO_ERROR) {
515 ALOGE("Failed to requestBuffer() (%d)", result);
516 return;
517 }
518
519 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
520 LayerProperties::DATASPACE,
521 Rect(LayerProperties::WIDTH,
522 LayerProperties::HEIGHT),
523 LayerProperties::SCALING_MODE,
524 LayerProperties::TRANSFORM, Fence::NO_FENCE);
525 result = producer->queueBuffer(slot, qbi, &qbo);
526 if (result != NO_ERROR) {
527 ALOGE("Failed to queueBuffer (%d)", result);
528 return;
529 }
530 }
531
532 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
533 // TODO: Eliminate the complexity of actually creating a buffer
534 EXPECT_CALL(*test->mRenderEngine, getMaxTextureSize()).WillOnce(Return(16384));
535 EXPECT_CALL(*test->mRenderEngine, getMaxViewportDims()).WillOnce(Return(16384));
536 status_t err =
537 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
538 LayerProperties::FORMAT);
539 ASSERT_EQ(NO_ERROR, err);
540 Mock::VerifyAndClear(test->mRenderEngine);
541
542 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
543 enqueueBuffer(test, layer);
544 Mock::VerifyAndClear(test->mMessageQueue);
545
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700546 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700547 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700548 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700549 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700550 }
551
552 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
553 setupLatchedBuffer(test, layer);
554 }
555
556 static void setupBufferLayerPostFrameCallExpectations(CompositionTest* test) {
557 // BufferLayer::onPostComposition(), when there is no present fence
558 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY, _))
559 .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE)));
560 }
561
562 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800563 if (!test->mDisplayOff) {
564 // TODO: Coverage of other values
565 EXPECT_CALL(*test->mComposer,
566 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
567 .Times(1);
568 // TODO: Coverage of other values for origin
569 EXPECT_CALL(*test->mComposer,
570 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
571 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
572 LayerProperties::HEIGHT})))
573 .Times(1);
574 EXPECT_CALL(*test->mComposer,
575 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
576 .Times(1);
577 // TODO: Coverage of other values
578 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
579 // TODO: Coverage of other values
580 EXPECT_CALL(*test->mComposer, setLayerInfo(HWC_DISPLAY, HWC_LAYER, 0u, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700581
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800582 // These expectations retire on saturation as the code path these
583 // expectations are for appears to make an extra call to them.
584 // TODO: Investigate this extra call
585 EXPECT_CALL(*test->mComposer,
586 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
587 .Times(AtLeast(1))
588 .RetiresOnSaturation();
589 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700590 }
591
592 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800593 if (!test->mDisplayOff) {
594 EXPECT_CALL(*test->mComposer,
595 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
596 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
597 LayerProperties::HEIGHT})))
598 .Times(1);
599 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700600 }
601
602 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800603 if (!test->mDisplayOff) {
604 EXPECT_CALL(*test->mComposer,
605 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
606 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
607 .Times(1);
608 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700609 }
610
611 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800612 if (!test->mDisplayOff) {
613 EXPECT_CALL(*test->mComposer,
614 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
615 std::vector<IComposerClient::Rect>(
616 {IComposerClient::Rect(
617 {0, 0, LayerProperties::WIDTH,
618 LayerProperties::HEIGHT})})))
619 .Times(1);
620 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700621 }
622
623 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800624 if (!test->mDisplayOff) {
625 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
626 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700627
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800628 // TODO: use COLOR
629 EXPECT_CALL(*test->mComposer,
630 setLayerColor(HWC_DISPLAY, HWC_LAYER,
631 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
632 .Times(1);
633 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700634 }
635
636 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800637 if (!test->mDisplayOff) {
638 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
639 .Times(1);
640 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
641 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700642
643 setupBufferLayerPostFrameCallExpectations(test);
644 }
645
646 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000647 EXPECT_CALL(*test->mRenderEngine, drawLayers)
648 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800649 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700650 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800651 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000652 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
653 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
654 displaySettings.physicalDisplay);
655 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
656 displaySettings.clip);
657 // screen capture adds an additional color layer as an alpha
658 // prefill, so gtet the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800659 if (layerSettings.empty()) {
660 ADD_FAILURE() << "layerSettings was not expected to be empty in "
661 "setupREBufferCompositionCommonCallExpectations "
662 "verification lambda";
663 return NO_ERROR;
664 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800665 const renderengine::LayerSettings* layer = layerSettings.back();
666 EXPECT_THAT(layer->source.buffer.buffer, Not(IsNull()));
667 EXPECT_THAT(layer->source.buffer.fence, Not(IsNull()));
668 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer->source.buffer.textureName);
669 EXPECT_EQ(false, layer->source.buffer.isY410BT2020);
670 EXPECT_EQ(true, layer->source.buffer.usePremultipliedAlpha);
671 EXPECT_EQ(false, layer->source.buffer.isOpaque);
672 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
673 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
674 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000675 return NO_ERROR;
676 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700677 }
678
679 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
680 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700681 }
682
683 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
684 setupREBufferCompositionCallExpectations(test);
685 }
686
687 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
688 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
689 }
690
691 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
692 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
693 }
694
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700695 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000696 EXPECT_CALL(*test->mRenderEngine, drawLayers)
697 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800698 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700699 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800700 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000701 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
702 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
703 displaySettings.physicalDisplay);
704 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
705 displaySettings.clip);
706 // screen capture adds an additional color layer as an alpha
707 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800708 if (layerSettings.empty()) {
709 ADD_FAILURE()
710 << "layerSettings was not expected to be empty in "
711 "setupREColorCompositionCallExpectations verification lambda";
712 return NO_ERROR;
713 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800714 const renderengine::LayerSettings* layer = layerSettings.back();
715 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000716 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
717 LayerProperties::COLOR[2]),
Vishnu Nair9b079a22020-01-21 14:36:08 -0800718 layer->source.solidColor);
719 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
720 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
721 EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000722 return NO_ERROR;
723 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700724 }
725
726 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
727 setupREColorCompositionCallExpectations(test);
728 }
729};
730
731struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
732
Vishnu Nairfa247b12020-02-11 08:58:26 -0800733struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800734 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
735};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700736
737struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
738 using Base = BaseLayerProperties<SidebandLayerProperties>;
739 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
740
741 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
742 sp<NativeHandle> stream =
743 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
744 false);
745 test->mFlinger.setLayerSidebandStream(layer, stream);
746 }
747
748 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
749 EXPECT_CALL(*test->mComposer,
750 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
751 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
752 .Times(1);
753 }
754
755 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
756 EXPECT_CALL(*test->mComposer,
757 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
758 reinterpret_cast<native_handle_t*>(
759 DEFAULT_SIDEBAND_STREAM)))
760 .WillOnce(Return(Error::NONE));
761
762 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
763 }
764
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000765 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700766};
767
768struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> {
769 using Base = BaseLayerProperties<SecureLayerProperties>;
770
771 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
772
773 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000774 EXPECT_CALL(*test->mRenderEngine, drawLayers)
775 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800776 const std::vector<const renderengine::LayerSettings*>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700777 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800778 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000779 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
780 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
781 displaySettings.physicalDisplay);
782 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
783 displaySettings.clip);
784 // screen capture adds an additional color layer as an alpha
785 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800786 if (layerSettings.empty()) {
787 ADD_FAILURE() << "layerSettings was not expected to be empty in "
788 "setupInsecureREBufferCompositionCommonCallExpectations "
789 "verification lambda";
790 return NO_ERROR;
791 }
Vishnu Nair9b079a22020-01-21 14:36:08 -0800792 const renderengine::LayerSettings* layer = layerSettings.back();
793 EXPECT_THAT(layer->source.buffer.buffer, IsNull());
794 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer->source.solidColor);
795 EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius);
796 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace);
797 EXPECT_EQ(1.0f, layer->alpha);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000798 return NO_ERROR;
799 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700800 }
801
802 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
803 setupInsecureREBufferCompositionCommonCallExpectations(test);
804 Base::setupBufferLayerPostFrameCallExpectations(test);
805 }
806
807 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
808 setupInsecureREBufferCompositionCommonCallExpectations(test);
809 }
810};
811
812struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
813 using Base = BaseLayerProperties<CursorLayerProperties>;
814
815 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
816 Base::setupLayerState(test, layer);
817 test->mFlinger.setLayerPotentialCursor(layer, true);
818 }
819};
820
821struct NoLayerVariant {
822 using FlingerLayerType = sp<BufferQueueLayer>;
823
824 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
825 static void injectLayer(CompositionTest*, FlingerLayerType) {}
826 static void cleanupInjectedLayers(CompositionTest*) {}
827
828 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
829 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
830};
831
832template <typename LayerProperties>
833struct BaseLayerVariant {
834 template <typename L, typename F>
835 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
836 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0);
837
838 sp<L> layer = factory();
839
Dominik Laskowski49cea512019-11-12 14:13:23 -0800840 // Layer should be registered with scheduler.
841 EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize());
842
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700843 Mock::VerifyAndClear(test->mComposer);
844 Mock::VerifyAndClear(test->mRenderEngine);
845 Mock::VerifyAndClear(test->mMessageQueue);
846
847 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
848 layerDrawingState.layerStack = DEFAULT_LAYER_STACK;
849 layerDrawingState.active.w = 100;
850 layerDrawingState.active.h = 100;
851 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
852 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700853 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700854
855 return layer;
856 }
857
858 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
859 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
860 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
861
Lloyd Piquede196652020-01-22 17:29:58 -0800862 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
863 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700864 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
865 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700866
867 Mock::VerifyAndClear(test->mComposer);
868
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700869 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
870 }
871
872 static void cleanupInjectedLayers(CompositionTest* test) {
873 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
874 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800875
Lloyd Pique01c77c12019-04-17 12:48:32 -0700876 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700877 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800878
879 // Layer should be unregistered with scheduler.
880 test->mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
881 EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700882 }
883};
884
885template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800886struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700887 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800888 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700889
890 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800891 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
892 return new EffectLayer(
893 LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(), "test-layer",
894 LayerProperties::WIDTH, LayerProperties::HEIGHT,
895 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700896 });
Vishnu Nair60356342018-11-13 13:00:45 -0800897
898 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
899 layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700900 return layer;
901 }
902
903 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700904 LayerProperties::setupREColorCompositionCallExpectations(test);
905 }
906
907 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
908 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
909 }
910
911 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
912 LayerProperties::setupHwcSetGeometryCallExpectations(test);
913 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
914 }
915
916 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
917 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
918 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
919 }
920};
921
922template <typename LayerProperties>
923struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
924 using Base = BaseLayerVariant<LayerProperties>;
925 using FlingerLayerType = sp<BufferQueueLayer>;
926
927 static FlingerLayerType createLayer(CompositionTest* test) {
928 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
929
930 FlingerLayerType layer =
931 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
chaviwb4c6e582019-08-16 14:35:07 -0700932 sp<Client> client;
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700933 LayerCreationArgs args(test->mFlinger.mFlinger.get(), client, "test-layer",
934 LayerProperties::WIDTH, LayerProperties::HEIGHT,
935 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700936 args.textureName = test->mFlinger.mutableTexturePool().back();
937 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700938 });
939
940 LayerProperties::setupLayerState(test, layer);
941
942 return layer;
943 }
944
945 static void cleanupInjectedLayers(CompositionTest* test) {
Dan Stoza67765d82019-05-07 14:58:27 -0700946 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700947 Base::cleanupInjectedLayers(test);
948 }
949
950 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
951 LayerProperties::setupHwcSetGeometryCallExpectations(test);
952 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
953 }
954
955 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
956 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
957 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
958 }
959
960 static void setupRECompositionCallExpectations(CompositionTest* test) {
961 LayerProperties::setupREBufferCompositionCallExpectations(test);
962 }
963
964 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
965 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
966 }
967
968 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
969 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
970 }
971
972 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
973 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
974 }
975};
976
977/* ------------------------------------------------------------------------
978 * Variants to control how the composition type is changed
979 */
980
981struct NoCompositionTypeVariant {
982 static void setupHwcSetCallExpectations(CompositionTest*) {}
983
984 static void setupHwcGetCallExpectations(CompositionTest* test) {
985 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
986 }
987};
988
989template <IComposerClient::Composition CompositionType>
990struct KeepCompositionTypeVariant {
Peiyong Line9d809e2020-04-14 13:10:48 -0700991 static constexpr hal::Composition TYPE = CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700992
993 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800994 if (!test->mDisplayOff) {
995 EXPECT_CALL(*test->mComposer,
996 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
997 .Times(1);
998 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700999 }
1000
1001 static void setupHwcGetCallExpectations(CompositionTest* test) {
1002 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1003 }
1004};
1005
1006template <IComposerClient::Composition InitialCompositionType,
1007 IComposerClient::Composition FinalCompositionType>
1008struct ChangeCompositionTypeVariant {
Peiyong Line9d809e2020-04-14 13:10:48 -07001009 static constexpr hal::Composition TYPE = FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001010
1011 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001012 if (!test->mDisplayOff) {
1013 EXPECT_CALL(*test->mComposer,
1014 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1015 .Times(1);
1016 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001017 }
1018
1019 static void setupHwcGetCallExpectations(CompositionTest* test) {
1020 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1021 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1022 static_cast<Hwc2::Layer>(HWC_LAYER)}),
1023 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
1024 FinalCompositionType}),
1025 Return(Error::NONE)));
1026 }
1027};
1028
1029/* ------------------------------------------------------------------------
1030 * Variants to select how the composition is expected to be handled
1031 */
1032
1033struct CompositionResultBaseVariant {
1034 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1035
1036 template <typename Case>
1037 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1038 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1039 }
1040
1041 template <typename Case>
1042 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1043 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1044 }
1045};
1046
1047struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1048 template <typename Case>
1049 static void setupCallExpectations(CompositionTest* test) {
1050 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1051 Case::Display::setupHwcCompositionCallExpectations(test);
1052 }
1053};
1054
1055struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1056 template <typename Case>
1057 static void setupCallExpectations(CompositionTest* test) {
1058 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1059 Case::Display::setupHwcCompositionCallExpectations(test);
1060 }
1061};
1062
1063struct RECompositionResultVariant : public CompositionResultBaseVariant {
1064 template <typename Case>
1065 static void setupCallExpectations(CompositionTest* test) {
1066 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001067 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001068 Case::Display::setupRECompositionCallExpectations(test);
1069 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1070 }
1071};
1072
Lloyd Pique66d68602019-02-13 14:23:31 -08001073struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001074 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piquef5275482019-01-29 18:42:42 -08001075 const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay);
1076 LOG_FATAL_IF(!outputLayer);
1077 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001078 }
1079
1080 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001081 static void setupCallExpectations(CompositionTest* test) {
1082 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1083 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1084 Case::Display::setupRECompositionCallExpectations(test);
1085 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1086 }
1087
1088 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001089 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1090
1091 template <typename Case>
1092 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1093};
1094
Lloyd Pique4fe29402019-08-12 16:51:24 -07001095struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1096 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1097 test->mFlinger.mutableDebugDisableHWC() = true;
1098 }
1099
1100 template <typename Case>
1101 static void setupCallExpectations(CompositionTest* test) {
1102 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1103 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1104 Case::Display::setupRECompositionCallExpectations(test);
1105 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1106 }
1107
1108 template <typename Case>
1109 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1110
1111 template <typename Case>
1112 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1113};
1114
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001115struct EmptyScreenshotResultVariant {
1116 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1117
1118 template <typename Case>
1119 static void setupCallExpectations(CompositionTest*) {}
1120};
1121
1122struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1123 using Base = EmptyScreenshotResultVariant;
1124
1125 template <typename Case>
1126 static void setupCallExpectations(CompositionTest* test) {
1127 Base::template setupCallExpectations<Case>(test);
1128 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1129 }
1130};
1131
1132/* ------------------------------------------------------------------------
1133 * Composition test case, containing all the variants being tested
1134 */
1135
1136template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1137 typename CompositionResultCase>
1138struct CompositionCase {
1139 using ThisCase =
1140 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1141 using Display = DisplayCase;
1142 using Layer = LayerCase;
1143 using CompositionType = CompositionTypeCase;
1144 using CompositionResult = CompositionResultCase;
1145
1146 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001147 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001148 Display::setupPreconditions(test);
1149
1150 auto layer = Layer::createLayer(test);
1151 Layer::injectLayer(test, layer);
1152 CompositionResult::setupLayerState(test, layer);
1153 }
1154
1155 static void setupForDirtyGeometry(CompositionTest* test) {
1156 setupCommon(test);
1157
1158 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1159 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1160 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1161 CompositionResult::template setupCallExpectations<ThisCase>(test);
1162 }
1163
1164 static void setupForDirtyFrame(CompositionTest* test) {
1165 setupCommon(test);
1166
1167 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1168 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1169 CompositionResult::template setupCallExpectations<ThisCase>(test);
1170 }
1171
1172 static void setupForScreenCapture(CompositionTest* test) {
1173 setupCommon(test);
1174
1175 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1176 CompositionResult::template setupCallExpectations<ThisCase>(test);
1177 }
1178
1179 static void cleanup(CompositionTest* test) {
1180 Layer::cleanupInjectedLayers(test);
1181
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001182 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1183 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1184 ->mutableLayers()
1185 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001186 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001187 }
1188};
1189
1190/* ------------------------------------------------------------------------
1191 * Composition cases to test
1192 */
1193
1194TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1195 displayRefreshCompositionDirtyGeometry<
1196 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1197 NoCompositionResultVariant>>();
1198}
1199
1200TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1201 displayRefreshCompositionDirtyFrame<
1202 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1203 NoCompositionResultVariant>>();
1204}
1205
1206TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1207 captureScreenComposition<
1208 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1209 EmptyScreenshotResultVariant>>();
1210}
1211
1212/* ------------------------------------------------------------------------
1213 * Simple buffer layers
1214 */
1215
1216TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1217 displayRefreshCompositionDirtyGeometry<
1218 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1219 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1220 HwcCompositionResultVariant>>();
1221}
1222
1223TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1224 displayRefreshCompositionDirtyFrame<
1225 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1226 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1227 HwcCompositionResultVariant>>();
1228}
1229
1230TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1231 displayRefreshCompositionDirtyFrame<
1232 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1233 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1234 IComposerClient::Composition::CLIENT>,
1235 RECompositionResultVariant>>();
1236}
1237
1238TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1239 captureScreenComposition<
1240 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1241 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1242}
1243
1244/* ------------------------------------------------------------------------
1245 * Single-color layers
1246 */
1247
Vishnu Nairfa247b12020-02-11 08:58:26 -08001248TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001249 displayRefreshCompositionDirtyGeometry<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001250 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001251 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1252 HwcCompositionResultVariant>>();
1253}
1254
Vishnu Nairfa247b12020-02-11 08:58:26 -08001255TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001256 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001257 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001258 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1259 HwcCompositionResultVariant>>();
1260}
1261
Vishnu Nairfa247b12020-02-11 08:58:26 -08001262TEST_F(CompositionTest, REComposedEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001263 displayRefreshCompositionDirtyFrame<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001264 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001265 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1266 IComposerClient::Composition::CLIENT>,
1267 RECompositionResultVariant>>();
1268}
1269
Vishnu Nairfa247b12020-02-11 08:58:26 -08001270TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001271 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001272 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001273 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1274}
1275
1276/* ------------------------------------------------------------------------
1277 * Layers with sideband buffers
1278 */
1279
1280TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1281 displayRefreshCompositionDirtyGeometry<
1282 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1283 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1284 HwcCompositionResultVariant>>();
1285}
1286
1287TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1288 displayRefreshCompositionDirtyFrame<
1289 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1290 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1291 HwcCompositionResultVariant>>();
1292}
1293
1294TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1295 displayRefreshCompositionDirtyFrame<
1296 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1297 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1298 IComposerClient::Composition::CLIENT>,
1299 RECompositionResultVariant>>();
1300}
1301
1302TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1303 captureScreenComposition<
1304 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1305 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1306}
1307
1308/* ------------------------------------------------------------------------
1309 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1310 */
1311
1312TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1313 displayRefreshCompositionDirtyGeometry<
1314 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1315 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1316 HwcCompositionResultVariant>>();
1317}
1318
1319TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1320 displayRefreshCompositionDirtyFrame<
1321 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1322 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1323 HwcCompositionResultVariant>>();
1324}
1325
1326TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1327 displayRefreshCompositionDirtyFrame<
1328 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1329 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1330 IComposerClient::Composition::CLIENT>,
1331 RECompositionResultVariant>>();
1332}
1333
1334TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1335 captureScreenComposition<
1336 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1337 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1338}
1339
1340/* ------------------------------------------------------------------------
1341 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1342 */
1343
1344TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1345 displayRefreshCompositionDirtyGeometry<
1346 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1347 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1348 ForcedClientCompositionResultVariant>>();
1349}
1350
1351TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1352 displayRefreshCompositionDirtyFrame<
1353 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1354 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1355 ForcedClientCompositionResultVariant>>();
1356}
1357
1358TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1359 captureScreenComposition<
1360 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1361 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1362}
1363
1364/* ------------------------------------------------------------------------
1365 * Cursor layers
1366 */
1367
1368TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1369 displayRefreshCompositionDirtyGeometry<
1370 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1371 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1372 HwcCompositionResultVariant>>();
1373}
1374
1375TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1376 displayRefreshCompositionDirtyFrame<
1377 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1378 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1379 HwcCompositionResultVariant>>();
1380}
1381
1382TEST_F(CompositionTest, REComposedCursorLayer) {
1383 displayRefreshCompositionDirtyFrame<
1384 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1385 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1386 IComposerClient::Composition::CLIENT>,
1387 RECompositionResultVariant>>();
1388}
1389
1390TEST_F(CompositionTest, captureScreenCursorLayer) {
1391 captureScreenComposition<
1392 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1393 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1394}
1395
1396/* ------------------------------------------------------------------------
1397 * Simple buffer layer on a display which is powered off.
1398 */
1399
1400TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001401 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001402 displayRefreshCompositionDirtyGeometry<CompositionCase<
1403 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1404 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1405 HwcCompositionResultVariant>>();
1406}
1407
1408TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001409 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001410 displayRefreshCompositionDirtyFrame<CompositionCase<
1411 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1412 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1413 HwcCompositionResultVariant>>();
1414}
1415
1416TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001417 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001418 displayRefreshCompositionDirtyFrame<CompositionCase<
1419 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1420 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1421 IComposerClient::Composition::CLIENT>,
1422 RECompositionResultVariant>>();
1423}
1424
1425TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1426 captureScreenComposition<CompositionCase<
1427 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1428 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1429}
1430
Lloyd Pique4fe29402019-08-12 16:51:24 -07001431/* ------------------------------------------------------------------------
1432 * Client composition forced through debug/developer settings
1433 */
1434
1435TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
1436 displayRefreshCompositionDirtyGeometry<
1437 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1438 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1439 ForcedClientCompositionViaDebugOptionResultVariant>>();
1440}
1441
1442TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
1443 displayRefreshCompositionDirtyFrame<
1444 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1445 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1446 ForcedClientCompositionViaDebugOptionResultVariant>>();
1447}
1448
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001449} // namespace
1450} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001451
1452// TODO(b/129481165): remove the #pragma below and fix conversion issues
1453#pragma clang diagnostic pop // ignored "-Wconversion"