blob: 602dd236f775aa0bcae6210074842b0f21bc5d35 [file] [log] [blame]
Lloyd Pique70d91362018-10-18 16:02:55 -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
Leon Scroggins IIIab551a32023-11-22 10:08:25 -050017#include <com_android_graphics_surfaceflinger_flags.h>
18#include <common/test/FlagUtils.h>
Lloyd Piqueab039b52019-02-13 14:22:42 -080019#include <compositionengine/CompositionRefreshArgs.h>
Lloyd Piqueaed56ab2019-11-13 22:34:11 -080020#include <compositionengine/LayerFECompositionState.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070021#include <compositionengine/impl/CompositionEngine.h>
Lloyd Piqueab039b52019-02-13 14:22:42 -080022#include <compositionengine/mock/LayerFE.h>
23#include <compositionengine/mock/Output.h>
Lloyd Piqueaed56ab2019-11-13 22:34:11 -080024#include <compositionengine/mock/OutputLayer.h>
Leon Scroggins III2f60d732022-09-12 14:42:38 -040025#include <ftl/future.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070026#include <gtest/gtest.h>
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070027#include <renderengine/mock/RenderEngine.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070028
Lloyd Pique441d5042018-10-18 16:49:51 -070029#include "MockHWComposer.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080030#include "TimeStats/TimeStats.h"
Lloyd Pique441d5042018-10-18 16:49:51 -070031
Leon Scroggins III2f60d732022-09-12 14:42:38 -040032#include <variant>
33
Leon Scroggins IIIab551a32023-11-22 10:08:25 -050034using namespace com::android::graphics::surfaceflinger;
35
Lloyd Pique70d91362018-10-18 16:02:55 -070036namespace android::compositionengine {
37namespace {
38
Lloyd Piqueab039b52019-02-13 14:22:42 -080039using ::testing::_;
Haibo Huangf66b7522020-09-10 18:20:30 -070040using ::testing::DoAll;
Lloyd Piquee82ed2d2019-11-13 19:28:12 -080041using ::testing::InSequence;
42using ::testing::Ref;
Lloyd Piqueab039b52019-02-13 14:22:42 -080043using ::testing::Return;
Lloyd Piqueaed56ab2019-11-13 22:34:11 -080044using ::testing::ReturnRef;
Lloyd Piqueab039b52019-02-13 14:22:42 -080045using ::testing::SaveArg;
Lloyd Pique441d5042018-10-18 16:49:51 -070046using ::testing::StrictMock;
47
Lloyd Piquee82ed2d2019-11-13 19:28:12 -080048struct CompositionEngineTest : public testing::Test {
Alec Mourie4034bb2019-11-19 12:45:54 -080049 std::shared_ptr<TimeStats> mTimeStats;
50
Lloyd Pique441d5042018-10-18 16:49:51 -070051 impl::CompositionEngine mEngine;
Lloyd Piquee82ed2d2019-11-13 19:28:12 -080052 CompositionRefreshArgs mRefreshArgs;
53
54 std::shared_ptr<mock::Output> mOutput1{std::make_shared<StrictMock<mock::Output>>()};
55 std::shared_ptr<mock::Output> mOutput2{std::make_shared<StrictMock<mock::Output>>()};
56 std::shared_ptr<mock::Output> mOutput3{std::make_shared<StrictMock<mock::Output>>()};
Lloyd Pique70d91362018-10-18 16:02:55 -070057};
58
Lloyd Pique70d91362018-10-18 16:02:55 -070059TEST_F(CompositionEngineTest, canInstantiateCompositionEngine) {
60 auto engine = impl::createCompositionEngine();
61 EXPECT_TRUE(engine.get() != nullptr);
62}
63
Lloyd Pique441d5042018-10-18 16:49:51 -070064TEST_F(CompositionEngineTest, canSetHWComposer) {
Ady Abrahameca9d752021-03-03 12:20:00 -080065 android::mock::HWComposer* hwc = new StrictMock<android::mock::HWComposer>();
66 mEngine.setHwComposer(std::unique_ptr<android::HWComposer>(hwc));
Lloyd Pique441d5042018-10-18 16:49:51 -070067
Ady Abrahameca9d752021-03-03 12:20:00 -080068 EXPECT_EQ(hwc, &mEngine.getHwComposer());
Lloyd Pique441d5042018-10-18 16:49:51 -070069}
70
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070071TEST_F(CompositionEngineTest, canSetRenderEngine) {
Patrick Williams0a525a42022-10-26 20:20:50 +000072 auto renderEngine = std::make_unique<StrictMock<renderengine::mock::RenderEngine>>();
73 mEngine.setRenderEngine(renderEngine.get());
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070074
Patrick Williams0a525a42022-10-26 20:20:50 +000075 EXPECT_EQ(renderEngine.get(), &mEngine.getRenderEngine());
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070076}
77
Alec Mourie4034bb2019-11-19 12:45:54 -080078TEST_F(CompositionEngineTest, canSetTimeStats) {
79 mEngine.setTimeStats(mTimeStats);
80
Patrick Williams74c0bf62022-11-02 23:59:26 +000081 EXPECT_EQ(mTimeStats.get(), mEngine.getTimeStats());
Alec Mourie4034bb2019-11-19 12:45:54 -080082}
83
Lloyd Piqueab039b52019-02-13 14:22:42 -080084/*
Lloyd Piquee82ed2d2019-11-13 19:28:12 -080085 * CompositionEngine::present
86 */
87
88struct CompositionEnginePresentTest : public CompositionEngineTest {
89 struct CompositionEnginePartialMock : public impl::CompositionEngine {
90 // These are the overridable functions CompositionEngine::present() may
91 // call, and have separate test coverage.
92 MOCK_METHOD1(preComposition, void(CompositionRefreshArgs&));
93 };
94
95 StrictMock<CompositionEnginePartialMock> mEngine;
96};
97
98TEST_F(CompositionEnginePresentTest, worksWithEmptyRequest) {
99 // present() always calls preComposition()
100 EXPECT_CALL(mEngine, preComposition(Ref(mRefreshArgs)));
101
102 mEngine.present(mRefreshArgs);
103}
104
105TEST_F(CompositionEnginePresentTest, worksAsExpected) {
106 // Expect calls to in a certain sequence
107 InSequence seq;
108
109 // present() always calls preComposition()
110 EXPECT_CALL(mEngine, preComposition(Ref(mRefreshArgs)));
111
112 // The first step in presenting is to make sure all outputs are prepared.
113 EXPECT_CALL(*mOutput1, prepare(Ref(mRefreshArgs), _));
114 EXPECT_CALL(*mOutput2, prepare(Ref(mRefreshArgs), _));
115 EXPECT_CALL(*mOutput3, prepare(Ref(mRefreshArgs), _));
116
Leon Scroggins IIIab551a32023-11-22 10:08:25 -0500117 // All of mOutput<i> are StrictMocks. If the flag is true, it will introduce
118 // calls to getDisplayId, which are not relevant to this test.
119 SET_FLAG_FOR_TEST(flags::multithreaded_present, false);
Leon Scroggins III2f60d732022-09-12 14:42:38 -0400120
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800121 // The last step is to actually present each output.
Leon Scroggins III2f60d732022-09-12 14:42:38 -0400122 EXPECT_CALL(*mOutput1, present(Ref(mRefreshArgs)))
123 .WillOnce(Return(ftl::yield<std::monostate>({})));
124 EXPECT_CALL(*mOutput2, present(Ref(mRefreshArgs)))
125 .WillOnce(Return(ftl::yield<std::monostate>({})));
126 EXPECT_CALL(*mOutput3, present(Ref(mRefreshArgs)))
127 .WillOnce(Return(ftl::yield<std::monostate>({})));
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800128
129 mRefreshArgs.outputs = {mOutput1, mOutput2, mOutput3};
130 mEngine.present(mRefreshArgs);
131}
132
133/*
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800134 * CompositionEngine::updateCursorAsync
135 */
136
137struct CompositionEngineUpdateCursorAsyncTest : public CompositionEngineTest {
138public:
Lloyd Piquede196652020-01-22 17:29:58 -0800139 struct Layer {
Ady Abrahameca9d752021-03-03 12:20:00 -0800140 Layer() { EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE)); }
Lloyd Piquede196652020-01-22 17:29:58 -0800141
142 StrictMock<mock::OutputLayer> outputLayer;
Ady Abrahameca9d752021-03-03 12:20:00 -0800143 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -0800144 LayerFECompositionState layerFEState;
145 };
146
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800147 CompositionEngineUpdateCursorAsyncTest() {
Lloyd Pique0a456232020-01-16 17:51:13 -0800148 EXPECT_CALL(*mOutput1, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800149 EXPECT_CALL(*mOutput1, getOutputLayerOrderedByZByIndex(_)).Times(0);
150
Lloyd Pique0a456232020-01-16 17:51:13 -0800151 EXPECT_CALL(*mOutput2, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800152 EXPECT_CALL(*mOutput2, getOutputLayerOrderedByZByIndex(0))
Lloyd Piquede196652020-01-22 17:29:58 -0800153 .WillRepeatedly(Return(&mOutput2Layer1.outputLayer));
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800154
Lloyd Pique0a456232020-01-16 17:51:13 -0800155 EXPECT_CALL(*mOutput3, getOutputLayerCount()).WillRepeatedly(Return(2u));
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800156 EXPECT_CALL(*mOutput3, getOutputLayerOrderedByZByIndex(0))
Lloyd Piquede196652020-01-22 17:29:58 -0800157 .WillRepeatedly(Return(&mOutput3Layer1.outputLayer));
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800158 EXPECT_CALL(*mOutput3, getOutputLayerOrderedByZByIndex(1))
Lloyd Piquede196652020-01-22 17:29:58 -0800159 .WillRepeatedly(Return(&mOutput3Layer2.outputLayer));
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800160 }
161
Lloyd Piquede196652020-01-22 17:29:58 -0800162 Layer mOutput2Layer1;
163 Layer mOutput3Layer1;
164 Layer mOutput3Layer2;
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800165};
166
167TEST_F(CompositionEngineUpdateCursorAsyncTest, handlesNoOutputs) {
168 mEngine.updateCursorAsync(mRefreshArgs);
169}
170
171TEST_F(CompositionEngineUpdateCursorAsyncTest, handlesNoLayersBeingCursorLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800172 EXPECT_CALL(mOutput3Layer1.outputLayer, isHardwareCursor()).WillRepeatedly(Return(false));
173 EXPECT_CALL(mOutput3Layer2.outputLayer, isHardwareCursor()).WillRepeatedly(Return(false));
174 EXPECT_CALL(mOutput2Layer1.outputLayer, isHardwareCursor()).WillRepeatedly(Return(false));
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800175
176 mRefreshArgs.outputs = {mOutput1, mOutput2, mOutput3};
177
178 mEngine.updateCursorAsync(mRefreshArgs);
179}
180
181TEST_F(CompositionEngineUpdateCursorAsyncTest, handlesMultipleLayersBeingCursorLayers) {
182 {
183 InSequence seq;
Lloyd Piquede196652020-01-22 17:29:58 -0800184 EXPECT_CALL(mOutput2Layer1.outputLayer, isHardwareCursor()).WillRepeatedly(Return(true));
Lloyd Piquede196652020-01-22 17:29:58 -0800185 EXPECT_CALL(mOutput2Layer1.outputLayer, writeCursorPositionToHWC());
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800186 }
187
188 {
189 InSequence seq;
Lloyd Piquede196652020-01-22 17:29:58 -0800190 EXPECT_CALL(mOutput3Layer1.outputLayer, isHardwareCursor()).WillRepeatedly(Return(true));
Lloyd Piquede196652020-01-22 17:29:58 -0800191 EXPECT_CALL(mOutput3Layer1.outputLayer, writeCursorPositionToHWC());
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800192 }
193
194 {
195 InSequence seq;
Lloyd Piquede196652020-01-22 17:29:58 -0800196 EXPECT_CALL(mOutput3Layer2.outputLayer, isHardwareCursor()).WillRepeatedly(Return(true));
Lloyd Piquede196652020-01-22 17:29:58 -0800197 EXPECT_CALL(mOutput3Layer2.outputLayer, writeCursorPositionToHWC());
Lloyd Piqueaed56ab2019-11-13 22:34:11 -0800198 }
199
200 mRefreshArgs.outputs = {mOutput1, mOutput2, mOutput3};
201
202 mEngine.updateCursorAsync(mRefreshArgs);
203}
204
205/*
Lloyd Piqueab039b52019-02-13 14:22:42 -0800206 * CompositionEngine::preComposition
207 */
208
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800209struct CompositionTestPreComposition : public CompositionEngineTest {
Ady Abrahame0eafa82022-02-02 19:30:47 -0800210 sp<StrictMock<mock::LayerFE>> mLayer1FE = sp<StrictMock<mock::LayerFE>>::make();
211 sp<StrictMock<mock::LayerFE>> mLayer2FE = sp<StrictMock<mock::LayerFE>>::make();
212 sp<StrictMock<mock::LayerFE>> mLayer3FE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piqueab039b52019-02-13 14:22:42 -0800213};
214
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800215TEST_F(CompositionTestPreComposition, preCompositionSetsFrameTimestamp) {
Lloyd Piqueab039b52019-02-13 14:22:42 -0800216 const nsecs_t before = systemTime(SYSTEM_TIME_MONOTONIC);
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800217 mEngine.preComposition(mRefreshArgs);
Lloyd Piqueab039b52019-02-13 14:22:42 -0800218 const nsecs_t after = systemTime(SYSTEM_TIME_MONOTONIC);
219
220 // The frame timestamp should be between the before and after timestamps
221 EXPECT_GE(mEngine.getLastFrameRefreshTimestamp(), before);
222 EXPECT_LE(mEngine.getLastFrameRefreshTimestamp(), after);
223}
224
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800225TEST_F(CompositionTestPreComposition, preCompositionInvokesLayerPreCompositionWithFrameTimestamp) {
Lloyd Piqueab039b52019-02-13 14:22:42 -0800226 nsecs_t ts1 = 0;
227 nsecs_t ts2 = 0;
228 nsecs_t ts3 = 0;
Vishnu Nairba354102022-08-01 00:14:18 +0000229 EXPECT_CALL(*mLayer1FE, onPreComposition(_, _))
230 .WillOnce(DoAll(SaveArg<0>(&ts1), Return(false)));
231 EXPECT_CALL(*mLayer2FE, onPreComposition(_, _))
232 .WillOnce(DoAll(SaveArg<0>(&ts2), Return(false)));
233 EXPECT_CALL(*mLayer3FE, onPreComposition(_, _))
234 .WillOnce(DoAll(SaveArg<0>(&ts3), Return(false)));
Lloyd Piqueab039b52019-02-13 14:22:42 -0800235
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800236 mRefreshArgs.outputs = {mOutput1};
Lloyd Piquede196652020-01-22 17:29:58 -0800237 mRefreshArgs.layers = {mLayer1FE, mLayer2FE, mLayer3FE};
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800238
Lloyd Piqueab039b52019-02-13 14:22:42 -0800239 mEngine.preComposition(mRefreshArgs);
240
241 // Each of the onPreComposition calls should used the same refresh timestamp
242 EXPECT_EQ(ts1, mEngine.getLastFrameRefreshTimestamp());
243 EXPECT_EQ(ts2, mEngine.getLastFrameRefreshTimestamp());
244 EXPECT_EQ(ts3, mEngine.getLastFrameRefreshTimestamp());
245}
246
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800247TEST_F(CompositionTestPreComposition, preCompositionDefaultsToNoUpdateNeeded) {
Vishnu Nairba354102022-08-01 00:14:18 +0000248 EXPECT_CALL(*mLayer1FE, onPreComposition(_, _)).WillOnce(Return(false));
249 EXPECT_CALL(*mLayer2FE, onPreComposition(_, _)).WillOnce(Return(false));
250 EXPECT_CALL(*mLayer3FE, onPreComposition(_, _)).WillOnce(Return(false));
Lloyd Piqueab039b52019-02-13 14:22:42 -0800251
252 mEngine.setNeedsAnotherUpdateForTest(true);
253
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800254 mRefreshArgs.outputs = {mOutput1};
Lloyd Piquede196652020-01-22 17:29:58 -0800255 mRefreshArgs.layers = {mLayer1FE, mLayer2FE, mLayer3FE};
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800256
Lloyd Piqueab039b52019-02-13 14:22:42 -0800257 mEngine.preComposition(mRefreshArgs);
258
259 // The call should have cleared the needsAnotherUpdate flag
260 EXPECT_FALSE(mEngine.needsAnotherUpdate());
261}
262
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800263TEST_F(CompositionTestPreComposition,
264 preCompositionSetsNeedsAnotherUpdateIfAtLeastOneLayerRequestsIt) {
Vishnu Nairba354102022-08-01 00:14:18 +0000265 EXPECT_CALL(*mLayer1FE, onPreComposition(_, _)).WillOnce(Return(true));
266 EXPECT_CALL(*mLayer2FE, onPreComposition(_, _)).WillOnce(Return(false));
267 EXPECT_CALL(*mLayer3FE, onPreComposition(_, _)).WillOnce(Return(false));
Lloyd Piqueab039b52019-02-13 14:22:42 -0800268
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800269 mRefreshArgs.outputs = {mOutput1};
Lloyd Piquede196652020-01-22 17:29:58 -0800270 mRefreshArgs.layers = {mLayer1FE, mLayer2FE, mLayer3FE};
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800271
Lloyd Piqueab039b52019-02-13 14:22:42 -0800272 mEngine.preComposition(mRefreshArgs);
273
274 EXPECT_TRUE(mEngine.needsAnotherUpdate());
275}
276
Leon Scroggins IIIab551a32023-11-22 10:08:25 -0500277struct CompositionEngineOffloadTest : public testing::Test {
278 impl::CompositionEngine mEngine;
279 CompositionRefreshArgs mRefreshArgs;
280
281 std::shared_ptr<mock::Output> mDisplay1{std::make_shared<StrictMock<mock::Output>>()};
282 std::shared_ptr<mock::Output> mDisplay2{std::make_shared<StrictMock<mock::Output>>()};
283 std::shared_ptr<mock::Output> mVirtualDisplay{std::make_shared<StrictMock<mock::Output>>()};
284 std::shared_ptr<mock::Output> mHalVirtualDisplay{std::make_shared<StrictMock<mock::Output>>()};
285
286 static constexpr PhysicalDisplayId kDisplayId1 = PhysicalDisplayId::fromPort(123u);
287 static constexpr PhysicalDisplayId kDisplayId2 = PhysicalDisplayId::fromPort(234u);
288 static constexpr GpuVirtualDisplayId kGpuVirtualDisplayId{789u};
289 static constexpr HalVirtualDisplayId kHalVirtualDisplayId{456u};
290
291 void SetUp() override {
292 EXPECT_CALL(*mDisplay1, getDisplayId)
293 .WillRepeatedly(Return(std::make_optional<DisplayId>(kDisplayId1)));
294 EXPECT_CALL(*mDisplay2, getDisplayId)
295 .WillRepeatedly(Return(std::make_optional<DisplayId>(kDisplayId2)));
296 EXPECT_CALL(*mVirtualDisplay, getDisplayId)
297 .WillRepeatedly(Return(std::make_optional<DisplayId>(kGpuVirtualDisplayId)));
298 EXPECT_CALL(*mHalVirtualDisplay, getDisplayId)
299 .WillRepeatedly(Return(std::make_optional<DisplayId>(kHalVirtualDisplayId)));
300 }
301
302 void setOutputs(std::initializer_list<std::shared_ptr<mock::Output>> outputs) {
303 for (auto& output : outputs) {
304 // If we call mEngine.present, prepare and present will be called on all the
305 // outputs in mRefreshArgs, but that's not the interesting part of the test.
306 EXPECT_CALL(*output, prepare(Ref(mRefreshArgs), _)).Times(1);
307 EXPECT_CALL(*output, present(Ref(mRefreshArgs)))
308 .WillOnce(Return(ftl::yield<std::monostate>({})));
309
310 mRefreshArgs.outputs.push_back(std::move(output));
311 }
312 }
313};
314
315TEST_F(CompositionEngineOffloadTest, basic) {
316 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
317 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(true));
318
319 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
320 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
321
322 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
323 setOutputs({mDisplay1, mDisplay2});
324
325 mEngine.present(mRefreshArgs);
326}
327
328TEST_F(CompositionEngineOffloadTest, dependsOnSupport) {
329 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(false));
330 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).Times(0);
331
332 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
333 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
334
335 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
336 setOutputs({mDisplay1, mDisplay2});
337
338 mEngine.present(mRefreshArgs);
339}
340
341TEST_F(CompositionEngineOffloadTest, dependsOnSupport2) {
342 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
343 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(false));
344
345 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
346 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
347
348 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
349 setOutputs({mDisplay1, mDisplay2});
350
351 mEngine.present(mRefreshArgs);
352}
353
354TEST_F(CompositionEngineOffloadTest, dependsOnFlag) {
355 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).Times(0);
356 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).Times(0);
357
358 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
359 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
360
361 SET_FLAG_FOR_TEST(flags::multithreaded_present, false);
362 setOutputs({mDisplay1, mDisplay2});
363
364 mEngine.present(mRefreshArgs);
365}
366
367TEST_F(CompositionEngineOffloadTest, oneDisplay) {
368 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).Times(0);
369
370 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
371
372 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
373 setOutputs({mDisplay1});
374
375 mEngine.present(mRefreshArgs);
376}
377
378TEST_F(CompositionEngineOffloadTest, virtualDisplay) {
379 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
380 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(true));
381 EXPECT_CALL(*mVirtualDisplay, supportsOffloadPresent).Times(0);
382
383 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
384 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
385 EXPECT_CALL(*mVirtualDisplay, offloadPresentNextFrame).Times(0);
386
387 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
388 setOutputs({mDisplay1, mDisplay2, mVirtualDisplay});
389
390 mEngine.present(mRefreshArgs);
391}
392
393TEST_F(CompositionEngineOffloadTest, virtualDisplay2) {
394 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
395 EXPECT_CALL(*mVirtualDisplay, supportsOffloadPresent).Times(0);
396
397 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
398 EXPECT_CALL(*mVirtualDisplay, offloadPresentNextFrame).Times(0);
399
400 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
401 setOutputs({mDisplay1, mVirtualDisplay});
402
403 mEngine.present(mRefreshArgs);
404}
405
406TEST_F(CompositionEngineOffloadTest, halVirtual) {
407 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
408 EXPECT_CALL(*mHalVirtualDisplay, supportsOffloadPresent).WillOnce(Return(true));
409
410 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
411 EXPECT_CALL(*mHalVirtualDisplay, offloadPresentNextFrame).Times(0);
412
413 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
414 setOutputs({mDisplay1, mHalVirtualDisplay});
415
416 mEngine.present(mRefreshArgs);
417}
418
419TEST_F(CompositionEngineOffloadTest, ordering) {
420 EXPECT_CALL(*mVirtualDisplay, supportsOffloadPresent).Times(0);
421 EXPECT_CALL(*mHalVirtualDisplay, supportsOffloadPresent).WillOnce(Return(true));
422 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
423 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(true));
424
425 EXPECT_CALL(*mVirtualDisplay, offloadPresentNextFrame).Times(0);
426 EXPECT_CALL(*mHalVirtualDisplay, offloadPresentNextFrame).Times(1);
427 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
428 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
429
430 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
431 setOutputs({mVirtualDisplay, mHalVirtualDisplay, mDisplay1, mDisplay2});
432
433 mEngine.present(mRefreshArgs);
434}
435
Lloyd Pique70d91362018-10-18 16:02:55 -0700436} // namespace
437} // namespace android::compositionengine