blob: 425768e244879d46d3318040c55d6e29ae921c42 [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.
617 renderengine::LayerSettings layer = layerSettings.back();
618 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
619 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000620 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
621 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
622 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
623 EXPECT_EQ(false, layer.source.buffer.isOpaque);
624 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
625 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
626 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
627 return NO_ERROR;
628 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700629 }
630
631 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
632 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700633 }
634
635 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
636 setupREBufferCompositionCallExpectations(test);
637 }
638
639 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
640 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
641 }
642
643 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
644 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
645 }
646
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700647 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000648 EXPECT_CALL(*test->mRenderEngine, drawLayers)
649 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
650 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700651 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800652 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000653 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
654 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
655 displaySettings.physicalDisplay);
656 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
657 displaySettings.clip);
658 // screen capture adds an additional color layer as an alpha
659 // prefill, so get the back layer.
660 renderengine::LayerSettings layer = layerSettings.back();
661 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
662 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
663 LayerProperties::COLOR[2]),
664 layer.source.solidColor);
665 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
666 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
667 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
668 return NO_ERROR;
669 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700670 }
671
672 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
673 setupREColorCompositionCallExpectations(test);
674 }
675};
676
677struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
678
679struct ColorLayerProperties : public BaseLayerProperties<ColorLayerProperties> {};
680
681struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
682 using Base = BaseLayerProperties<SidebandLayerProperties>;
683 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
684
685 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
686 sp<NativeHandle> stream =
687 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
688 false);
689 test->mFlinger.setLayerSidebandStream(layer, stream);
690 }
691
692 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
693 EXPECT_CALL(*test->mComposer,
694 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
695 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
696 .Times(1);
697 }
698
699 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
700 EXPECT_CALL(*test->mComposer,
701 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
702 reinterpret_cast<native_handle_t*>(
703 DEFAULT_SIDEBAND_STREAM)))
704 .WillOnce(Return(Error::NONE));
705
706 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
707 }
708
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000709 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700710};
711
712struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> {
713 using Base = BaseLayerProperties<SecureLayerProperties>;
714
715 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
716
717 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000718 EXPECT_CALL(*test->mRenderEngine, drawLayers)
719 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
720 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700721 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800722 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000723 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
724 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
725 displaySettings.physicalDisplay);
726 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
727 displaySettings.clip);
728 // screen capture adds an additional color layer as an alpha
729 // prefill, so get the back layer.
730 renderengine::LayerSettings layer = layerSettings.back();
731 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
732 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
733 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
734 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
735 EXPECT_EQ(1.0f, layer.alpha);
736 return NO_ERROR;
737 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700738 }
739
740 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
741 setupInsecureREBufferCompositionCommonCallExpectations(test);
742 Base::setupBufferLayerPostFrameCallExpectations(test);
743 }
744
745 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
746 setupInsecureREBufferCompositionCommonCallExpectations(test);
747 }
748};
749
750struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
751 using Base = BaseLayerProperties<CursorLayerProperties>;
752
753 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
754 Base::setupLayerState(test, layer);
755 test->mFlinger.setLayerPotentialCursor(layer, true);
756 }
757};
758
759struct NoLayerVariant {
760 using FlingerLayerType = sp<BufferQueueLayer>;
761
762 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
763 static void injectLayer(CompositionTest*, FlingerLayerType) {}
764 static void cleanupInjectedLayers(CompositionTest*) {}
765
766 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
767 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
768};
769
770template <typename LayerProperties>
771struct BaseLayerVariant {
772 template <typename L, typename F>
773 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
774 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0);
775
776 sp<L> layer = factory();
777
778 Mock::VerifyAndClear(test->mComposer);
779 Mock::VerifyAndClear(test->mRenderEngine);
780 Mock::VerifyAndClear(test->mMessageQueue);
781
782 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
783 layerDrawingState.layerStack = DEFAULT_LAYER_STACK;
784 layerDrawingState.active.w = 100;
785 layerDrawingState.active.h = 100;
786 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
787 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nair4351ad52019-02-11 14:13:02 -0800788 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700789 layer->setVisibleRegion(Region(Rect(0, 0, 100, 100)));
790
791 return layer;
792 }
793
794 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
795 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
796 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
797
Lloyd Pique07e33212018-12-18 16:33:37 -0800798 std::vector<std::unique_ptr<compositionengine::OutputLayer>> outputLayers;
799 outputLayers.emplace_back(test->mDisplay->getCompositionDisplay()
800 ->getOrCreateOutputLayer(DEFAULT_DISPLAY_ID,
801 layer->getCompositionLayer(),
802 layer));
803
804 test->mDisplay->getCompositionDisplay()->setOutputLayersOrderedByZ(std::move(outputLayers));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700805
806 Mock::VerifyAndClear(test->mComposer);
807
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700808 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
809 }
810
811 static void cleanupInjectedLayers(CompositionTest* test) {
812 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
813 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800814
815 test->mDisplay->getCompositionDisplay()->setOutputLayersOrderedByZ(
816 std::vector<std::unique_ptr<compositionengine::OutputLayer>>());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700817 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
818 }
819};
820
821template <typename LayerProperties>
822struct ColorLayerVariant : public BaseLayerVariant<LayerProperties> {
823 using Base = BaseLayerVariant<LayerProperties>;
824 using FlingerLayerType = sp<ColorLayer>;
825
826 static FlingerLayerType createLayer(CompositionTest* test) {
827 FlingerLayerType layer = Base::template createLayerWithFactory<ColorLayer>(test, [test]() {
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700828 return new ColorLayer(LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
829 String8("test-layer"), LayerProperties::WIDTH,
830 LayerProperties::HEIGHT,
Evan Roskya1f1e152019-01-24 16:17:46 -0800831 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700832 });
Vishnu Nair60356342018-11-13 13:00:45 -0800833
834 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
835 layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700836 return layer;
837 }
838
839 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700840 LayerProperties::setupREColorCompositionCallExpectations(test);
841 }
842
843 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
844 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
845 }
846
847 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
848 LayerProperties::setupHwcSetGeometryCallExpectations(test);
849 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
850 }
851
852 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
853 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
854 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
855 }
856};
857
858template <typename LayerProperties>
859struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
860 using Base = BaseLayerVariant<LayerProperties>;
861 using FlingerLayerType = sp<BufferQueueLayer>;
862
863 static FlingerLayerType createLayer(CompositionTest* test) {
864 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
865
866 FlingerLayerType layer =
867 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700868 return new BufferQueueLayer(
869 LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
870 String8("test-layer"), LayerProperties::WIDTH,
871 LayerProperties::HEIGHT,
Evan Roskya1f1e152019-01-24 16:17:46 -0800872 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700873 });
874
875 LayerProperties::setupLayerState(test, layer);
876
877 return layer;
878 }
879
880 static void cleanupInjectedLayers(CompositionTest* test) {
Dan Stoza67765d82019-05-07 14:58:27 -0700881 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700882 Base::cleanupInjectedLayers(test);
883 }
884
885 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
886 LayerProperties::setupHwcSetGeometryCallExpectations(test);
887 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
888 }
889
890 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
891 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
892 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
893 }
894
895 static void setupRECompositionCallExpectations(CompositionTest* test) {
896 LayerProperties::setupREBufferCompositionCallExpectations(test);
897 }
898
899 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
900 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
901 }
902
903 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
904 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
905 }
906
907 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
908 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
909 }
910};
911
912/* ------------------------------------------------------------------------
913 * Variants to control how the composition type is changed
914 */
915
916struct NoCompositionTypeVariant {
917 static void setupHwcSetCallExpectations(CompositionTest*) {}
918
919 static void setupHwcGetCallExpectations(CompositionTest* test) {
920 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
921 }
922};
923
924template <IComposerClient::Composition CompositionType>
925struct KeepCompositionTypeVariant {
926 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(CompositionType);
927
928 static void setupHwcSetCallExpectations(CompositionTest* test) {
929 EXPECT_CALL(*test->mComposer,
930 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
931 .Times(1);
932 }
933
934 static void setupHwcGetCallExpectations(CompositionTest* test) {
935 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
936 }
937};
938
939template <IComposerClient::Composition InitialCompositionType,
940 IComposerClient::Composition FinalCompositionType>
941struct ChangeCompositionTypeVariant {
942 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(FinalCompositionType);
943
944 static void setupHwcSetCallExpectations(CompositionTest* test) {
945 EXPECT_CALL(*test->mComposer,
946 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
947 .Times(1);
948 }
949
950 static void setupHwcGetCallExpectations(CompositionTest* test) {
951 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
952 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
953 static_cast<Hwc2::Layer>(HWC_LAYER)}),
954 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
955 FinalCompositionType}),
956 Return(Error::NONE)));
957 }
958};
959
960/* ------------------------------------------------------------------------
961 * Variants to select how the composition is expected to be handled
962 */
963
964struct CompositionResultBaseVariant {
965 static void setupLayerState(CompositionTest*, sp<Layer>) {}
966
967 template <typename Case>
968 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
969 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
970 }
971
972 template <typename Case>
973 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
974 Case::Layer::setupCallExpectationsForDirtyFrame(test);
975 }
976};
977
978struct NoCompositionResultVariant : public CompositionResultBaseVariant {
979 template <typename Case>
980 static void setupCallExpectations(CompositionTest* test) {
981 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
982 Case::Display::setupHwcCompositionCallExpectations(test);
983 }
984};
985
986struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
987 template <typename Case>
988 static void setupCallExpectations(CompositionTest* test) {
989 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
990 Case::Display::setupHwcCompositionCallExpectations(test);
991 }
992};
993
994struct RECompositionResultVariant : public CompositionResultBaseVariant {
995 template <typename Case>
996 static void setupCallExpectations(CompositionTest* test) {
997 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -0800998 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700999 Case::Display::setupRECompositionCallExpectations(test);
1000 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1001 }
1002};
1003
Lloyd Pique66d68602019-02-13 14:23:31 -08001004struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001005 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piquef5275482019-01-29 18:42:42 -08001006 const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay);
1007 LOG_FATAL_IF(!outputLayer);
1008 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001009 }
1010
1011 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001012 static void setupCallExpectations(CompositionTest* test) {
1013 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1014 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1015 Case::Display::setupRECompositionCallExpectations(test);
1016 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1017 }
1018
1019 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001020 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1021
1022 template <typename Case>
1023 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1024};
1025
1026struct EmptyScreenshotResultVariant {
1027 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1028
1029 template <typename Case>
1030 static void setupCallExpectations(CompositionTest*) {}
1031};
1032
1033struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1034 using Base = EmptyScreenshotResultVariant;
1035
1036 template <typename Case>
1037 static void setupCallExpectations(CompositionTest* test) {
1038 Base::template setupCallExpectations<Case>(test);
1039 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1040 }
1041};
1042
1043/* ------------------------------------------------------------------------
1044 * Composition test case, containing all the variants being tested
1045 */
1046
1047template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1048 typename CompositionResultCase>
1049struct CompositionCase {
1050 using ThisCase =
1051 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1052 using Display = DisplayCase;
1053 using Layer = LayerCase;
1054 using CompositionType = CompositionTypeCase;
1055 using CompositionResult = CompositionResultCase;
1056
1057 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001058 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001059 Display::setupPreconditions(test);
1060
1061 auto layer = Layer::createLayer(test);
1062 Layer::injectLayer(test, layer);
1063 CompositionResult::setupLayerState(test, layer);
1064 }
1065
1066 static void setupForDirtyGeometry(CompositionTest* test) {
1067 setupCommon(test);
1068
1069 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1070 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1071 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1072 CompositionResult::template setupCallExpectations<ThisCase>(test);
1073 }
1074
1075 static void setupForDirtyFrame(CompositionTest* test) {
1076 setupCommon(test);
1077
1078 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1079 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1080 CompositionResult::template setupCallExpectations<ThisCase>(test);
1081 }
1082
1083 static void setupForScreenCapture(CompositionTest* test) {
1084 setupCommon(test);
1085
1086 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1087 CompositionResult::template setupCallExpectations<ThisCase>(test);
1088 }
1089
1090 static void cleanup(CompositionTest* test) {
1091 Layer::cleanupInjectedLayers(test);
1092
1093 for (auto& hwcDisplay : test->mFlinger.mFakeHwcDisplays) {
1094 hwcDisplay->mutableLayers().clear();
1095 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001096 }
1097};
1098
1099/* ------------------------------------------------------------------------
1100 * Composition cases to test
1101 */
1102
1103TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1104 displayRefreshCompositionDirtyGeometry<
1105 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1106 NoCompositionResultVariant>>();
1107}
1108
1109TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1110 displayRefreshCompositionDirtyFrame<
1111 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1112 NoCompositionResultVariant>>();
1113}
1114
1115TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1116 captureScreenComposition<
1117 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1118 EmptyScreenshotResultVariant>>();
1119}
1120
1121/* ------------------------------------------------------------------------
1122 * Simple buffer layers
1123 */
1124
1125TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1126 displayRefreshCompositionDirtyGeometry<
1127 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1128 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1129 HwcCompositionResultVariant>>();
1130}
1131
1132TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1133 displayRefreshCompositionDirtyFrame<
1134 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1135 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1136 HwcCompositionResultVariant>>();
1137}
1138
1139TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1140 displayRefreshCompositionDirtyFrame<
1141 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1142 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1143 IComposerClient::Composition::CLIENT>,
1144 RECompositionResultVariant>>();
1145}
1146
1147TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1148 captureScreenComposition<
1149 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1150 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1151}
1152
1153/* ------------------------------------------------------------------------
1154 * Single-color layers
1155 */
1156
1157TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyGeometry) {
1158 displayRefreshCompositionDirtyGeometry<
1159 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1160 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1161 HwcCompositionResultVariant>>();
1162}
1163
1164TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyFrame) {
1165 displayRefreshCompositionDirtyFrame<
1166 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1167 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1168 HwcCompositionResultVariant>>();
1169}
1170
1171TEST_F(CompositionTest, REComposedColorLayer) {
1172 displayRefreshCompositionDirtyFrame<
1173 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1174 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1175 IComposerClient::Composition::CLIENT>,
1176 RECompositionResultVariant>>();
1177}
1178
1179TEST_F(CompositionTest, captureScreenColorLayer) {
1180 captureScreenComposition<
1181 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1182 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1183}
1184
1185/* ------------------------------------------------------------------------
1186 * Layers with sideband buffers
1187 */
1188
1189TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1190 displayRefreshCompositionDirtyGeometry<
1191 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1192 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1193 HwcCompositionResultVariant>>();
1194}
1195
1196TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1197 displayRefreshCompositionDirtyFrame<
1198 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1199 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1200 HwcCompositionResultVariant>>();
1201}
1202
1203TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1204 displayRefreshCompositionDirtyFrame<
1205 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1206 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1207 IComposerClient::Composition::CLIENT>,
1208 RECompositionResultVariant>>();
1209}
1210
1211TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1212 captureScreenComposition<
1213 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1214 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1215}
1216
1217/* ------------------------------------------------------------------------
1218 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1219 */
1220
1221TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1222 displayRefreshCompositionDirtyGeometry<
1223 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1224 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1225 HwcCompositionResultVariant>>();
1226}
1227
1228TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1229 displayRefreshCompositionDirtyFrame<
1230 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1231 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1232 HwcCompositionResultVariant>>();
1233}
1234
1235TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1236 displayRefreshCompositionDirtyFrame<
1237 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1238 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1239 IComposerClient::Composition::CLIENT>,
1240 RECompositionResultVariant>>();
1241}
1242
1243TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1244 captureScreenComposition<
1245 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1246 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1247}
1248
1249/* ------------------------------------------------------------------------
1250 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1251 */
1252
1253TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1254 displayRefreshCompositionDirtyGeometry<
1255 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1256 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1257 ForcedClientCompositionResultVariant>>();
1258}
1259
1260TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1261 displayRefreshCompositionDirtyFrame<
1262 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1263 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1264 ForcedClientCompositionResultVariant>>();
1265}
1266
1267TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1268 captureScreenComposition<
1269 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1270 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1271}
1272
1273/* ------------------------------------------------------------------------
1274 * Cursor layers
1275 */
1276
1277TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1278 displayRefreshCompositionDirtyGeometry<
1279 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1280 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1281 HwcCompositionResultVariant>>();
1282}
1283
1284TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1285 displayRefreshCompositionDirtyFrame<
1286 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1287 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1288 HwcCompositionResultVariant>>();
1289}
1290
1291TEST_F(CompositionTest, REComposedCursorLayer) {
1292 displayRefreshCompositionDirtyFrame<
1293 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1294 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1295 IComposerClient::Composition::CLIENT>,
1296 RECompositionResultVariant>>();
1297}
1298
1299TEST_F(CompositionTest, captureScreenCursorLayer) {
1300 captureScreenComposition<
1301 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1302 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1303}
1304
1305/* ------------------------------------------------------------------------
1306 * Simple buffer layer on a display which is powered off.
1307 */
1308
1309TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
1310 displayRefreshCompositionDirtyGeometry<CompositionCase<
1311 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1312 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1313 HwcCompositionResultVariant>>();
1314}
1315
1316TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
1317 displayRefreshCompositionDirtyFrame<CompositionCase<
1318 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1319 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1320 HwcCompositionResultVariant>>();
1321}
1322
1323TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
1324 displayRefreshCompositionDirtyFrame<CompositionCase<
1325 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1326 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1327 IComposerClient::Composition::CLIENT>,
1328 RECompositionResultVariant>>();
1329}
1330
1331TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1332 captureScreenComposition<CompositionCase<
1333 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1334 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1335}
1336
1337} // namespace
1338} // namespace android