blob: 20dfed65e23cd7564c9e5b44710a78b1d34bd3ae [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
17#undef LOG_TAG
18#define LOG_TAG "CompositionTest"
19
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080020#include <compositionengine/Display.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070021#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070022#include <gmock/gmock.h>
23#include <gtest/gtest.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070024#include <gui/IProducerListener.h>
Evan Roskya1f1e152019-01-24 16:17:46 -080025#include <gui/LayerMetadata.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070026#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070027#include <renderengine/mock/Framebuffer.h>
28#include <renderengine/mock/Image.h>
29#include <renderengine/mock/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070030#include <system/window.h>
31#include <utils/String8.h>
32
33#include "BufferQueueLayer.h"
34#include "ColorLayer.h"
35#include "Layer.h"
36
37#include "TestableSurfaceFlinger.h"
38#include "mock/DisplayHardware/MockComposer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070039#include "mock/MockDispSync.h"
40#include "mock/MockEventControlThread.h"
41#include "mock/MockEventThread.h"
42#include "mock/MockMessageQueue.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070043#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070044
45namespace android {
46namespace {
47
48using testing::_;
David Sodman15094112018-10-11 09:39:37 -070049using testing::AtLeast;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000050using testing::Between;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070051using testing::ByMove;
52using testing::DoAll;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000053using testing::Field;
Alec Mouri0a9c7b82018-11-16 13:05:25 -080054using testing::Invoke;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070055using testing::IsNull;
56using testing::Mock;
57using testing::NotNull;
58using testing::Ref;
59using testing::Return;
60using testing::ReturnRef;
61using testing::SetArgPointee;
62
63using android::Hwc2::Error;
64using android::Hwc2::IComposer;
65using android::Hwc2::IComposerClient;
66using android::Hwc2::Transform;
67
68using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
69using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
70
71constexpr hwc2_display_t HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
72constexpr hwc2_layer_t HWC_LAYER = 5000;
73constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
74
Dominik Laskowski34157762018-10-31 13:07:19 -070075constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070076constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
77constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
78
79constexpr int DEFAULT_CONFIG_ID = 0;
80constexpr int DEFAULT_TEXTURE_ID = 6000;
81constexpr int DEFAULT_LAYER_STACK = 7000;
82
83constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
84
85constexpr int DEFAULT_SIDEBAND_STREAM = 51;
86
87class CompositionTest : public testing::Test {
88public:
89 CompositionTest() {
90 const ::testing::TestInfo* const test_info =
91 ::testing::UnitTest::GetInstance()->current_test_info();
92 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
93
Lloyd Piqued6b579f2018-04-06 15:29:10 -070094 mFlinger.mutableEventQueue().reset(mMessageQueue);
Ana Krulecafb45842019-02-13 13:33:03 -080095 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -070096
Alec Mourif6fd29e2018-11-17 04:56:41 +000097 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
98 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
99 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
100 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700101
102 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
103 setupComposer(0);
104 }
105
106 ~CompositionTest() {
107 const ::testing::TestInfo* const test_info =
108 ::testing::UnitTest::GetInstance()->current_test_info();
109 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
110 }
111
112 void setupComposer(int virtualDisplayCount) {
113 mComposer = new Hwc2::mock::Composer();
114 EXPECT_CALL(*mComposer, getCapabilities())
115 .WillOnce(Return(std::vector<IComposer::Capability>()));
116 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
117 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
118
119 Mock::VerifyAndClear(mComposer);
120 }
121
Ana Krulecafb45842019-02-13 13:33:03 -0800122 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700123 auto eventThread = std::make_unique<mock::EventThread>();
124 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800125
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700126 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700127 EXPECT_CALL(*eventThread, createEventConnection(_, _))
128 .WillOnce(Return(
129 new EventThreadConnection(eventThread.get(), ResyncCallback(),
130 ISurfaceComposer::eConfigChangedSuppress)));
131
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700132 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700133 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
134 .WillOnce(Return(
135 new EventThreadConnection(sfEventThread.get(), ResyncCallback(),
136 ISurfaceComposer::eConfigChangedSuppress)));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700137
138 auto primaryDispSync = std::make_unique<mock::DispSync>();
139
140 EXPECT_CALL(*primaryDispSync, computeNextRefresh(0)).WillRepeatedly(Return(0));
141 EXPECT_CALL(*primaryDispSync, getPeriod())
142 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE));
143 EXPECT_CALL(*primaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
144
145 mFlinger.setupScheduler(std::move(primaryDispSync),
146 std::make_unique<mock::EventControlThread>(),
147 std::move(eventThread), std::move(sfEventThread));
Ana Krulecafb45842019-02-13 13:33:03 -0800148 }
149
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700150 void setupForceGeometryDirty() {
151 // TODO: This requires the visible region and other related
152 // state to be set, and is problematic for BufferLayers since they are
153 // not visible without a buffer (and setting up a buffer looks like a
154 // pain)
155 // mFlinger.mutableVisibleRegionsDirty() = true;
156
157 mFlinger.mutableGeometryInvalid() = true;
158 }
159
160 template <typename Case>
161 void displayRefreshCompositionDirtyGeometry();
162
163 template <typename Case>
164 void displayRefreshCompositionDirtyFrame();
165
166 template <typename Case>
167 void captureScreenComposition();
168
169 std::unordered_set<HWC2::Capability> mDefaultCapabilities = {HWC2::Capability::SidebandStream};
170
171 TestableSurfaceFlinger mFlinger;
172 sp<DisplayDevice> mDisplay;
173 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700174 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
175 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700176 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700177
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800178 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
179 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
180
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700181 Hwc2::mock::Composer* mComposer = nullptr;
182 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
183 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700184
185 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
186
187 sp<GraphicBuffer> mCaptureScreenBuffer;
188};
189
190template <typename LayerCase>
191void CompositionTest::displayRefreshCompositionDirtyGeometry() {
192 setupForceGeometryDirty();
193 LayerCase::setupForDirtyGeometry(this);
194
195 // --------------------------------------------------------------------
196 // Invocation
197
198 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
199 mFlinger.onMessageReceived(MessageQueue::REFRESH);
200
201 LayerCase::cleanup(this);
202}
203
204template <typename LayerCase>
205void CompositionTest::displayRefreshCompositionDirtyFrame() {
206 LayerCase::setupForDirtyFrame(this);
207
208 // --------------------------------------------------------------------
209 // Invocation
210
211 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
212 mFlinger.onMessageReceived(MessageQueue::REFRESH);
213
214 LayerCase::cleanup(this);
215}
216
217template <typename LayerCase>
218void CompositionTest::captureScreenComposition() {
219 LayerCase::setupForScreenCapture(this);
220
221 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700222 constexpr bool useIdentityTransform = true;
223 constexpr bool forSystem = true;
224
225 DisplayRenderArea renderArea(mDisplay, sourceCrop, DEFAULT_DISPLAY_WIDTH,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700226 DEFAULT_DISPLAY_HEIGHT, ui::Dataspace::V0_SRGB,
227 ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700228
229 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw0e3479f2018-09-10 16:49:30 -0700230 return mFlinger.traverseLayersInDisplay(mDisplay, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700231 };
232
233 // TODO: Eliminate expensive/real allocation if possible.
234 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
235 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
236 mCaptureScreenBuffer = new GraphicBuffer(renderArea.getReqWidth(), renderArea.getReqHeight(),
237 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage, "screenshot");
238
239 int fd = -1;
240 status_t result =
241 mFlinger.captureScreenImplLocked(renderArea, traverseLayers, mCaptureScreenBuffer.get(),
242 useIdentityTransform, forSystem, &fd);
243 if (fd >= 0) {
244 close(fd);
245 }
246
247 EXPECT_EQ(NO_ERROR, result);
248
249 LayerCase::cleanup(this);
250}
251
252/* ------------------------------------------------------------------------
253 * Variants for each display configuration which can be tested
254 */
255
256template <typename Derived>
257struct BaseDisplayVariant {
258 static constexpr bool IS_SECURE = true;
259 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
260
261 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700262 EXPECT_CALL(*test->mComposer,
263 setPowerMode(HWC_DISPLAY,
264 static_cast<Hwc2::IComposerClient::PowerMode>(
265 Derived::INIT_POWER_MODE)))
266 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700267
Dominik Laskowski075d3172018-05-24 15:50:06 -0700268 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, HWC2::DisplayType::Physical,
269 true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700270 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700271 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700272 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800273 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700274
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800275 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
276 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
277 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
278 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
279 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
280 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
281 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700282 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, DEFAULT_DISPLAY_ID,
283 false /* isVirtual */, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700284 .setDisplaySurface(test->mDisplaySurface)
Alec Mouriba013fa2018-10-16 12:43:11 -0700285 .setNativeWindow(test->mNativeWindow)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700286 .setSecure(Derived::IS_SECURE)
287 .setPowerMode(Derived::INIT_POWER_MODE)
288 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800289 Mock::VerifyAndClear(test->mNativeWindow);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700290 test->mDisplay->setLayerStack(DEFAULT_LAYER_STACK);
291 }
292
293 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700294 static void setupPreconditionCallExpectations(CompositionTest* test) {
295 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
296 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
297 Return(Error::NONE)));
298 }
299
300 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700301 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
302 EXPECT_CALL(*test->mComposer,
303 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
304 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700305 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
306 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
307 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
308 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
309
310 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700311
312 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
313 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
314
315 Case::CompositionType::setupHwcSetCallExpectations(test);
316 Case::CompositionType::setupHwcGetCallExpectations(test);
317 }
318
319 template <typename Case>
320 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000321 EXPECT_CALL(*test->mRenderEngine, drawLayers)
322 .WillRepeatedly(
323 [](const renderengine::DisplaySettings& displaySettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700324 const std::vector<renderengine::LayerSettings>&, ANativeWindowBuffer*,
325 const bool, base::unique_fd&&, base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000326 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
327 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
328 displaySettings.physicalDisplay);
329 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
330 displaySettings.clip);
331 return NO_ERROR;
332 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700333 }
334
335 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
336 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
337 }
338
339 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
340 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
341 }
342
343 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800344 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
345
Lloyd Pique542307f2018-10-19 13:24:08 -0700346 EXPECT_CALL(*test->mDisplaySurface,
347 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC))
348 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700349 }
350
Lloyd Pique66d68602019-02-13 14:23:31 -0800351 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
352 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
353 }
354
355 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
356 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1);
357 }
358
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700359 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700360 EXPECT_CALL(*test->mDisplaySurface,
361 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_GLES))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700362 .Times(1);
363 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
364 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
365
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800366 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
367 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
368 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
369 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000370 EXPECT_CALL(*test->mRenderEngine, drawLayers)
371 .WillRepeatedly(
372 [](const renderengine::DisplaySettings& displaySettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700373 const std::vector<renderengine::LayerSettings>&, ANativeWindowBuffer*,
374 const bool, base::unique_fd&&, base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000375 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
376 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
377 displaySettings.physicalDisplay);
378 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
379 displaySettings.clip);
380 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
381 return NO_ERROR;
382 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700383 }
384
385 template <typename Case>
386 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
387 Case::Layer::setupRECompositionCallExpectations(test);
388 }
389
390 template <typename Case>
391 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
392 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700393 }
394};
395
396struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
397
398struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
399 static constexpr bool IS_SECURE = false;
400
401 template <typename Case>
402 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
403 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700404 }
405
406 template <typename Case>
407 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
408 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700409 }
410};
411
412struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
413 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_OFF;
414
415 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700416 static void setupPreconditionCallExpectations(CompositionTest*) {}
417
418 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700419 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800420 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
421
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700422 // TODO: This seems like an unnecessary call if display is powered off.
423 EXPECT_CALL(*test->mComposer,
424 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
425 .Times(1);
426
427 // TODO: This seems like an unnecessary call if display is powered off.
428 Case::CompositionType::setupHwcSetCallExpectations(test);
429 }
430
431 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800432 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
433 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700434
435 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800436 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
437
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700438 // TODO: This seems like an unnecessary call if display is powered off.
439 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
440 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
441 }
442
443 template <typename Case>
444 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
445};
446
447/* ------------------------------------------------------------------------
448 * Variants for each layer configuration which can be tested
449 */
450
451template <typename LayerProperties>
452struct BaseLayerProperties {
453 static constexpr uint32_t WIDTH = 100;
454 static constexpr uint32_t HEIGHT = 100;
455 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
456 static constexpr uint64_t USAGE =
457 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
458 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
459 static constexpr uint32_t SCALING_MODE = 0;
460 static constexpr uint32_t TRANSFORM = 0;
461 static constexpr uint32_t LAYER_FLAGS = 0;
462 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
463 static constexpr IComposerClient::BlendMode BLENDMODE =
464 IComposerClient::BlendMode::PREMULTIPLIED;
465
466 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
467 auto producer = layer->getProducer();
468
469 IGraphicBufferProducer::QueueBufferOutput qbo;
470 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
471 if (result != NO_ERROR) {
472 ALOGE("Failed to connect() (%d)", result);
473 return;
474 }
475
476 int slot;
477 sp<Fence> fence;
478 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
479 LayerProperties::HEIGHT, LayerProperties::FORMAT,
480 LayerProperties::USAGE, nullptr, nullptr);
481 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
482 ALOGE("Failed to dequeueBuffer() (%d)", result);
483 return;
484 }
485
486 sp<GraphicBuffer> buffer;
487 result = producer->requestBuffer(slot, &buffer);
488 if (result != NO_ERROR) {
489 ALOGE("Failed to requestBuffer() (%d)", result);
490 return;
491 }
492
493 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
494 LayerProperties::DATASPACE,
495 Rect(LayerProperties::WIDTH,
496 LayerProperties::HEIGHT),
497 LayerProperties::SCALING_MODE,
498 LayerProperties::TRANSFORM, Fence::NO_FENCE);
499 result = producer->queueBuffer(slot, qbi, &qbo);
500 if (result != NO_ERROR) {
501 ALOGE("Failed to queueBuffer (%d)", result);
502 return;
503 }
504 }
505
506 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
507 // TODO: Eliminate the complexity of actually creating a buffer
508 EXPECT_CALL(*test->mRenderEngine, getMaxTextureSize()).WillOnce(Return(16384));
509 EXPECT_CALL(*test->mRenderEngine, getMaxViewportDims()).WillOnce(Return(16384));
510 status_t err =
511 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
512 LayerProperties::FORMAT);
513 ASSERT_EQ(NO_ERROR, err);
514 Mock::VerifyAndClear(test->mRenderEngine);
515
516 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
517 enqueueBuffer(test, layer);
518 Mock::VerifyAndClear(test->mMessageQueue);
519
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700520 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700521 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700522 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700523 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700524 }
525
526 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
527 setupLatchedBuffer(test, layer);
528 }
529
530 static void setupBufferLayerPostFrameCallExpectations(CompositionTest* test) {
531 // BufferLayer::onPostComposition(), when there is no present fence
532 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY, _))
533 .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE)));
534 }
535
536 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
537 // TODO: Coverage of other values
538 EXPECT_CALL(*test->mComposer,
539 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
540 .Times(1);
541 // TODO: Coverage of other values for origin
542 EXPECT_CALL(*test->mComposer,
543 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
544 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
545 LayerProperties::HEIGHT})))
546 .Times(1);
547 EXPECT_CALL(*test->mComposer,
548 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
549 .Times(1);
550 // TODO: Coverage of other values
551 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
552 // TODO: Coverage of other values
553 EXPECT_CALL(*test->mComposer, setLayerInfo(HWC_DISPLAY, HWC_LAYER, 0u, 0u)).Times(1);
554
555 // These expectations retire on saturation as the code path these
556 // expectations are for appears to make an extra call to them.
557 // TODO: Investigate this extra call
558 EXPECT_CALL(*test->mComposer, setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
David Sodman15094112018-10-11 09:39:37 -0700559 .Times(AtLeast(1))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700560 .RetiresOnSaturation();
561 }
562
563 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
564 EXPECT_CALL(*test->mComposer,
565 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
566 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
567 LayerProperties::HEIGHT})))
568 .Times(1);
569 }
570
571 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
572 EXPECT_CALL(*test->mComposer,
573 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
574 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
575 .Times(1);
576 }
577
578 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
579 EXPECT_CALL(*test->mComposer,
580 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
581 std::vector<IComposerClient::Rect>({IComposerClient::Rect(
582 {0, 0, LayerProperties::WIDTH,
583 LayerProperties::HEIGHT})})))
584 .Times(1);
585 }
586
587 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
588 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
589
590 // TODO: use COLOR
591 EXPECT_CALL(*test->mComposer,
592 setLayerColor(HWC_DISPLAY, HWC_LAYER,
593 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
594 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700595 }
596
597 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
598 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
599 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
600
601 setupBufferLayerPostFrameCallExpectations(test);
602 }
603
604 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000605 EXPECT_CALL(*test->mRenderEngine, drawLayers)
606 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
607 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700608 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800609 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000610 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
611 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
612 displaySettings.physicalDisplay);
613 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
614 displaySettings.clip);
615 // screen capture adds an additional color layer as an alpha
616 // prefill, so gtet the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800617 if (layerSettings.empty()) {
618 ADD_FAILURE() << "layerSettings was not expected to be empty in "
619 "setupREBufferCompositionCommonCallExpectations "
620 "verification lambda";
621 return NO_ERROR;
622 }
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000623 renderengine::LayerSettings layer = layerSettings.back();
624 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
625 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000626 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
627 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
628 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
629 EXPECT_EQ(false, layer.source.buffer.isOpaque);
630 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
631 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
632 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
633 return NO_ERROR;
634 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700635 }
636
637 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
638 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700639 }
640
641 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
642 setupREBufferCompositionCallExpectations(test);
643 }
644
645 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
646 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
647 }
648
649 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
650 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
651 }
652
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700653 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000654 EXPECT_CALL(*test->mRenderEngine, drawLayers)
655 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
656 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700657 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800658 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000659 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
660 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
661 displaySettings.physicalDisplay);
662 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
663 displaySettings.clip);
664 // screen capture adds an additional color layer as an alpha
665 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800666 if (layerSettings.empty()) {
667 ADD_FAILURE()
668 << "layerSettings was not expected to be empty in "
669 "setupREColorCompositionCallExpectations verification lambda";
670 return NO_ERROR;
671 }
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000672 renderengine::LayerSettings layer = layerSettings.back();
673 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
674 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
675 LayerProperties::COLOR[2]),
676 layer.source.solidColor);
677 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
678 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
679 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
680 return NO_ERROR;
681 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700682 }
683
684 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
685 setupREColorCompositionCallExpectations(test);
686 }
687};
688
689struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
690
691struct ColorLayerProperties : public BaseLayerProperties<ColorLayerProperties> {};
692
693struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
694 using Base = BaseLayerProperties<SidebandLayerProperties>;
695 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
696
697 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
698 sp<NativeHandle> stream =
699 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
700 false);
701 test->mFlinger.setLayerSidebandStream(layer, stream);
702 }
703
704 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
705 EXPECT_CALL(*test->mComposer,
706 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
707 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
708 .Times(1);
709 }
710
711 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
712 EXPECT_CALL(*test->mComposer,
713 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
714 reinterpret_cast<native_handle_t*>(
715 DEFAULT_SIDEBAND_STREAM)))
716 .WillOnce(Return(Error::NONE));
717
718 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
719 }
720
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000721 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700722};
723
724struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> {
725 using Base = BaseLayerProperties<SecureLayerProperties>;
726
727 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
728
729 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000730 EXPECT_CALL(*test->mRenderEngine, drawLayers)
731 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
732 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700733 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800734 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000735 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
736 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
737 displaySettings.physicalDisplay);
738 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
739 displaySettings.clip);
740 // screen capture adds an additional color layer as an alpha
741 // prefill, so get the back layer.
Lloyd Piquea2468662019-03-07 21:31:06 -0800742 if (layerSettings.empty()) {
743 ADD_FAILURE() << "layerSettings was not expected to be empty in "
744 "setupInsecureREBufferCompositionCommonCallExpectations "
745 "verification lambda";
746 return NO_ERROR;
747 }
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000748 renderengine::LayerSettings layer = layerSettings.back();
749 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
750 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
751 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
752 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
753 EXPECT_EQ(1.0f, layer.alpha);
754 return NO_ERROR;
755 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700756 }
757
758 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
759 setupInsecureREBufferCompositionCommonCallExpectations(test);
760 Base::setupBufferLayerPostFrameCallExpectations(test);
761 }
762
763 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
764 setupInsecureREBufferCompositionCommonCallExpectations(test);
765 }
766};
767
768struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
769 using Base = BaseLayerProperties<CursorLayerProperties>;
770
771 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
772 Base::setupLayerState(test, layer);
773 test->mFlinger.setLayerPotentialCursor(layer, true);
774 }
775};
776
777struct NoLayerVariant {
778 using FlingerLayerType = sp<BufferQueueLayer>;
779
780 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
781 static void injectLayer(CompositionTest*, FlingerLayerType) {}
782 static void cleanupInjectedLayers(CompositionTest*) {}
783
784 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
785 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
786};
787
788template <typename LayerProperties>
789struct BaseLayerVariant {
790 template <typename L, typename F>
791 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
792 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0);
793
794 sp<L> layer = factory();
795
796 Mock::VerifyAndClear(test->mComposer);
797 Mock::VerifyAndClear(test->mRenderEngine);
798 Mock::VerifyAndClear(test->mMessageQueue);
799
800 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
801 layerDrawingState.layerStack = DEFAULT_LAYER_STACK;
802 layerDrawingState.active.w = 100;
803 layerDrawingState.active.h = 100;
804 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
805 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nair4351ad52019-02-11 14:13:02 -0800806 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700807
808 return layer;
809 }
810
811 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
812 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
813 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
814
Lloyd Pique07e33212018-12-18 16:33:37 -0800815 std::vector<std::unique_ptr<compositionengine::OutputLayer>> outputLayers;
816 outputLayers.emplace_back(test->mDisplay->getCompositionDisplay()
Lloyd Piquedf336d92019-03-07 21:38:42 -0800817 ->createOutputLayer(layer->getCompositionLayer(), layer));
Lloyd Pique07e33212018-12-18 16:33:37 -0800818
Lloyd Piquea2468662019-03-07 21:31:06 -0800819 outputLayers.back()->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
820 outputLayers.back()->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
821
Lloyd Pique07e33212018-12-18 16:33:37 -0800822 test->mDisplay->getCompositionDisplay()->setOutputLayersOrderedByZ(std::move(outputLayers));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700823
824 Mock::VerifyAndClear(test->mComposer);
825
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700826 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
827 }
828
829 static void cleanupInjectedLayers(CompositionTest* test) {
830 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
831 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800832
833 test->mDisplay->getCompositionDisplay()->setOutputLayersOrderedByZ(
834 std::vector<std::unique_ptr<compositionengine::OutputLayer>>());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700835 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
836 }
837};
838
839template <typename LayerProperties>
840struct ColorLayerVariant : public BaseLayerVariant<LayerProperties> {
841 using Base = BaseLayerVariant<LayerProperties>;
842 using FlingerLayerType = sp<ColorLayer>;
843
844 static FlingerLayerType createLayer(CompositionTest* test) {
845 FlingerLayerType layer = Base::template createLayerWithFactory<ColorLayer>(test, [test]() {
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700846 return new ColorLayer(LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
847 String8("test-layer"), LayerProperties::WIDTH,
848 LayerProperties::HEIGHT,
Evan Roskya1f1e152019-01-24 16:17:46 -0800849 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700850 });
Vishnu Nair60356342018-11-13 13:00:45 -0800851
852 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
853 layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700854 return layer;
855 }
856
857 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700858 LayerProperties::setupREColorCompositionCallExpectations(test);
859 }
860
861 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
862 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
863 }
864
865 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
866 LayerProperties::setupHwcSetGeometryCallExpectations(test);
867 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
868 }
869
870 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
871 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
872 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
873 }
874};
875
876template <typename LayerProperties>
877struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
878 using Base = BaseLayerVariant<LayerProperties>;
879 using FlingerLayerType = sp<BufferQueueLayer>;
880
881 static FlingerLayerType createLayer(CompositionTest* test) {
882 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
883
884 FlingerLayerType layer =
885 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700886 return new BufferQueueLayer(
887 LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
888 String8("test-layer"), LayerProperties::WIDTH,
889 LayerProperties::HEIGHT,
Evan Roskya1f1e152019-01-24 16:17:46 -0800890 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700891 });
892
893 LayerProperties::setupLayerState(test, layer);
894
895 return layer;
896 }
897
898 static void cleanupInjectedLayers(CompositionTest* test) {
Dan Stoza67765d82019-05-07 14:58:27 -0700899 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700900 Base::cleanupInjectedLayers(test);
901 }
902
903 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
904 LayerProperties::setupHwcSetGeometryCallExpectations(test);
905 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
906 }
907
908 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
909 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
910 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
911 }
912
913 static void setupRECompositionCallExpectations(CompositionTest* test) {
914 LayerProperties::setupREBufferCompositionCallExpectations(test);
915 }
916
917 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
918 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
919 }
920
921 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
922 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
923 }
924
925 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
926 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
927 }
928};
929
930/* ------------------------------------------------------------------------
931 * Variants to control how the composition type is changed
932 */
933
934struct NoCompositionTypeVariant {
935 static void setupHwcSetCallExpectations(CompositionTest*) {}
936
937 static void setupHwcGetCallExpectations(CompositionTest* test) {
938 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
939 }
940};
941
942template <IComposerClient::Composition CompositionType>
943struct KeepCompositionTypeVariant {
944 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(CompositionType);
945
946 static void setupHwcSetCallExpectations(CompositionTest* test) {
947 EXPECT_CALL(*test->mComposer,
948 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
949 .Times(1);
950 }
951
952 static void setupHwcGetCallExpectations(CompositionTest* test) {
953 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
954 }
955};
956
957template <IComposerClient::Composition InitialCompositionType,
958 IComposerClient::Composition FinalCompositionType>
959struct ChangeCompositionTypeVariant {
960 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(FinalCompositionType);
961
962 static void setupHwcSetCallExpectations(CompositionTest* test) {
963 EXPECT_CALL(*test->mComposer,
964 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
965 .Times(1);
966 }
967
968 static void setupHwcGetCallExpectations(CompositionTest* test) {
969 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
970 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
971 static_cast<Hwc2::Layer>(HWC_LAYER)}),
972 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
973 FinalCompositionType}),
974 Return(Error::NONE)));
975 }
976};
977
978/* ------------------------------------------------------------------------
979 * Variants to select how the composition is expected to be handled
980 */
981
982struct CompositionResultBaseVariant {
983 static void setupLayerState(CompositionTest*, sp<Layer>) {}
984
985 template <typename Case>
986 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
987 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
988 }
989
990 template <typename Case>
991 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
992 Case::Layer::setupCallExpectationsForDirtyFrame(test);
993 }
994};
995
996struct NoCompositionResultVariant : public CompositionResultBaseVariant {
997 template <typename Case>
998 static void setupCallExpectations(CompositionTest* test) {
999 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1000 Case::Display::setupHwcCompositionCallExpectations(test);
1001 }
1002};
1003
1004struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1005 template <typename Case>
1006 static void setupCallExpectations(CompositionTest* test) {
1007 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1008 Case::Display::setupHwcCompositionCallExpectations(test);
1009 }
1010};
1011
1012struct RECompositionResultVariant : public CompositionResultBaseVariant {
1013 template <typename Case>
1014 static void setupCallExpectations(CompositionTest* test) {
1015 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001016 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001017 Case::Display::setupRECompositionCallExpectations(test);
1018 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1019 }
1020};
1021
Lloyd Pique66d68602019-02-13 14:23:31 -08001022struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001023 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piquef5275482019-01-29 18:42:42 -08001024 const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay);
1025 LOG_FATAL_IF(!outputLayer);
1026 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001027 }
1028
1029 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001030 static void setupCallExpectations(CompositionTest* test) {
1031 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1032 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1033 Case::Display::setupRECompositionCallExpectations(test);
1034 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1035 }
1036
1037 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001038 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1039
1040 template <typename Case>
1041 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1042};
1043
1044struct EmptyScreenshotResultVariant {
1045 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1046
1047 template <typename Case>
1048 static void setupCallExpectations(CompositionTest*) {}
1049};
1050
1051struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1052 using Base = EmptyScreenshotResultVariant;
1053
1054 template <typename Case>
1055 static void setupCallExpectations(CompositionTest* test) {
1056 Base::template setupCallExpectations<Case>(test);
1057 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1058 }
1059};
1060
1061/* ------------------------------------------------------------------------
1062 * Composition test case, containing all the variants being tested
1063 */
1064
1065template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1066 typename CompositionResultCase>
1067struct CompositionCase {
1068 using ThisCase =
1069 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1070 using Display = DisplayCase;
1071 using Layer = LayerCase;
1072 using CompositionType = CompositionTypeCase;
1073 using CompositionResult = CompositionResultCase;
1074
1075 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001076 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001077 Display::setupPreconditions(test);
1078
1079 auto layer = Layer::createLayer(test);
1080 Layer::injectLayer(test, layer);
1081 CompositionResult::setupLayerState(test, layer);
1082 }
1083
1084 static void setupForDirtyGeometry(CompositionTest* test) {
1085 setupCommon(test);
1086
1087 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1088 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1089 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1090 CompositionResult::template setupCallExpectations<ThisCase>(test);
1091 }
1092
1093 static void setupForDirtyFrame(CompositionTest* test) {
1094 setupCommon(test);
1095
1096 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1097 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1098 CompositionResult::template setupCallExpectations<ThisCase>(test);
1099 }
1100
1101 static void setupForScreenCapture(CompositionTest* test) {
1102 setupCommon(test);
1103
1104 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1105 CompositionResult::template setupCallExpectations<ThisCase>(test);
1106 }
1107
1108 static void cleanup(CompositionTest* test) {
1109 Layer::cleanupInjectedLayers(test);
1110
1111 for (auto& hwcDisplay : test->mFlinger.mFakeHwcDisplays) {
1112 hwcDisplay->mutableLayers().clear();
1113 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001114 }
1115};
1116
1117/* ------------------------------------------------------------------------
1118 * Composition cases to test
1119 */
1120
1121TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1122 displayRefreshCompositionDirtyGeometry<
1123 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1124 NoCompositionResultVariant>>();
1125}
1126
1127TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1128 displayRefreshCompositionDirtyFrame<
1129 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1130 NoCompositionResultVariant>>();
1131}
1132
1133TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1134 captureScreenComposition<
1135 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1136 EmptyScreenshotResultVariant>>();
1137}
1138
1139/* ------------------------------------------------------------------------
1140 * Simple buffer layers
1141 */
1142
1143TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1144 displayRefreshCompositionDirtyGeometry<
1145 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1146 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1147 HwcCompositionResultVariant>>();
1148}
1149
1150TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1151 displayRefreshCompositionDirtyFrame<
1152 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1153 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1154 HwcCompositionResultVariant>>();
1155}
1156
1157TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1158 displayRefreshCompositionDirtyFrame<
1159 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1160 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1161 IComposerClient::Composition::CLIENT>,
1162 RECompositionResultVariant>>();
1163}
1164
1165TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1166 captureScreenComposition<
1167 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1168 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1169}
1170
1171/* ------------------------------------------------------------------------
1172 * Single-color layers
1173 */
1174
1175TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyGeometry) {
1176 displayRefreshCompositionDirtyGeometry<
1177 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1178 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1179 HwcCompositionResultVariant>>();
1180}
1181
1182TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyFrame) {
1183 displayRefreshCompositionDirtyFrame<
1184 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1185 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1186 HwcCompositionResultVariant>>();
1187}
1188
1189TEST_F(CompositionTest, REComposedColorLayer) {
1190 displayRefreshCompositionDirtyFrame<
1191 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1192 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1193 IComposerClient::Composition::CLIENT>,
1194 RECompositionResultVariant>>();
1195}
1196
1197TEST_F(CompositionTest, captureScreenColorLayer) {
1198 captureScreenComposition<
1199 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1200 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1201}
1202
1203/* ------------------------------------------------------------------------
1204 * Layers with sideband buffers
1205 */
1206
1207TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1208 displayRefreshCompositionDirtyGeometry<
1209 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1210 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1211 HwcCompositionResultVariant>>();
1212}
1213
1214TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1215 displayRefreshCompositionDirtyFrame<
1216 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1217 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1218 HwcCompositionResultVariant>>();
1219}
1220
1221TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1222 displayRefreshCompositionDirtyFrame<
1223 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1224 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1225 IComposerClient::Composition::CLIENT>,
1226 RECompositionResultVariant>>();
1227}
1228
1229TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1230 captureScreenComposition<
1231 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1232 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1233}
1234
1235/* ------------------------------------------------------------------------
1236 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1237 */
1238
1239TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1240 displayRefreshCompositionDirtyGeometry<
1241 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1242 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1243 HwcCompositionResultVariant>>();
1244}
1245
1246TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1247 displayRefreshCompositionDirtyFrame<
1248 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1249 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1250 HwcCompositionResultVariant>>();
1251}
1252
1253TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1254 displayRefreshCompositionDirtyFrame<
1255 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1256 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1257 IComposerClient::Composition::CLIENT>,
1258 RECompositionResultVariant>>();
1259}
1260
1261TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1262 captureScreenComposition<
1263 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1264 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1265}
1266
1267/* ------------------------------------------------------------------------
1268 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1269 */
1270
1271TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1272 displayRefreshCompositionDirtyGeometry<
1273 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1274 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1275 ForcedClientCompositionResultVariant>>();
1276}
1277
1278TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1279 displayRefreshCompositionDirtyFrame<
1280 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1281 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1282 ForcedClientCompositionResultVariant>>();
1283}
1284
1285TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1286 captureScreenComposition<
1287 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1288 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1289}
1290
1291/* ------------------------------------------------------------------------
1292 * Cursor layers
1293 */
1294
1295TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1296 displayRefreshCompositionDirtyGeometry<
1297 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1298 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1299 HwcCompositionResultVariant>>();
1300}
1301
1302TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1303 displayRefreshCompositionDirtyFrame<
1304 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1305 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1306 HwcCompositionResultVariant>>();
1307}
1308
1309TEST_F(CompositionTest, REComposedCursorLayer) {
1310 displayRefreshCompositionDirtyFrame<
1311 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1312 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1313 IComposerClient::Composition::CLIENT>,
1314 RECompositionResultVariant>>();
1315}
1316
1317TEST_F(CompositionTest, captureScreenCursorLayer) {
1318 captureScreenComposition<
1319 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1320 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1321}
1322
1323/* ------------------------------------------------------------------------
1324 * Simple buffer layer on a display which is powered off.
1325 */
1326
1327TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
1328 displayRefreshCompositionDirtyGeometry<CompositionCase<
1329 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1330 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1331 HwcCompositionResultVariant>>();
1332}
1333
1334TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
1335 displayRefreshCompositionDirtyFrame<CompositionCase<
1336 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1337 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1338 HwcCompositionResultVariant>>();
1339}
1340
1341TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
1342 displayRefreshCompositionDirtyFrame<CompositionCase<
1343 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1344 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1345 IComposerClient::Composition::CLIENT>,
1346 RECompositionResultVariant>>();
1347}
1348
1349TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1350 captureScreenComposition<CompositionCase<
1351 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1352 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1353}
1354
1355} // namespace
1356} // namespace android