blob: 042010edd5f54b1fceb9fbc1b217316650f3afbb [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);
Melody Hsuc949cde2024-03-12 01:43:34 +0000217 mRefreshArgs.refreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800218 mEngine.preComposition(mRefreshArgs);
Lloyd Piqueab039b52019-02-13 14:22:42 -0800219 const nsecs_t after = systemTime(SYSTEM_TIME_MONOTONIC);
220
221 // The frame timestamp should be between the before and after timestamps
222 EXPECT_GE(mEngine.getLastFrameRefreshTimestamp(), before);
223 EXPECT_LE(mEngine.getLastFrameRefreshTimestamp(), after);
224}
225
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800226TEST_F(CompositionTestPreComposition, preCompositionInvokesLayerPreCompositionWithFrameTimestamp) {
Lloyd Piqueab039b52019-02-13 14:22:42 -0800227 nsecs_t ts1 = 0;
228 nsecs_t ts2 = 0;
229 nsecs_t ts3 = 0;
Melody Hsuc949cde2024-03-12 01:43:34 +0000230 EXPECT_CALL(*mLayer1FE, onPreComposition(_)).WillOnce(DoAll(SaveArg<0>(&ts1), Return(false)));
231 EXPECT_CALL(*mLayer2FE, onPreComposition(_)).WillOnce(DoAll(SaveArg<0>(&ts2), Return(false)));
232 EXPECT_CALL(*mLayer3FE, onPreComposition(_)).WillOnce(DoAll(SaveArg<0>(&ts3), Return(false)));
Lloyd Piqueab039b52019-02-13 14:22:42 -0800233
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800234 mRefreshArgs.outputs = {mOutput1};
Lloyd Piquede196652020-01-22 17:29:58 -0800235 mRefreshArgs.layers = {mLayer1FE, mLayer2FE, mLayer3FE};
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800236
Lloyd Piqueab039b52019-02-13 14:22:42 -0800237 mEngine.preComposition(mRefreshArgs);
238
239 // Each of the onPreComposition calls should used the same refresh timestamp
240 EXPECT_EQ(ts1, mEngine.getLastFrameRefreshTimestamp());
241 EXPECT_EQ(ts2, mEngine.getLastFrameRefreshTimestamp());
242 EXPECT_EQ(ts3, mEngine.getLastFrameRefreshTimestamp());
243}
244
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800245TEST_F(CompositionTestPreComposition, preCompositionDefaultsToNoUpdateNeeded) {
Melody Hsuc949cde2024-03-12 01:43:34 +0000246 EXPECT_CALL(*mLayer1FE, onPreComposition(_)).WillOnce(Return(false));
247 EXPECT_CALL(*mLayer2FE, onPreComposition(_)).WillOnce(Return(false));
248 EXPECT_CALL(*mLayer3FE, onPreComposition(_)).WillOnce(Return(false));
Lloyd Piqueab039b52019-02-13 14:22:42 -0800249
250 mEngine.setNeedsAnotherUpdateForTest(true);
251
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800252 mRefreshArgs.outputs = {mOutput1};
Lloyd Piquede196652020-01-22 17:29:58 -0800253 mRefreshArgs.layers = {mLayer1FE, mLayer2FE, mLayer3FE};
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800254
Lloyd Piqueab039b52019-02-13 14:22:42 -0800255 mEngine.preComposition(mRefreshArgs);
256
257 // The call should have cleared the needsAnotherUpdate flag
258 EXPECT_FALSE(mEngine.needsAnotherUpdate());
259}
260
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800261TEST_F(CompositionTestPreComposition,
262 preCompositionSetsNeedsAnotherUpdateIfAtLeastOneLayerRequestsIt) {
Melody Hsuc949cde2024-03-12 01:43:34 +0000263 EXPECT_CALL(*mLayer1FE, onPreComposition(_)).WillOnce(Return(true));
264 EXPECT_CALL(*mLayer2FE, onPreComposition(_)).WillOnce(Return(false));
265 EXPECT_CALL(*mLayer3FE, onPreComposition(_)).WillOnce(Return(false));
Lloyd Piqueab039b52019-02-13 14:22:42 -0800266
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800267 mRefreshArgs.outputs = {mOutput1};
Lloyd Piquede196652020-01-22 17:29:58 -0800268 mRefreshArgs.layers = {mLayer1FE, mLayer2FE, mLayer3FE};
Lloyd Piquee82ed2d2019-11-13 19:28:12 -0800269
Lloyd Piqueab039b52019-02-13 14:22:42 -0800270 mEngine.preComposition(mRefreshArgs);
271
272 EXPECT_TRUE(mEngine.needsAnotherUpdate());
273}
274
Leon Scroggins IIIab551a32023-11-22 10:08:25 -0500275struct CompositionEngineOffloadTest : public testing::Test {
276 impl::CompositionEngine mEngine;
277 CompositionRefreshArgs mRefreshArgs;
278
279 std::shared_ptr<mock::Output> mDisplay1{std::make_shared<StrictMock<mock::Output>>()};
280 std::shared_ptr<mock::Output> mDisplay2{std::make_shared<StrictMock<mock::Output>>()};
281 std::shared_ptr<mock::Output> mVirtualDisplay{std::make_shared<StrictMock<mock::Output>>()};
282 std::shared_ptr<mock::Output> mHalVirtualDisplay{std::make_shared<StrictMock<mock::Output>>()};
283
284 static constexpr PhysicalDisplayId kDisplayId1 = PhysicalDisplayId::fromPort(123u);
285 static constexpr PhysicalDisplayId kDisplayId2 = PhysicalDisplayId::fromPort(234u);
286 static constexpr GpuVirtualDisplayId kGpuVirtualDisplayId{789u};
287 static constexpr HalVirtualDisplayId kHalVirtualDisplayId{456u};
288
Leon Scroggins IIIcbc929d2023-12-01 16:21:37 -0500289 std::array<impl::OutputCompositionState, 4> mOutputStates;
290
Leon Scroggins IIIab551a32023-11-22 10:08:25 -0500291 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)));
Leon Scroggins IIIcbc929d2023-12-01 16:21:37 -0500300
301 // Most tests will depend on the outputs being enabled.
302 for (auto& state : mOutputStates) {
303 state.isEnabled = true;
304 }
305
306 EXPECT_CALL(*mDisplay1, getState).WillRepeatedly(ReturnRef(mOutputStates[0]));
307 EXPECT_CALL(*mDisplay2, getState).WillRepeatedly(ReturnRef(mOutputStates[1]));
308 EXPECT_CALL(*mVirtualDisplay, getState).WillRepeatedly(ReturnRef(mOutputStates[2]));
309 EXPECT_CALL(*mHalVirtualDisplay, getState).WillRepeatedly(ReturnRef(mOutputStates[3]));
Leon Scroggins IIIab551a32023-11-22 10:08:25 -0500310 }
311
312 void setOutputs(std::initializer_list<std::shared_ptr<mock::Output>> outputs) {
313 for (auto& output : outputs) {
314 // If we call mEngine.present, prepare and present will be called on all the
315 // outputs in mRefreshArgs, but that's not the interesting part of the test.
316 EXPECT_CALL(*output, prepare(Ref(mRefreshArgs), _)).Times(1);
317 EXPECT_CALL(*output, present(Ref(mRefreshArgs)))
318 .WillOnce(Return(ftl::yield<std::monostate>({})));
319
320 mRefreshArgs.outputs.push_back(std::move(output));
321 }
322 }
323};
324
325TEST_F(CompositionEngineOffloadTest, basic) {
326 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
327 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(true));
328
329 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
330 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
331
332 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
333 setOutputs({mDisplay1, mDisplay2});
334
335 mEngine.present(mRefreshArgs);
336}
337
338TEST_F(CompositionEngineOffloadTest, dependsOnSupport) {
339 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(false));
340 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).Times(0);
341
342 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
343 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
344
345 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
346 setOutputs({mDisplay1, mDisplay2});
347
348 mEngine.present(mRefreshArgs);
349}
350
351TEST_F(CompositionEngineOffloadTest, dependsOnSupport2) {
352 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
353 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(false));
354
355 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
356 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
357
358 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
359 setOutputs({mDisplay1, mDisplay2});
360
361 mEngine.present(mRefreshArgs);
362}
363
364TEST_F(CompositionEngineOffloadTest, dependsOnFlag) {
365 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).Times(0);
366 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).Times(0);
367
368 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
369 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
370
371 SET_FLAG_FOR_TEST(flags::multithreaded_present, false);
372 setOutputs({mDisplay1, mDisplay2});
373
374 mEngine.present(mRefreshArgs);
375}
376
377TEST_F(CompositionEngineOffloadTest, oneDisplay) {
378 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).Times(0);
379
380 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
381
382 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
383 setOutputs({mDisplay1});
384
385 mEngine.present(mRefreshArgs);
386}
387
388TEST_F(CompositionEngineOffloadTest, virtualDisplay) {
389 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
390 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(true));
391 EXPECT_CALL(*mVirtualDisplay, supportsOffloadPresent).Times(0);
392
393 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
394 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
395 EXPECT_CALL(*mVirtualDisplay, offloadPresentNextFrame).Times(0);
396
397 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
398 setOutputs({mDisplay1, mDisplay2, mVirtualDisplay});
399
400 mEngine.present(mRefreshArgs);
401}
402
403TEST_F(CompositionEngineOffloadTest, virtualDisplay2) {
404 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
405 EXPECT_CALL(*mVirtualDisplay, supportsOffloadPresent).Times(0);
406
407 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
408 EXPECT_CALL(*mVirtualDisplay, offloadPresentNextFrame).Times(0);
409
410 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
411 setOutputs({mDisplay1, mVirtualDisplay});
412
413 mEngine.present(mRefreshArgs);
414}
415
416TEST_F(CompositionEngineOffloadTest, halVirtual) {
417 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
418 EXPECT_CALL(*mHalVirtualDisplay, supportsOffloadPresent).WillOnce(Return(true));
419
420 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
421 EXPECT_CALL(*mHalVirtualDisplay, offloadPresentNextFrame).Times(0);
422
423 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
424 setOutputs({mDisplay1, mHalVirtualDisplay});
425
426 mEngine.present(mRefreshArgs);
427}
428
429TEST_F(CompositionEngineOffloadTest, ordering) {
430 EXPECT_CALL(*mVirtualDisplay, supportsOffloadPresent).Times(0);
431 EXPECT_CALL(*mHalVirtualDisplay, supportsOffloadPresent).WillOnce(Return(true));
432 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
433 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillOnce(Return(true));
434
435 EXPECT_CALL(*mVirtualDisplay, offloadPresentNextFrame).Times(0);
436 EXPECT_CALL(*mHalVirtualDisplay, offloadPresentNextFrame).Times(1);
437 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
438 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
439
440 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
441 setOutputs({mVirtualDisplay, mHalVirtualDisplay, mDisplay1, mDisplay2});
442
443 mEngine.present(mRefreshArgs);
444}
445
Leon Scroggins IIIcbc929d2023-12-01 16:21:37 -0500446TEST_F(CompositionEngineOffloadTest, dependsOnEnabled) {
447 // Disable mDisplay2.
448 mOutputStates[1].isEnabled = false;
449 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
450
451 // This is not actually called, because it is not enabled, but this distinguishes
452 // from the case where it did not return true.
453 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillRepeatedly(Return(true));
454
455 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(0);
456 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
457
458 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
459 setOutputs({mDisplay1, mDisplay2});
460
461 mEngine.present(mRefreshArgs);
462}
463
464TEST_F(CompositionEngineOffloadTest, disabledDisplaysDoNotPreventOthersFromOffloading) {
465 // Disable mDisplay2.
466 mOutputStates[1].isEnabled = false;
467 EXPECT_CALL(*mDisplay1, supportsOffloadPresent).WillOnce(Return(true));
468
469 // This is not actually called, because it is not enabled, but this distinguishes
470 // from the case where it did not return true.
471 EXPECT_CALL(*mDisplay2, supportsOffloadPresent).WillRepeatedly(Return(true));
472 EXPECT_CALL(*mHalVirtualDisplay, supportsOffloadPresent).WillOnce(Return(true));
473
474 EXPECT_CALL(*mDisplay1, offloadPresentNextFrame).Times(1);
475 EXPECT_CALL(*mDisplay2, offloadPresentNextFrame).Times(0);
476 EXPECT_CALL(*mHalVirtualDisplay, offloadPresentNextFrame).Times(0);
477
478 SET_FLAG_FOR_TEST(flags::multithreaded_present, true);
479 setOutputs({mDisplay1, mDisplay2, mHalVirtualDisplay});
480
481 mEngine.present(mRefreshArgs);
482}
483
Lloyd Pique70d91362018-10-18 16:02:55 -0700484} // namespace
485} // namespace android::compositionengine