blob: da578e2046a3daea06b292ea146b2c57d0444801 [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
Leon Scroggins IIIcbc929d2023-12-01 16:21:37 -0500291 std::array<impl::OutputCompositionState, 4> mOutputStates;
292
Leon Scroggins IIIab551a32023-11-22 10:08:25 -0500293 void SetUp() override {
294 EXPECT_CALL(*mDisplay1, getDisplayId)
295 .WillRepeatedly(Return(std::make_optional<DisplayId>(kDisplayId1)));
296 EXPECT_CALL(*mDisplay2, getDisplayId)
297 .WillRepeatedly(Return(std::make_optional<DisplayId>(kDisplayId2)));
298 EXPECT_CALL(*mVirtualDisplay, getDisplayId)
299 .WillRepeatedly(Return(std::make_optional<DisplayId>(kGpuVirtualDisplayId)));
300 EXPECT_CALL(*mHalVirtualDisplay, getDisplayId)
301 .WillRepeatedly(Return(std::make_optional<DisplayId>(kHalVirtualDisplayId)));
Leon Scroggins IIIcbc929d2023-12-01 16:21:37 -0500302
303 // Most tests will depend on the outputs being enabled.
304 for (auto& state : mOutputStates) {
305 state.isEnabled = true;
306 }
307
308 EXPECT_CALL(*mDisplay1, getState).WillRepeatedly(ReturnRef(mOutputStates[0]));
309 EXPECT_CALL(*mDisplay2, getState).WillRepeatedly(ReturnRef(mOutputStates[1]));
310 EXPECT_CALL(*mVirtualDisplay, getState).WillRepeatedly(ReturnRef(mOutputStates[2]));
311 EXPECT_CALL(*mHalVirtualDisplay, getState).WillRepeatedly(ReturnRef(mOutputStates[3]));
Leon Scroggins IIIab551a32023-11-22 10:08:25 -0500312 }
313
314 void setOutputs(std::initializer_list<std::shared_ptr<mock::Output>> outputs) {
315 for (auto& output : outputs) {
316 // If we call mEngine.present, prepare and present will be called on all the
317 // outputs in mRefreshArgs, but that's not the interesting part of the test.
318 EXPECT_CALL(*output, prepare(Ref(mRefreshArgs), _)).Times(1);
319 EXPECT_CALL(*output, present(Ref(mRefreshArgs)))
320 .WillOnce(Return(ftl::yield<std::monostate>({})));
321
322 mRefreshArgs.outputs.push_back(std::move(output));
323 }
324 }
325};
326
327TEST_F(CompositionEngineOffloadTest, basic) {
328 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
329 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(true));
330
331 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
332 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
333
334 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
335 setOutputs({mDisplay1, mDisplay2});
336
337 mEngine.present(mRefreshArgs);
338}
339
340TEST_F(CompositionEngineOffloadTest, dependsOnSupport) {
341 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(false));
342 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).Times(0);
343
344 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
345 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
346
347 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
348 setOutputs({mDisplay1, mDisplay2});
349
350 mEngine.present(mRefreshArgs);
351}
352
353TEST_F(CompositionEngineOffloadTest, dependsOnSupport2) {
354 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
355 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(false));
356
357 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
358 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
359
360 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
361 setOutputs({mDisplay1, mDisplay2});
362
363 mEngine.present(mRefreshArgs);
364}
365
366TEST_F(CompositionEngineOffloadTest, dependsOnFlag) {
367 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).Times(0);
368 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).Times(0);
369
370 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
371 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
372
373 SET_FLAG_FOR_TEST(flags::multithreaded_present, false);
374 setOutputs({mDisplay1, mDisplay2});
375
376 mEngine.present(mRefreshArgs);
377}
378
379TEST_F(CompositionEngineOffloadTest, oneDisplay) {
380 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).Times(0);
381
382 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
383
384 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
385 setOutputs({mDisplay1});
386
387 mEngine.present(mRefreshArgs);
388}
389
390TEST_F(CompositionEngineOffloadTest, virtualDisplay) {
391 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
392 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(true));
393 EXPECT_CALL(*mVirtualDisplay, supportsOffloadPresent).Times(0);
394
395 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
396 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
397 EXPECT_CALL(*mVirtualDisplay, offloadPresentNextFrame).Times(0);
398
399 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
400 setOutputs({mDisplay1, mDisplay2, mVirtualDisplay});
401
402 mEngine.present(mRefreshArgs);
403}
404
405TEST_F(CompositionEngineOffloadTest, virtualDisplay2) {
406 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
407 EXPECT_CALL(*mVirtualDisplay, supportsOffloadPresent).Times(0);
408
409 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
410 EXPECT_CALL(*mVirtualDisplay, offloadPresentNextFrame).Times(0);
411
412 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
413 setOutputs({mDisplay1, mVirtualDisplay});
414
415 mEngine.present(mRefreshArgs);
416}
417
418TEST_F(CompositionEngineOffloadTest, halVirtual) {
419 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
420 EXPECT_CALL(*mHalVirtualDisplay, supportsOffloadPresent).WillOnce(Return(true));
421
422 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
423 EXPECT_CALL(*mHalVirtualDisplay, offloadPresentNextFrame).Times(0);
424
425 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
426 setOutputs({mDisplay1, mHalVirtualDisplay});
427
428 mEngine.present(mRefreshArgs);
429}
430
431TEST_F(CompositionEngineOffloadTest, ordering) {
432 EXPECT_CALL(*mVirtualDisplay, supportsOffloadPresent).Times(0);
433 EXPECT_CALL(*mHalVirtualDisplay, supportsOffloadPresent).WillOnce(Return(true));
434 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
435 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(true));
436
437 EXPECT_CALL(*mVirtualDisplay, offloadPresentNextFrame).Times(0);
438 EXPECT_CALL(*mHalVirtualDisplay, offloadPresentNextFrame).Times(1);
439 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
440 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
441
442 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
443 setOutputs({mVirtualDisplay, mHalVirtualDisplay, mDisplay1, mDisplay2});
444
445 mEngine.present(mRefreshArgs);
446}
447
Leon Scroggins IIIcbc929d2023-12-01 16:21:37 -0500448TEST_F(CompositionEngineOffloadTest, dependsOnEnabled) {
449 // Disable mDisplay2.
450 mOutputStates[1].isEnabled = false;
451 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
452
453 // This is not actually called, because it is not enabled, but this distinguishes
454 // from the case where it did not return true.
455 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillRepeatedly(Return(true));
456
457 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
458 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
459
460 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
461 setOutputs({mDisplay1, mDisplay2});
462
463 mEngine.present(mRefreshArgs);
464}
465
466TEST_F(CompositionEngineOffloadTest, disabledDisplaysDoNotPreventOthersFromOffloading) {
467 // Disable mDisplay2.
468 mOutputStates[1].isEnabled = false;
469 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
470
471 // This is not actually called, because it is not enabled, but this distinguishes
472 // from the case where it did not return true.
473 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillRepeatedly(Return(true));
474 EXPECT_CALL(*mHalVirtualDisplay, supportsOffloadPresent).WillOnce(Return(true));
475
476 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
477 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
478 EXPECT_CALL(*mHalVirtualDisplay, offloadPresentNextFrame).Times(0);
479
480 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
481 setOutputs({mDisplay1, mDisplay2, mHalVirtualDisplay});
482
483 mEngine.present(mRefreshArgs);
484}
485
Lloyd Pique70d91362018-10-18 16:02:55 -0700486} // namespace
487} // namespace android::compositionengine