blob: 47243a9595eb8fe3ea28adb5dfc204a0c70533f5 [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
Ana Krulecafb45842019-02-13 13:33:03 -080037#include "TestableScheduler.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070038#include "TestableSurfaceFlinger.h"
39#include "mock/DisplayHardware/MockComposer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070040#include "mock/MockDispSync.h"
41#include "mock/MockEventControlThread.h"
42#include "mock/MockEventThread.h"
43#include "mock/MockMessageQueue.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070044#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070045
46namespace android {
47namespace {
48
49using testing::_;
David Sodman15094112018-10-11 09:39:37 -070050using testing::AtLeast;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000051using testing::Between;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070052using testing::ByMove;
53using testing::DoAll;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000054using testing::Field;
Alec Mouri0a9c7b82018-11-16 13:05:25 -080055using testing::Invoke;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070056using testing::IsNull;
57using testing::Mock;
58using testing::NotNull;
59using testing::Ref;
60using testing::Return;
61using testing::ReturnRef;
62using testing::SetArgPointee;
63
64using android::Hwc2::Error;
65using android::Hwc2::IComposer;
66using android::Hwc2::IComposerClient;
67using android::Hwc2::Transform;
68
69using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
70using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
71
72constexpr hwc2_display_t HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
73constexpr hwc2_layer_t HWC_LAYER = 5000;
74constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
75
Dominik Laskowski34157762018-10-31 13:07:19 -070076constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070077constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
78constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
79
80constexpr int DEFAULT_CONFIG_ID = 0;
81constexpr int DEFAULT_TEXTURE_ID = 6000;
82constexpr int DEFAULT_LAYER_STACK = 7000;
83
84constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
85
86constexpr int DEFAULT_SIDEBAND_STREAM = 51;
87
88class CompositionTest : public testing::Test {
89public:
90 CompositionTest() {
91 const ::testing::TestInfo* const test_info =
92 ::testing::UnitTest::GetInstance()->current_test_info();
93 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
94
Lloyd Piqued6b579f2018-04-06 15:29:10 -070095 mFlinger.mutableEventQueue().reset(mMessageQueue);
Ana Krulecafb45842019-02-13 13:33:03 -080096 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -070097
Lloyd Piqued6b579f2018-04-06 15:29:10 -070098 EXPECT_CALL(*mPrimaryDispSync, computeNextRefresh(0)).WillRepeatedly(Return(0));
99 EXPECT_CALL(*mPrimaryDispSync, getPeriod())
100 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE));
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800101 EXPECT_CALL(*mPrimaryDispSync, expectedPresentTime()).WillRepeatedly(Return(0));
Alec Mourif6fd29e2018-11-17 04:56:41 +0000102 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
103 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
104 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
105 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700106
107 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
108 setupComposer(0);
109 }
110
111 ~CompositionTest() {
112 const ::testing::TestInfo* const test_info =
113 ::testing::UnitTest::GetInstance()->current_test_info();
114 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
115 }
116
117 void setupComposer(int virtualDisplayCount) {
118 mComposer = new Hwc2::mock::Composer();
119 EXPECT_CALL(*mComposer, getCapabilities())
120 .WillOnce(Return(std::vector<IComposer::Capability>()));
121 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
122 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
123
124 Mock::VerifyAndClear(mComposer);
125 }
126
Ana Krulecafb45842019-02-13 13:33:03 -0800127 void setupScheduler() {
Ady Abraham09bd3922019-04-08 10:44:56 -0700128 mScheduler = new TestableScheduler(mFlinger.mutableRefreshRateConfigs());
Ana Krulecafb45842019-02-13 13:33:03 -0800129 mScheduler->mutableEventControlThread().reset(mEventControlThread);
130 mScheduler->mutablePrimaryDispSync().reset(mPrimaryDispSync);
131 EXPECT_CALL(*mEventThread.get(), registerDisplayEventConnection(_));
132 sp<Scheduler::ConnectionHandle> connectionHandle =
133 mScheduler->addConnection(std::move(mEventThread));
134 mFlinger.mutableSfConnectionHandle() = std::move(connectionHandle);
135
136 mFlinger.mutableScheduler().reset(mScheduler);
137 }
138
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700139 void setupForceGeometryDirty() {
140 // TODO: This requires the visible region and other related
141 // state to be set, and is problematic for BufferLayers since they are
142 // not visible without a buffer (and setting up a buffer looks like a
143 // pain)
144 // mFlinger.mutableVisibleRegionsDirty() = true;
145
146 mFlinger.mutableGeometryInvalid() = true;
147 }
148
149 template <typename Case>
150 void displayRefreshCompositionDirtyGeometry();
151
152 template <typename Case>
153 void displayRefreshCompositionDirtyFrame();
154
155 template <typename Case>
156 void captureScreenComposition();
157
158 std::unordered_set<HWC2::Capability> mDefaultCapabilities = {HWC2::Capability::SidebandStream};
159
Ana Krulecafb45842019-02-13 13:33:03 -0800160 TestableScheduler* mScheduler;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700161 TestableSurfaceFlinger mFlinger;
162 sp<DisplayDevice> mDisplay;
163 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700164 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
165 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700166 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700167
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800168 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
169 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
170
Ana Krulecafb45842019-02-13 13:33:03 -0800171 std::unique_ptr<mock::EventThread> mEventThread = std::make_unique<mock::EventThread>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700172 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
173
174 Hwc2::mock::Composer* mComposer = nullptr;
175 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
176 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
177 mock::DispSync* mPrimaryDispSync = new mock::DispSync();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700178
179 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
180
181 sp<GraphicBuffer> mCaptureScreenBuffer;
182};
183
184template <typename LayerCase>
185void CompositionTest::displayRefreshCompositionDirtyGeometry() {
186 setupForceGeometryDirty();
187 LayerCase::setupForDirtyGeometry(this);
188
189 // --------------------------------------------------------------------
190 // Invocation
191
192 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
193 mFlinger.onMessageReceived(MessageQueue::REFRESH);
194
195 LayerCase::cleanup(this);
196}
197
198template <typename LayerCase>
199void CompositionTest::displayRefreshCompositionDirtyFrame() {
200 LayerCase::setupForDirtyFrame(this);
201
202 // --------------------------------------------------------------------
203 // Invocation
204
205 mFlinger.onMessageReceived(MessageQueue::INVALIDATE);
206 mFlinger.onMessageReceived(MessageQueue::REFRESH);
207
208 LayerCase::cleanup(this);
209}
210
211template <typename LayerCase>
212void CompositionTest::captureScreenComposition() {
213 LayerCase::setupForScreenCapture(this);
214
215 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700216 constexpr bool useIdentityTransform = true;
217 constexpr bool forSystem = true;
218
219 DisplayRenderArea renderArea(mDisplay, sourceCrop, DEFAULT_DISPLAY_WIDTH,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700220 DEFAULT_DISPLAY_HEIGHT, ui::Dataspace::V0_SRGB,
221 ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700222
223 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw0e3479f2018-09-10 16:49:30 -0700224 return mFlinger.traverseLayersInDisplay(mDisplay, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700225 };
226
227 // TODO: Eliminate expensive/real allocation if possible.
228 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
229 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
230 mCaptureScreenBuffer = new GraphicBuffer(renderArea.getReqWidth(), renderArea.getReqHeight(),
231 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage, "screenshot");
232
233 int fd = -1;
234 status_t result =
235 mFlinger.captureScreenImplLocked(renderArea, traverseLayers, mCaptureScreenBuffer.get(),
236 useIdentityTransform, forSystem, &fd);
237 if (fd >= 0) {
238 close(fd);
239 }
240
241 EXPECT_EQ(NO_ERROR, result);
242
243 LayerCase::cleanup(this);
244}
245
246/* ------------------------------------------------------------------------
247 * Variants for each display configuration which can be tested
248 */
249
250template <typename Derived>
251struct BaseDisplayVariant {
252 static constexpr bool IS_SECURE = true;
253 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;
254
255 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700256 EXPECT_CALL(*test->mComposer,
257 setPowerMode(HWC_DISPLAY,
258 static_cast<Hwc2::IComposerClient::PowerMode>(
259 Derived::INIT_POWER_MODE)))
260 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700261
Dominik Laskowski075d3172018-05-24 15:50:06 -0700262 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, HWC2::DisplayType::Physical,
263 true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700264 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700265 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700266 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800267 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700268
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800269 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
270 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
271 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
272 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
273 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
274 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
275 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700276 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, DEFAULT_DISPLAY_ID,
277 false /* isVirtual */, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700278 .setDisplaySurface(test->mDisplaySurface)
Alec Mouriba013fa2018-10-16 12:43:11 -0700279 .setNativeWindow(test->mNativeWindow)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700280 .setSecure(Derived::IS_SECURE)
281 .setPowerMode(Derived::INIT_POWER_MODE)
282 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800283 Mock::VerifyAndClear(test->mNativeWindow);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700284 test->mDisplay->setLayerStack(DEFAULT_LAYER_STACK);
285 }
286
287 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700288 static void setupPreconditionCallExpectations(CompositionTest* test) {
289 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
290 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
291 Return(Error::NONE)));
292 }
293
294 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700295 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
296 EXPECT_CALL(*test->mComposer,
297 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
298 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700299 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
300 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
301 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
302 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
303
304 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700305
306 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
307 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
308
309 Case::CompositionType::setupHwcSetCallExpectations(test);
310 Case::CompositionType::setupHwcGetCallExpectations(test);
311 }
312
313 template <typename Case>
314 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000315 EXPECT_CALL(*test->mRenderEngine, drawLayers)
316 .WillRepeatedly(
317 [](const renderengine::DisplaySettings& displaySettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700318 const std::vector<renderengine::LayerSettings>&, ANativeWindowBuffer*,
319 const bool, base::unique_fd&&, base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000320 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
321 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
322 displaySettings.physicalDisplay);
323 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
324 displaySettings.clip);
325 return NO_ERROR;
326 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700327 }
328
329 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
330 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
331 }
332
333 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
334 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
335 }
336
337 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique66d68602019-02-13 14:23:31 -0800338 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
339
Lloyd Pique542307f2018-10-19 13:24:08 -0700340 EXPECT_CALL(*test->mDisplaySurface,
341 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC))
342 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700343 }
344
Lloyd Pique66d68602019-02-13 14:23:31 -0800345 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
346 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
347 }
348
349 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
350 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1);
351 }
352
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700353 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700354 EXPECT_CALL(*test->mDisplaySurface,
355 prepareFrame(compositionengine::DisplaySurface::COMPOSITION_GLES))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700356 .Times(1);
357 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
358 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
359
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800360 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
361 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
362 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
363 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000364 EXPECT_CALL(*test->mRenderEngine, drawLayers)
365 .WillRepeatedly(
366 [](const renderengine::DisplaySettings& displaySettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700367 const std::vector<renderengine::LayerSettings>&, ANativeWindowBuffer*,
368 const bool, base::unique_fd&&, base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000369 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
370 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
371 displaySettings.physicalDisplay);
372 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
373 displaySettings.clip);
374 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
375 return NO_ERROR;
376 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700377 }
378
379 template <typename Case>
380 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
381 Case::Layer::setupRECompositionCallExpectations(test);
382 }
383
384 template <typename Case>
385 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
386 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700387 }
388};
389
390struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
391
392struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
393 static constexpr bool IS_SECURE = false;
394
395 template <typename Case>
396 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
397 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700398 }
399
400 template <typename Case>
401 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
402 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700403 }
404};
405
406struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
407 static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_OFF;
408
409 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700410 static void setupPreconditionCallExpectations(CompositionTest*) {}
411
412 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700413 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800414 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
415
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700416 // TODO: This seems like an unnecessary call if display is powered off.
417 EXPECT_CALL(*test->mComposer,
418 setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
419 .Times(1);
420
421 // TODO: This seems like an unnecessary call if display is powered off.
422 Case::CompositionType::setupHwcSetCallExpectations(test);
423 }
424
425 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800426 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
427 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700428
429 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800430 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
431
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700432 // TODO: This seems like an unnecessary call if display is powered off.
433 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
434 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
435 }
436
437 template <typename Case>
438 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
439};
440
441/* ------------------------------------------------------------------------
442 * Variants for each layer configuration which can be tested
443 */
444
445template <typename LayerProperties>
446struct BaseLayerProperties {
447 static constexpr uint32_t WIDTH = 100;
448 static constexpr uint32_t HEIGHT = 100;
449 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
450 static constexpr uint64_t USAGE =
451 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
452 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
453 static constexpr uint32_t SCALING_MODE = 0;
454 static constexpr uint32_t TRANSFORM = 0;
455 static constexpr uint32_t LAYER_FLAGS = 0;
456 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
457 static constexpr IComposerClient::BlendMode BLENDMODE =
458 IComposerClient::BlendMode::PREMULTIPLIED;
459
460 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
461 auto producer = layer->getProducer();
462
463 IGraphicBufferProducer::QueueBufferOutput qbo;
464 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
465 if (result != NO_ERROR) {
466 ALOGE("Failed to connect() (%d)", result);
467 return;
468 }
469
470 int slot;
471 sp<Fence> fence;
472 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
473 LayerProperties::HEIGHT, LayerProperties::FORMAT,
474 LayerProperties::USAGE, nullptr, nullptr);
475 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
476 ALOGE("Failed to dequeueBuffer() (%d)", result);
477 return;
478 }
479
480 sp<GraphicBuffer> buffer;
481 result = producer->requestBuffer(slot, &buffer);
482 if (result != NO_ERROR) {
483 ALOGE("Failed to requestBuffer() (%d)", result);
484 return;
485 }
486
487 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
488 LayerProperties::DATASPACE,
489 Rect(LayerProperties::WIDTH,
490 LayerProperties::HEIGHT),
491 LayerProperties::SCALING_MODE,
492 LayerProperties::TRANSFORM, Fence::NO_FENCE);
493 result = producer->queueBuffer(slot, qbi, &qbo);
494 if (result != NO_ERROR) {
495 ALOGE("Failed to queueBuffer (%d)", result);
496 return;
497 }
498 }
499
500 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
501 // TODO: Eliminate the complexity of actually creating a buffer
502 EXPECT_CALL(*test->mRenderEngine, getMaxTextureSize()).WillOnce(Return(16384));
503 EXPECT_CALL(*test->mRenderEngine, getMaxViewportDims()).WillOnce(Return(16384));
504 status_t err =
505 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
506 LayerProperties::FORMAT);
507 ASSERT_EQ(NO_ERROR, err);
508 Mock::VerifyAndClear(test->mRenderEngine);
509
510 EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1);
511 enqueueBuffer(test, layer);
512 Mock::VerifyAndClear(test->mMessageQueue);
513
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700514 EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700515 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700516 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700517 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700518 }
519
520 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
521 setupLatchedBuffer(test, layer);
522 }
523
524 static void setupBufferLayerPostFrameCallExpectations(CompositionTest* test) {
525 // BufferLayer::onPostComposition(), when there is no present fence
526 EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY, _))
527 .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE)));
528 }
529
530 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
531 // TODO: Coverage of other values
532 EXPECT_CALL(*test->mComposer,
533 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
534 .Times(1);
535 // TODO: Coverage of other values for origin
536 EXPECT_CALL(*test->mComposer,
537 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
538 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
539 LayerProperties::HEIGHT})))
540 .Times(1);
541 EXPECT_CALL(*test->mComposer,
542 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
543 .Times(1);
544 // TODO: Coverage of other values
545 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
546 // TODO: Coverage of other values
547 EXPECT_CALL(*test->mComposer, setLayerInfo(HWC_DISPLAY, HWC_LAYER, 0u, 0u)).Times(1);
548
549 // These expectations retire on saturation as the code path these
550 // expectations are for appears to make an extra call to them.
551 // TODO: Investigate this extra call
552 EXPECT_CALL(*test->mComposer, setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
David Sodman15094112018-10-11 09:39:37 -0700553 .Times(AtLeast(1))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700554 .RetiresOnSaturation();
555 }
556
557 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
558 EXPECT_CALL(*test->mComposer,
559 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
560 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
561 LayerProperties::HEIGHT})))
562 .Times(1);
563 }
564
565 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
566 EXPECT_CALL(*test->mComposer,
567 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
568 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
569 .Times(1);
570 }
571
572 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
573 EXPECT_CALL(*test->mComposer,
574 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
575 std::vector<IComposerClient::Rect>({IComposerClient::Rect(
576 {0, 0, LayerProperties::WIDTH,
577 LayerProperties::HEIGHT})})))
578 .Times(1);
579 }
580
581 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
582 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
583
584 // TODO: use COLOR
585 EXPECT_CALL(*test->mComposer,
586 setLayerColor(HWC_DISPLAY, HWC_LAYER,
587 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
588 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700589 }
590
591 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
592 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
593 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
594
595 setupBufferLayerPostFrameCallExpectations(test);
596 }
597
598 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000599 EXPECT_CALL(*test->mRenderEngine, drawLayers)
600 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
601 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700602 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800603 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000604 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
605 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
606 displaySettings.physicalDisplay);
607 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
608 displaySettings.clip);
609 // screen capture adds an additional color layer as an alpha
610 // prefill, so gtet the back layer.
611 renderengine::LayerSettings layer = layerSettings.back();
612 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
613 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000614 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
615 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
616 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
617 EXPECT_EQ(false, layer.source.buffer.isOpaque);
618 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
619 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
620 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
621 return NO_ERROR;
622 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700623 }
624
625 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
626 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700627 }
628
629 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
630 setupREBufferCompositionCallExpectations(test);
631 }
632
633 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
634 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
635 }
636
637 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
638 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
639 }
640
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700641 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000642 EXPECT_CALL(*test->mRenderEngine, drawLayers)
643 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
644 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700645 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800646 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000647 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
648 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
649 displaySettings.physicalDisplay);
650 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
651 displaySettings.clip);
652 // screen capture adds an additional color layer as an alpha
653 // prefill, so get the back layer.
654 renderengine::LayerSettings layer = layerSettings.back();
655 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
656 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
657 LayerProperties::COLOR[2]),
658 layer.source.solidColor);
659 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
660 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
661 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
662 return NO_ERROR;
663 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700664 }
665
666 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
667 setupREColorCompositionCallExpectations(test);
668 }
669};
670
671struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
672
673struct ColorLayerProperties : public BaseLayerProperties<ColorLayerProperties> {};
674
675struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
676 using Base = BaseLayerProperties<SidebandLayerProperties>;
677 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
678
679 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
680 sp<NativeHandle> stream =
681 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
682 false);
683 test->mFlinger.setLayerSidebandStream(layer, stream);
684 }
685
686 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
687 EXPECT_CALL(*test->mComposer,
688 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
689 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
690 .Times(1);
691 }
692
693 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
694 EXPECT_CALL(*test->mComposer,
695 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
696 reinterpret_cast<native_handle_t*>(
697 DEFAULT_SIDEBAND_STREAM)))
698 .WillOnce(Return(Error::NONE));
699
700 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
701 }
702
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000703 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700704};
705
706struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> {
707 using Base = BaseLayerProperties<SecureLayerProperties>;
708
709 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
710
711 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000712 EXPECT_CALL(*test->mRenderEngine, drawLayers)
713 .WillOnce([](const renderengine::DisplaySettings& displaySettings,
714 const std::vector<renderengine::LayerSettings>& layerSettings,
Alec Mourife0d72b2019-03-21 14:05:56 -0700715 ANativeWindowBuffer*, const bool, base::unique_fd&&,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800716 base::unique_fd*) -> status_t {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000717 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
718 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
719 displaySettings.physicalDisplay);
720 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
721 displaySettings.clip);
722 // screen capture adds an additional color layer as an alpha
723 // prefill, so get the back layer.
724 renderengine::LayerSettings layer = layerSettings.back();
725 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
726 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
727 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
728 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
729 EXPECT_EQ(1.0f, layer.alpha);
730 return NO_ERROR;
731 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700732 }
733
734 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
735 setupInsecureREBufferCompositionCommonCallExpectations(test);
736 Base::setupBufferLayerPostFrameCallExpectations(test);
737 }
738
739 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
740 setupInsecureREBufferCompositionCommonCallExpectations(test);
741 }
742};
743
744struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
745 using Base = BaseLayerProperties<CursorLayerProperties>;
746
747 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
748 Base::setupLayerState(test, layer);
749 test->mFlinger.setLayerPotentialCursor(layer, true);
750 }
751};
752
753struct NoLayerVariant {
754 using FlingerLayerType = sp<BufferQueueLayer>;
755
756 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
757 static void injectLayer(CompositionTest*, FlingerLayerType) {}
758 static void cleanupInjectedLayers(CompositionTest*) {}
759
760 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
761 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
762};
763
764template <typename LayerProperties>
765struct BaseLayerVariant {
766 template <typename L, typename F>
767 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
768 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0);
769
770 sp<L> layer = factory();
771
772 Mock::VerifyAndClear(test->mComposer);
773 Mock::VerifyAndClear(test->mRenderEngine);
774 Mock::VerifyAndClear(test->mMessageQueue);
775
776 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
777 layerDrawingState.layerStack = DEFAULT_LAYER_STACK;
778 layerDrawingState.active.w = 100;
779 layerDrawingState.active.h = 100;
780 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
781 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nair4351ad52019-02-11 14:13:02 -0800782 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700783 layer->setVisibleRegion(Region(Rect(0, 0, 100, 100)));
784
785 return layer;
786 }
787
788 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
789 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
790 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
791
Lloyd Pique07e33212018-12-18 16:33:37 -0800792 std::vector<std::unique_ptr<compositionengine::OutputLayer>> outputLayers;
793 outputLayers.emplace_back(test->mDisplay->getCompositionDisplay()
794 ->getOrCreateOutputLayer(DEFAULT_DISPLAY_ID,
795 layer->getCompositionLayer(),
796 layer));
797
798 test->mDisplay->getCompositionDisplay()->setOutputLayersOrderedByZ(std::move(outputLayers));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700799
800 Mock::VerifyAndClear(test->mComposer);
801
802 Vector<sp<Layer>> layers;
803 layers.add(layer);
804 test->mDisplay->setVisibleLayersSortedByZ(layers);
805 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
806 }
807
808 static void cleanupInjectedLayers(CompositionTest* test) {
809 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
810 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800811
812 test->mDisplay->getCompositionDisplay()->setOutputLayersOrderedByZ(
813 std::vector<std::unique_ptr<compositionengine::OutputLayer>>());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700814 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
815 }
816};
817
818template <typename LayerProperties>
819struct ColorLayerVariant : public BaseLayerVariant<LayerProperties> {
820 using Base = BaseLayerVariant<LayerProperties>;
821 using FlingerLayerType = sp<ColorLayer>;
822
823 static FlingerLayerType createLayer(CompositionTest* test) {
824 FlingerLayerType layer = Base::template createLayerWithFactory<ColorLayer>(test, [test]() {
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700825 return new ColorLayer(LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
826 String8("test-layer"), LayerProperties::WIDTH,
827 LayerProperties::HEIGHT,
Evan Roskya1f1e152019-01-24 16:17:46 -0800828 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700829 });
Vishnu Nair60356342018-11-13 13:00:45 -0800830
831 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
832 layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700833 return layer;
834 }
835
836 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700837 LayerProperties::setupREColorCompositionCallExpectations(test);
838 }
839
840 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
841 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
842 }
843
844 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
845 LayerProperties::setupHwcSetGeometryCallExpectations(test);
846 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
847 }
848
849 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
850 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
851 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
852 }
853};
854
855template <typename LayerProperties>
856struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
857 using Base = BaseLayerVariant<LayerProperties>;
858 using FlingerLayerType = sp<BufferQueueLayer>;
859
860 static FlingerLayerType createLayer(CompositionTest* test) {
861 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
862
863 FlingerLayerType layer =
864 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700865 return new BufferQueueLayer(
866 LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
867 String8("test-layer"), LayerProperties::WIDTH,
868 LayerProperties::HEIGHT,
Evan Roskya1f1e152019-01-24 16:17:46 -0800869 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700870 });
871
872 LayerProperties::setupLayerState(test, layer);
873
874 return layer;
875 }
876
877 static void cleanupInjectedLayers(CompositionTest* test) {
Dan Stoza67765d82019-05-07 14:58:27 -0700878 EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700879 Base::cleanupInjectedLayers(test);
880 }
881
882 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
883 LayerProperties::setupHwcSetGeometryCallExpectations(test);
884 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
885 }
886
887 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
888 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
889 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
890 }
891
892 static void setupRECompositionCallExpectations(CompositionTest* test) {
893 LayerProperties::setupREBufferCompositionCallExpectations(test);
894 }
895
896 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
897 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
898 }
899
900 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
901 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
902 }
903
904 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
905 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
906 }
907};
908
909/* ------------------------------------------------------------------------
910 * Variants to control how the composition type is changed
911 */
912
913struct NoCompositionTypeVariant {
914 static void setupHwcSetCallExpectations(CompositionTest*) {}
915
916 static void setupHwcGetCallExpectations(CompositionTest* test) {
917 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
918 }
919};
920
921template <IComposerClient::Composition CompositionType>
922struct KeepCompositionTypeVariant {
923 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(CompositionType);
924
925 static void setupHwcSetCallExpectations(CompositionTest* test) {
926 EXPECT_CALL(*test->mComposer,
927 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
928 .Times(1);
929 }
930
931 static void setupHwcGetCallExpectations(CompositionTest* test) {
932 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
933 }
934};
935
936template <IComposerClient::Composition InitialCompositionType,
937 IComposerClient::Composition FinalCompositionType>
938struct ChangeCompositionTypeVariant {
939 static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(FinalCompositionType);
940
941 static void setupHwcSetCallExpectations(CompositionTest* test) {
942 EXPECT_CALL(*test->mComposer,
943 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
944 .Times(1);
945 }
946
947 static void setupHwcGetCallExpectations(CompositionTest* test) {
948 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
949 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
950 static_cast<Hwc2::Layer>(HWC_LAYER)}),
951 SetArgPointee<2>(std::vector<IComposerClient::Composition>{
952 FinalCompositionType}),
953 Return(Error::NONE)));
954 }
955};
956
957/* ------------------------------------------------------------------------
958 * Variants to select how the composition is expected to be handled
959 */
960
961struct CompositionResultBaseVariant {
962 static void setupLayerState(CompositionTest*, sp<Layer>) {}
963
964 template <typename Case>
965 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
966 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
967 }
968
969 template <typename Case>
970 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
971 Case::Layer::setupCallExpectationsForDirtyFrame(test);
972 }
973};
974
975struct NoCompositionResultVariant : public CompositionResultBaseVariant {
976 template <typename Case>
977 static void setupCallExpectations(CompositionTest* test) {
978 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
979 Case::Display::setupHwcCompositionCallExpectations(test);
980 }
981};
982
983struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
984 template <typename Case>
985 static void setupCallExpectations(CompositionTest* test) {
986 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
987 Case::Display::setupHwcCompositionCallExpectations(test);
988 }
989};
990
991struct RECompositionResultVariant : public CompositionResultBaseVariant {
992 template <typename Case>
993 static void setupCallExpectations(CompositionTest* test) {
994 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -0800995 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700996 Case::Display::setupRECompositionCallExpectations(test);
997 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
998 }
999};
1000
Lloyd Pique66d68602019-02-13 14:23:31 -08001001struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001002 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Lloyd Piquef5275482019-01-29 18:42:42 -08001003 const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay);
1004 LOG_FATAL_IF(!outputLayer);
1005 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001006 }
1007
1008 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001009 static void setupCallExpectations(CompositionTest* test) {
1010 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1011 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1012 Case::Display::setupRECompositionCallExpectations(test);
1013 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1014 }
1015
1016 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001017 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1018
1019 template <typename Case>
1020 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1021};
1022
1023struct EmptyScreenshotResultVariant {
1024 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1025
1026 template <typename Case>
1027 static void setupCallExpectations(CompositionTest*) {}
1028};
1029
1030struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1031 using Base = EmptyScreenshotResultVariant;
1032
1033 template <typename Case>
1034 static void setupCallExpectations(CompositionTest* test) {
1035 Base::template setupCallExpectations<Case>(test);
1036 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1037 }
1038};
1039
1040/* ------------------------------------------------------------------------
1041 * Composition test case, containing all the variants being tested
1042 */
1043
1044template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1045 typename CompositionResultCase>
1046struct CompositionCase {
1047 using ThisCase =
1048 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1049 using Display = DisplayCase;
1050 using Layer = LayerCase;
1051 using CompositionType = CompositionTypeCase;
1052 using CompositionResult = CompositionResultCase;
1053
1054 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001055 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001056 Display::setupPreconditions(test);
1057
1058 auto layer = Layer::createLayer(test);
1059 Layer::injectLayer(test, layer);
1060 CompositionResult::setupLayerState(test, layer);
1061 }
1062
1063 static void setupForDirtyGeometry(CompositionTest* test) {
1064 setupCommon(test);
1065
1066 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1067 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1068 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1069 CompositionResult::template setupCallExpectations<ThisCase>(test);
1070 }
1071
1072 static void setupForDirtyFrame(CompositionTest* test) {
1073 setupCommon(test);
1074
1075 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1076 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1077 CompositionResult::template setupCallExpectations<ThisCase>(test);
1078 }
1079
1080 static void setupForScreenCapture(CompositionTest* test) {
1081 setupCommon(test);
1082
1083 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1084 CompositionResult::template setupCallExpectations<ThisCase>(test);
1085 }
1086
1087 static void cleanup(CompositionTest* test) {
1088 Layer::cleanupInjectedLayers(test);
1089
1090 for (auto& hwcDisplay : test->mFlinger.mFakeHwcDisplays) {
1091 hwcDisplay->mutableLayers().clear();
1092 }
1093
1094 test->mDisplay->setVisibleLayersSortedByZ(Vector<sp<android::Layer>>());
1095 }
1096};
1097
1098/* ------------------------------------------------------------------------
1099 * Composition cases to test
1100 */
1101
1102TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1103 displayRefreshCompositionDirtyGeometry<
1104 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1105 NoCompositionResultVariant>>();
1106}
1107
1108TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1109 displayRefreshCompositionDirtyFrame<
1110 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1111 NoCompositionResultVariant>>();
1112}
1113
1114TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1115 captureScreenComposition<
1116 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1117 EmptyScreenshotResultVariant>>();
1118}
1119
1120/* ------------------------------------------------------------------------
1121 * Simple buffer layers
1122 */
1123
1124TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1125 displayRefreshCompositionDirtyGeometry<
1126 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1127 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1128 HwcCompositionResultVariant>>();
1129}
1130
1131TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1132 displayRefreshCompositionDirtyFrame<
1133 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1134 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1135 HwcCompositionResultVariant>>();
1136}
1137
1138TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1139 displayRefreshCompositionDirtyFrame<
1140 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1141 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1142 IComposerClient::Composition::CLIENT>,
1143 RECompositionResultVariant>>();
1144}
1145
1146TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1147 captureScreenComposition<
1148 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1149 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1150}
1151
1152/* ------------------------------------------------------------------------
1153 * Single-color layers
1154 */
1155
1156TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyGeometry) {
1157 displayRefreshCompositionDirtyGeometry<
1158 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1159 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1160 HwcCompositionResultVariant>>();
1161}
1162
1163TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyFrame) {
1164 displayRefreshCompositionDirtyFrame<
1165 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1166 KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>,
1167 HwcCompositionResultVariant>>();
1168}
1169
1170TEST_F(CompositionTest, REComposedColorLayer) {
1171 displayRefreshCompositionDirtyFrame<
1172 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1173 ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR,
1174 IComposerClient::Composition::CLIENT>,
1175 RECompositionResultVariant>>();
1176}
1177
1178TEST_F(CompositionTest, captureScreenColorLayer) {
1179 captureScreenComposition<
1180 CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>,
1181 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1182}
1183
1184/* ------------------------------------------------------------------------
1185 * Layers with sideband buffers
1186 */
1187
1188TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1189 displayRefreshCompositionDirtyGeometry<
1190 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1191 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1192 HwcCompositionResultVariant>>();
1193}
1194
1195TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1196 displayRefreshCompositionDirtyFrame<
1197 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1198 KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>,
1199 HwcCompositionResultVariant>>();
1200}
1201
1202TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1203 displayRefreshCompositionDirtyFrame<
1204 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1205 ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND,
1206 IComposerClient::Composition::CLIENT>,
1207 RECompositionResultVariant>>();
1208}
1209
1210TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1211 captureScreenComposition<
1212 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1213 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1214}
1215
1216/* ------------------------------------------------------------------------
1217 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1218 */
1219
1220TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1221 displayRefreshCompositionDirtyGeometry<
1222 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1223 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1224 HwcCompositionResultVariant>>();
1225}
1226
1227TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1228 displayRefreshCompositionDirtyFrame<
1229 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1230 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1231 HwcCompositionResultVariant>>();
1232}
1233
1234TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1235 displayRefreshCompositionDirtyFrame<
1236 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1237 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1238 IComposerClient::Composition::CLIENT>,
1239 RECompositionResultVariant>>();
1240}
1241
1242TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1243 captureScreenComposition<
1244 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1245 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1246}
1247
1248/* ------------------------------------------------------------------------
1249 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1250 */
1251
1252TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1253 displayRefreshCompositionDirtyGeometry<
1254 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1255 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1256 ForcedClientCompositionResultVariant>>();
1257}
1258
1259TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1260 displayRefreshCompositionDirtyFrame<
1261 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1262 KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>,
1263 ForcedClientCompositionResultVariant>>();
1264}
1265
1266TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1267 captureScreenComposition<
1268 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1269 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1270}
1271
1272/* ------------------------------------------------------------------------
1273 * Cursor layers
1274 */
1275
1276TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1277 displayRefreshCompositionDirtyGeometry<
1278 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1279 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1280 HwcCompositionResultVariant>>();
1281}
1282
1283TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1284 displayRefreshCompositionDirtyFrame<
1285 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1286 KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>,
1287 HwcCompositionResultVariant>>();
1288}
1289
1290TEST_F(CompositionTest, REComposedCursorLayer) {
1291 displayRefreshCompositionDirtyFrame<
1292 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1293 ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR,
1294 IComposerClient::Composition::CLIENT>,
1295 RECompositionResultVariant>>();
1296}
1297
1298TEST_F(CompositionTest, captureScreenCursorLayer) {
1299 captureScreenComposition<
1300 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1301 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1302}
1303
1304/* ------------------------------------------------------------------------
1305 * Simple buffer layer on a display which is powered off.
1306 */
1307
1308TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
1309 displayRefreshCompositionDirtyGeometry<CompositionCase<
1310 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1311 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1312 HwcCompositionResultVariant>>();
1313}
1314
1315TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
1316 displayRefreshCompositionDirtyFrame<CompositionCase<
1317 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1318 KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>,
1319 HwcCompositionResultVariant>>();
1320}
1321
1322TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
1323 displayRefreshCompositionDirtyFrame<CompositionCase<
1324 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1325 ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE,
1326 IComposerClient::Composition::CLIENT>,
1327 RECompositionResultVariant>>();
1328}
1329
1330TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1331 captureScreenComposition<CompositionCase<
1332 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1333 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1334}
1335
1336} // namespace
1337} // namespace android