blob: 9e4d57e7dc664b308f5bf8c3de44389149d42e67 [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()
817 ->getOrCreateOutputLayer(DEFAULT_DISPLAY_ID,
818 layer->getCompositionLayer(),
819 layer));
820
Lloyd Piquea2468662019-03-07 21:31:06 -0800821 outputLayers.back()->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
822 outputLayers.back()->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
823
Lloyd Pique07e33212018-12-18 16:33:37 -0800824 test->mDisplay->getCompositionDisplay()->setOutputLayersOrderedByZ(std::move(outputLayers));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700825
826 Mock::VerifyAndClear(test->mComposer);
827
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700828 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
829 }
830
831 static void cleanupInjectedLayers(CompositionTest* test) {
832 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
833 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800834
835 test->mDisplay->getCompositionDisplay()->setOutputLayersOrderedByZ(
836 std::vector<std::unique_ptr<compositionengine::OutputLayer>>());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700837 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
838 }
839};
840
841template <typename LayerProperties>
842struct ColorLayerVariant : public BaseLayerVariant<LayerProperties> {
843 using Base = BaseLayerVariant<LayerProperties>;
844 using FlingerLayerType = sp<ColorLayer>;
845
846 static FlingerLayerType createLayer(CompositionTest* test) {
847 FlingerLayerType layer = Base::template createLayerWithFactory<ColorLayer>(test, [test]() {
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700848 return new ColorLayer(LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
849 String8("test-layer"), LayerProperties::WIDTH,
850 LayerProperties::HEIGHT,
Evan Roskya1f1e152019-01-24 16:17:46 -0800851 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700852 });
Vishnu Nair60356342018-11-13 13:00:45 -0800853
854 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
855 layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700856 return layer;
857 }
858
859 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700860 LayerProperties::setupREColorCompositionCallExpectations(test);
861 }
862
863 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
864 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
865 }
866
867 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
868 LayerProperties::setupHwcSetGeometryCallExpectations(test);
869 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
870 }
871
872 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
873 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
874 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
875 }
876};
877
878template <typename LayerProperties>
879struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
880 using Base = BaseLayerVariant<LayerProperties>;
881 using FlingerLayerType = sp<BufferQueueLayer>;
882
883 static FlingerLayerType createLayer(CompositionTest* test) {
884 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
885
886 FlingerLayerType layer =
887 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700888 return new BufferQueueLayer(
889 LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
890 String8("test-layer"), LayerProperties::WIDTH,
891 LayerProperties::HEIGHT,
Evan Roskya1f1e152019-01-24 16:17:46 -0800892 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700893 });
894
895 LayerProperties::setupLayerState(test, layer);
896
897 return layer;
898 }
899
900 static void cleanupInjectedLayers(CompositionTest* test) {
Dan Stoza67765d82019-05-07 14:58:27 -0700901 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700902 Base::cleanupInjectedLayers(test);
903 }
904
905 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
906 LayerProperties::setupHwcSetGeometryCallExpectations(test);
907 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
908 }
909
910 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
911 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
912 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
913 }
914
915 static void setupRECompositionCallExpectations(CompositionTest* test) {
916 LayerProperties::setupREBufferCompositionCallExpectations(test);
917 }
918
919 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
920 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
921 }
922
923 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
924 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
925 }
926
927 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
928 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
929 }
930};
931
932/* ------------------------------------------------------------------------
933 * Variants to control how the composition type is changed
934 */
935
936struct NoCompositionTypeVariant {
937 static void setupHwcSetCallExpectations(CompositionTest*) {}
938
939 static void setupHwcGetCallExpectations(CompositionTest* test) {
940 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
941 }
942};
943
944template <IComposerClient::Composition CompositionType>
945struct KeepCompositionTypeVariant {
946 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(CompositionType);
947
948 static void setupHwcSetCallExpectations(CompositionTest* test) {
949 EXPECT_CALL(*test->mComposer,
950 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
951 .Times(1);
952 }
953
954 static void setupHwcGetCallExpectations(CompositionTest* test) {
955 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
956 }
957};
958
959template <IComposerClient::Composition InitialCompositionType,
960 IComposerClient::Composition FinalCompositionType>
961struct ChangeCompositionTypeVariant {
962 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(FinalCompositionType);
963
964 static void setupHwcSetCallExpectations(CompositionTest* test) {
965 EXPECT_CALL(*test->mComposer,
966 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
967 .Times(1);
968 }
969
970 static void setupHwcGetCallExpectations(CompositionTest* test) {
971 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
972 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
973 static_cast<Hwc2::Layer>(HWC_LAYER)}),
974 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
975 FinalCompositionType}),
976 Return(Error::NONE)));
977 }
978};
979
980/* ------------------------------------------------------------------------
981 * Variants to select how the composition is expected to be handled
982 */
983
984struct CompositionResultBaseVariant {
985 static void setupLayerState(CompositionTest*, sp<Layer>) {}
986
987 template <typename Case>
988 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
989 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
990 }
991
992 template <typename Case>
993 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
994 Case::Layer::setupCallExpectationsForDirtyFrame(test);
995 }
996};
997
998struct NoCompositionResultVariant : public CompositionResultBaseVariant {
999 template <typename Case>
1000 static void setupCallExpectations(CompositionTest* test) {
1001 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1002 Case::Display::setupHwcCompositionCallExpectations(test);
1003 }
1004};
1005
1006struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1007 template <typename Case>
1008 static void setupCallExpectations(CompositionTest* test) {
1009 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1010 Case::Display::setupHwcCompositionCallExpectations(test);
1011 }
1012};
1013
1014struct RECompositionResultVariant : public CompositionResultBaseVariant {
1015 template <typename Case>
1016 static void setupCallExpectations(CompositionTest* test) {
1017 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001018 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001019 Case::Display::setupRECompositionCallExpectations(test);
1020 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1021 }
1022};
1023
Lloyd Pique66d68602019-02-13 14:23:31 -08001024struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001025 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piquef5275482019-01-29 18:42:42 -08001026 const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay);
1027 LOG_FATAL_IF(!outputLayer);
1028 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001029 }
1030
1031 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001032 static void setupCallExpectations(CompositionTest* test) {
1033 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1034 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1035 Case::Display::setupRECompositionCallExpectations(test);
1036 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1037 }
1038
1039 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001040 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1041
1042 template <typename Case>
1043 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1044};
1045
1046struct EmptyScreenshotResultVariant {
1047 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1048
1049 template <typename Case>
1050 static void setupCallExpectations(CompositionTest*) {}
1051};
1052
1053struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1054 using Base = EmptyScreenshotResultVariant;
1055
1056 template <typename Case>
1057 static void setupCallExpectations(CompositionTest* test) {
1058 Base::template setupCallExpectations<Case>(test);
1059 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1060 }
1061};
1062
1063/* ------------------------------------------------------------------------
1064 * Composition test case, containing all the variants being tested
1065 */
1066
1067template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1068 typename CompositionResultCase>
1069struct CompositionCase {
1070 using ThisCase =
1071 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1072 using Display = DisplayCase;
1073 using Layer = LayerCase;
1074 using CompositionType = CompositionTypeCase;
1075 using CompositionResult = CompositionResultCase;
1076
1077 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001078 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001079 Display::setupPreconditions(test);
1080
1081 auto layer = Layer::createLayer(test);
1082 Layer::injectLayer(test, layer);
1083 CompositionResult::setupLayerState(test, layer);
1084 }
1085
1086 static void setupForDirtyGeometry(CompositionTest* test) {
1087 setupCommon(test);
1088
1089 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1090 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1091 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1092 CompositionResult::template setupCallExpectations<ThisCase>(test);
1093 }
1094
1095 static void setupForDirtyFrame(CompositionTest* test) {
1096 setupCommon(test);
1097
1098 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1099 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1100 CompositionResult::template setupCallExpectations<ThisCase>(test);
1101 }
1102
1103 static void setupForScreenCapture(CompositionTest* test) {
1104 setupCommon(test);
1105
1106 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1107 CompositionResult::template setupCallExpectations<ThisCase>(test);
1108 }
1109
1110 static void cleanup(CompositionTest* test) {
1111 Layer::cleanupInjectedLayers(test);
1112
1113 for (auto& hwcDisplay : test->mFlinger.mFakeHwcDisplays) {
1114 hwcDisplay->mutableLayers().clear();
1115 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001116 }
1117};
1118
1119/* ------------------------------------------------------------------------
1120 * Composition cases to test
1121 */
1122
1123TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1124 displayRefreshCompositionDirtyGeometry<
1125 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1126 NoCompositionResultVariant>>();
1127}
1128
1129TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1130 displayRefreshCompositionDirtyFrame<
1131 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1132 NoCompositionResultVariant>>();
1133}
1134
1135TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1136 captureScreenComposition<
1137 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1138 EmptyScreenshotResultVariant>>();
1139}
1140
1141/* ------------------------------------------------------------------------
1142 * Simple buffer layers
1143 */
1144
1145TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1146 displayRefreshCompositionDirtyGeometry<
1147 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1148 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1149 HwcCompositionResultVariant>>();
1150}
1151
1152TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1153 displayRefreshCompositionDirtyFrame<
1154 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1155 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1156 HwcCompositionResultVariant>>();
1157}
1158
1159TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1160 displayRefreshCompositionDirtyFrame<
1161 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1162 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1163 IComposerClient::Composition::CLIENT>,
1164 RECompositionResultVariant>>();
1165}
1166
1167TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1168 captureScreenComposition<
1169 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1170 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1171}
1172
1173/* ------------------------------------------------------------------------
1174 * Single-color layers
1175 */
1176
1177TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyGeometry) {
1178 displayRefreshCompositionDirtyGeometry<
1179 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1180 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1181 HwcCompositionResultVariant>>();
1182}
1183
1184TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyFrame) {
1185 displayRefreshCompositionDirtyFrame<
1186 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1187 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1188 HwcCompositionResultVariant>>();
1189}
1190
1191TEST_F(CompositionTest, REComposedColorLayer) {
1192 displayRefreshCompositionDirtyFrame<
1193 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1194 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1195 IComposerClient::Composition::CLIENT>,
1196 RECompositionResultVariant>>();
1197}
1198
1199TEST_F(CompositionTest, captureScreenColorLayer) {
1200 captureScreenComposition<
1201 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1202 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1203}
1204
1205/* ------------------------------------------------------------------------
1206 * Layers with sideband buffers
1207 */
1208
1209TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1210 displayRefreshCompositionDirtyGeometry<
1211 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1212 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1213 HwcCompositionResultVariant>>();
1214}
1215
1216TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1217 displayRefreshCompositionDirtyFrame<
1218 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1219 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1220 HwcCompositionResultVariant>>();
1221}
1222
1223TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1224 displayRefreshCompositionDirtyFrame<
1225 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1226 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1227 IComposerClient::Composition::CLIENT>,
1228 RECompositionResultVariant>>();
1229}
1230
1231TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1232 captureScreenComposition<
1233 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1234 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1235}
1236
1237/* ------------------------------------------------------------------------
1238 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1239 */
1240
1241TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1242 displayRefreshCompositionDirtyGeometry<
1243 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1244 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1245 HwcCompositionResultVariant>>();
1246}
1247
1248TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1249 displayRefreshCompositionDirtyFrame<
1250 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1251 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1252 HwcCompositionResultVariant>>();
1253}
1254
1255TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1256 displayRefreshCompositionDirtyFrame<
1257 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1258 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1259 IComposerClient::Composition::CLIENT>,
1260 RECompositionResultVariant>>();
1261}
1262
1263TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1264 captureScreenComposition<
1265 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1266 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1267}
1268
1269/* ------------------------------------------------------------------------
1270 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1271 */
1272
1273TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1274 displayRefreshCompositionDirtyGeometry<
1275 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1276 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1277 ForcedClientCompositionResultVariant>>();
1278}
1279
1280TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1281 displayRefreshCompositionDirtyFrame<
1282 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1283 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1284 ForcedClientCompositionResultVariant>>();
1285}
1286
1287TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1288 captureScreenComposition<
1289 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1290 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1291}
1292
1293/* ------------------------------------------------------------------------
1294 * Cursor layers
1295 */
1296
1297TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1298 displayRefreshCompositionDirtyGeometry<
1299 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1300 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1301 HwcCompositionResultVariant>>();
1302}
1303
1304TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1305 displayRefreshCompositionDirtyFrame<
1306 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1307 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1308 HwcCompositionResultVariant>>();
1309}
1310
1311TEST_F(CompositionTest, REComposedCursorLayer) {
1312 displayRefreshCompositionDirtyFrame<
1313 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1314 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1315 IComposerClient::Composition::CLIENT>,
1316 RECompositionResultVariant>>();
1317}
1318
1319TEST_F(CompositionTest, captureScreenCursorLayer) {
1320 captureScreenComposition<
1321 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1322 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1323}
1324
1325/* ------------------------------------------------------------------------
1326 * Simple buffer layer on a display which is powered off.
1327 */
1328
1329TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
1330 displayRefreshCompositionDirtyGeometry<CompositionCase<
1331 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1332 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1333 HwcCompositionResultVariant>>();
1334}
1335
1336TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
1337 displayRefreshCompositionDirtyFrame<CompositionCase<
1338 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1339 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1340 HwcCompositionResultVariant>>();
1341}
1342
1343TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
1344 displayRefreshCompositionDirtyFrame<CompositionCase<
1345 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1346 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1347 IComposerClient::Composition::CLIENT>,
1348 RECompositionResultVariant>>();
1349}
1350
1351TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1352 captureScreenComposition<CompositionCase<
1353 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1354 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1355}
1356
1357} // namespace
1358} // namespace android