blob: a9a617bfa10c9c66726e515eb44864a81ec97941 [file] [log] [blame]
Valerie Haud251afb2019-03-29 14:19:02 -07001/*
2 * Copyright 2019 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
20#include <compositionengine/Display.h>
21#include <compositionengine/mock/DisplaySurface.h>
22#include <gmock/gmock.h>
23#include <gtest/gtest.h>
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070024#include <gui/LayerState.h>
Valerie Haud251afb2019-03-29 14:19:02 -070025#include <gui/SurfaceComposerClient.h>
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070026#include <gui/fake/BufferData.h>
Valerie Haud251afb2019-03-29 14:19:02 -070027#include <log/log.h>
ramindani4d48f902021-09-20 21:07:45 +000028#include <ui/MockFence.h>
Valerie Haud251afb2019-03-29 14:19:02 -070029#include <utils/String8.h>
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070030#include <vector>
31#include <binder/Binder.h>
Dominik Laskowski068173d2021-08-11 17:22:59 -070032
Vishnu Naira61e4fb2022-10-18 18:29:37 +000033#include "FrontEnd/TransactionHandler.h"
Valerie Haud251afb2019-03-29 14:19:02 -070034#include "TestableSurfaceFlinger.h"
Vishnu Nair40fff5c2022-11-04 02:46:28 +000035#include "TransactionState.h"
Valerie Haud251afb2019-03-29 14:19:02 -070036#include "mock/MockEventThread.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070037#include "mock/MockVsyncController.h"
Valerie Haud251afb2019-03-29 14:19:02 -070038
39namespace android {
40
41using testing::_;
42using testing::Return;
43
44using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
Vishnu Nairaf6d2972022-11-18 06:26:38 +000045using frontend::TransactionHandler;
46
Vishnu Nair1523dad2022-09-29 16:05:18 -070047constexpr nsecs_t TRANSACTION_TIMEOUT = s2ns(5);
Valerie Haud251afb2019-03-29 14:19:02 -070048class TransactionApplicationTest : public testing::Test {
49public:
50 TransactionApplicationTest() {
51 const ::testing::TestInfo* const test_info =
52 ::testing::UnitTest::GetInstance()->current_test_info();
53 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
54
Valerie Haud251afb2019-03-29 14:19:02 -070055 setupScheduler();
56 }
57
58 ~TransactionApplicationTest() {
59 const ::testing::TestInfo* const test_info =
60 ::testing::UnitTest::GetInstance()->current_test_info();
61 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
62 }
63
64 void setupScheduler() {
65 auto eventThread = std::make_unique<mock::EventThread>();
66 auto sfEventThread = std::make_unique<mock::EventThread>();
67
68 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
69 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abrahamd11bade2022-08-01 16:18:03 -070070 .WillOnce(Return(sp<EventThreadConnection>::make(eventThread.get(),
71 mock::EventThread::kCallingUid,
72 ResyncCallback())));
Valerie Haud251afb2019-03-29 14:19:02 -070073
74 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
75 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abrahamd11bade2022-08-01 16:18:03 -070076 .WillOnce(Return(sp<EventThreadConnection>::make(sfEventThread.get(),
77 mock::EventThread::kCallingUid,
78 ResyncCallback())));
Valerie Haud251afb2019-03-29 14:19:02 -070079
Ady Abraham8cb21882020-08-26 18:22:05 -070080 EXPECT_CALL(*mVSyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
81 EXPECT_CALL(*mVSyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +010082 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Valerie Haud251afb2019-03-29 14:19:02 -070083
Ady Abraham3efa3942021-06-24 19:01:25 -070084 mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>());
Ady Abraham8cb21882020-08-26 18:22:05 -070085 mFlinger.setupScheduler(std::unique_ptr<mock::VsyncController>(mVsyncController),
Leon Scroggins III31d41412022-11-18 16:42:53 -050086 mVSyncTracker, std::move(eventThread), std::move(sfEventThread));
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070087 mFlinger.flinger()->addTransactionReadyFilters();
Valerie Haud251afb2019-03-29 14:19:02 -070088 }
89
Valerie Haud251afb2019-03-29 14:19:02 -070090 TestableSurfaceFlinger mFlinger;
91
Ady Abraham8cb21882020-08-26 18:22:05 -070092 mock::VsyncController* mVsyncController = new mock::VsyncController();
Leon Scroggins III31d41412022-11-18 16:42:53 -050093 std::shared_ptr<mock::VSyncTracker> mVSyncTracker = std::make_shared<mock::VSyncTracker>();
Valerie Haud251afb2019-03-29 14:19:02 -070094
95 struct TransactionInfo {
96 Vector<ComposerState> states;
97 Vector<DisplayState> displays;
98 uint32_t flags = 0;
99 sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
100 InputWindowCommands inputWindowCommands;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800101 int64_t desiredPresentTime = 0;
102 bool isAutoTimestamp = true;
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000103 FrameTimelineInfo frameTimelineInfo;
Patrick Williams75ce1ea2023-01-19 15:02:30 -0600104 std::vector<client_cache_t> uncacheBuffers;
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000105 uint64_t id = static_cast<uint64_t>(-1);
106 static_assert(0xffffffffffffffff == static_cast<uint64_t>(-1));
Valerie Haud251afb2019-03-29 14:19:02 -0700107 };
108
Vishnu Nair6b591152021-10-08 11:45:14 -0700109 void checkEqual(TransactionInfo info, TransactionState state) {
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000110 EXPECT_EQ(0u, info.states.size());
111 EXPECT_EQ(0u, state.states.size());
Valerie Haud251afb2019-03-29 14:19:02 -0700112
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000113 EXPECT_EQ(0u, info.displays.size());
114 EXPECT_EQ(0u, state.displays.size());
Valerie Haud251afb2019-03-29 14:19:02 -0700115 EXPECT_EQ(info.flags, state.flags);
116 EXPECT_EQ(info.desiredPresentTime, state.desiredPresentTime);
117 }
118
Patrick Williams641f7f22022-06-22 19:25:35 +0000119 void setupSingle(TransactionInfo& transaction, uint32_t flags, int64_t desiredPresentTime,
120 bool isAutoTimestamp, const FrameTimelineInfo& frameTimelineInfo) {
Valerie Haud251afb2019-03-29 14:19:02 -0700121 mTransactionNumber++;
Vishnu Nair1523dad2022-09-29 16:05:18 -0700122 transaction.flags |= flags;
Valerie Haud251afb2019-03-29 14:19:02 -0700123 transaction.desiredPresentTime = desiredPresentTime;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800124 transaction.isAutoTimestamp = isAutoTimestamp;
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000125 transaction.frameTimelineInfo = frameTimelineInfo;
Valerie Haud251afb2019-03-29 14:19:02 -0700126 }
127
Patrick Williams641f7f22022-06-22 19:25:35 +0000128 void NotPlacedOnTransactionQueue(uint32_t flags) {
Vishnu Nair60d902e2022-07-20 02:55:37 +0000129 ASSERT_TRUE(mFlinger.getTransactionQueue().isEmpty());
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700130 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Valerie Haud251afb2019-03-29 14:19:02 -0700131 TransactionInfo transaction;
Patrick Williams641f7f22022-06-22 19:25:35 +0000132 setupSingle(transaction, flags,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800133 /*desiredPresentTime*/ systemTime(), /*isAutoTimestamp*/ true,
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000134 FrameTimelineInfo{});
Valerie Haud251afb2019-03-29 14:19:02 -0700135 nsecs_t applicationTime = systemTime();
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000136 mFlinger.setTransactionState(transaction.frameTimelineInfo, transaction.states,
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700137 transaction.displays, transaction.flags,
Valerie Haud251afb2019-03-29 14:19:02 -0700138 transaction.applyToken, transaction.inputWindowCommands,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800139 transaction.desiredPresentTime, transaction.isAutoTimestamp,
Patrick Williams75ce1ea2023-01-19 15:02:30 -0600140 transaction.uncacheBuffers, mHasListenerCallbacks, mCallbacks,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800141 transaction.id);
Valerie Haud251afb2019-03-29 14:19:02 -0700142
Patrick Williams641f7f22022-06-22 19:25:35 +0000143 // If transaction is synchronous, SF applyTransactionState should time out (5s) wating for
144 // SF to commit the transaction. If this is animation, it should not time out waiting.
Valerie Haud251afb2019-03-29 14:19:02 -0700145 nsecs_t returnedTime = systemTime();
Vishnu Nair1523dad2022-09-29 16:05:18 -0700146 EXPECT_LE(returnedTime, applicationTime + TRANSACTION_TIMEOUT);
Arthur Hung58144272021-01-16 03:43:53 +0000147 // Each transaction should have been placed on the transaction queue
Vishnu Nair60d902e2022-07-20 02:55:37 +0000148 auto& transactionQueue = mFlinger.getTransactionQueue();
149 EXPECT_FALSE(transactionQueue.isEmpty());
Valerie Haud251afb2019-03-29 14:19:02 -0700150 }
151
Patrick Williams641f7f22022-06-22 19:25:35 +0000152 void PlaceOnTransactionQueue(uint32_t flags) {
Vishnu Nair60d902e2022-07-20 02:55:37 +0000153 ASSERT_TRUE(mFlinger.getTransactionQueue().isEmpty());
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700154 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Valerie Haud251afb2019-03-29 14:19:02 -0700155
156 // first check will see desired present time has not passed,
157 // but afterwards it will look like the desired present time has passed
158 nsecs_t time = systemTime();
Valerie Haud251afb2019-03-29 14:19:02 -0700159 TransactionInfo transaction;
Patrick Williams641f7f22022-06-22 19:25:35 +0000160 setupSingle(transaction, flags, /*desiredPresentTime*/ time + s2ns(1), false,
161 FrameTimelineInfo{});
Valerie Haud251afb2019-03-29 14:19:02 -0700162 nsecs_t applicationSentTime = systemTime();
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000163 mFlinger.setTransactionState(transaction.frameTimelineInfo, transaction.states,
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700164 transaction.displays, transaction.flags,
Valerie Haud251afb2019-03-29 14:19:02 -0700165 transaction.applyToken, transaction.inputWindowCommands,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800166 transaction.desiredPresentTime, transaction.isAutoTimestamp,
Patrick Williams75ce1ea2023-01-19 15:02:30 -0600167 transaction.uncacheBuffers, mHasListenerCallbacks, mCallbacks,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800168 transaction.id);
Valerie Haud251afb2019-03-29 14:19:02 -0700169
170 nsecs_t returnedTime = systemTime();
Vishnu Nair1523dad2022-09-29 16:05:18 -0700171 EXPECT_LE(returnedTime, applicationSentTime + TRANSACTION_TIMEOUT);
Valerie Haud251afb2019-03-29 14:19:02 -0700172 // This transaction should have been placed on the transaction queue
Vishnu Nair60d902e2022-07-20 02:55:37 +0000173 auto& transactionQueue = mFlinger.getTransactionQueue();
174 EXPECT_FALSE(transactionQueue.isEmpty());
Valerie Haud251afb2019-03-29 14:19:02 -0700175 }
176
Patrick Williams641f7f22022-06-22 19:25:35 +0000177 void BlockedByPriorTransaction(uint32_t flags) {
Vishnu Nair60d902e2022-07-20 02:55:37 +0000178 ASSERT_TRUE(mFlinger.getTransactionQueue().isEmpty());
Valerie Haud251afb2019-03-29 14:19:02 -0700179 nsecs_t time = systemTime();
Patrick Williams641f7f22022-06-22 19:25:35 +0000180 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(2);
181
Valerie Haud251afb2019-03-29 14:19:02 -0700182 // transaction that should go on the pending thread
183 TransactionInfo transactionA;
Patrick Williams641f7f22022-06-22 19:25:35 +0000184 setupSingle(transactionA, /*flags*/ 0, /*desiredPresentTime*/ time + s2ns(1), false,
185 FrameTimelineInfo{});
Valerie Haud251afb2019-03-29 14:19:02 -0700186
187 // transaction that would not have gone on the pending thread if not
188 // blocked
189 TransactionInfo transactionB;
Patrick Williams641f7f22022-06-22 19:25:35 +0000190 setupSingle(transactionB, flags, /*desiredPresentTime*/ systemTime(),
191 /*isAutoTimestamp*/ true, FrameTimelineInfo{});
Valerie Haud251afb2019-03-29 14:19:02 -0700192
193 nsecs_t applicationSentTime = systemTime();
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000194 mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states,
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700195 transactionA.displays, transactionA.flags,
Valerie Haud251afb2019-03-29 14:19:02 -0700196 transactionA.applyToken, transactionA.inputWindowCommands,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800197 transactionA.desiredPresentTime, transactionA.isAutoTimestamp,
Patrick Williams75ce1ea2023-01-19 15:02:30 -0600198 transactionA.uncacheBuffers, mHasListenerCallbacks, mCallbacks,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800199 transactionA.id);
Valerie Haud251afb2019-03-29 14:19:02 -0700200
201 // This thread should not have been blocked by the above transaction
202 // (5s is the timeout period that applyTransactionState waits for SF to
203 // commit the transaction)
Vishnu Nair1523dad2022-09-29 16:05:18 -0700204 EXPECT_LE(systemTime(), applicationSentTime + TRANSACTION_TIMEOUT);
Arthur Hung58144272021-01-16 03:43:53 +0000205 // transaction that would goes to pending transaciton queue.
206 mFlinger.flushTransactionQueues();
Valerie Haud251afb2019-03-29 14:19:02 -0700207
208 applicationSentTime = systemTime();
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000209 mFlinger.setTransactionState(transactionB.frameTimelineInfo, transactionB.states,
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700210 transactionB.displays, transactionB.flags,
Valerie Haud251afb2019-03-29 14:19:02 -0700211 transactionB.applyToken, transactionB.inputWindowCommands,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800212 transactionB.desiredPresentTime, transactionB.isAutoTimestamp,
Patrick Williams75ce1ea2023-01-19 15:02:30 -0600213 transactionB.uncacheBuffers, mHasListenerCallbacks, mCallbacks,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800214 transactionB.id);
Valerie Haud251afb2019-03-29 14:19:02 -0700215
216 // this thread should have been blocked by the above transaction
217 // if this is an animation, this thread should be blocked for 5s
218 // in setTransactionState waiting for transactionA to flush. Otherwise,
219 // the transaction should be placed on the pending queue
Vishnu Nair1523dad2022-09-29 16:05:18 -0700220 EXPECT_LE(systemTime(), applicationSentTime + TRANSACTION_TIMEOUT);
Valerie Haud251afb2019-03-29 14:19:02 -0700221
Arthur Hung58144272021-01-16 03:43:53 +0000222 // transaction that would goes to pending transaciton queue.
223 mFlinger.flushTransactionQueues();
224
Ady Abrahame46243a2021-02-23 19:33:49 -0800225 // check that the transaction was applied.
Arthur Hung58144272021-01-16 03:43:53 +0000226 auto transactionQueue = mFlinger.getPendingTransactionQueue();
Ady Abrahame46243a2021-02-23 19:33:49 -0800227 EXPECT_EQ(0u, transactionQueue.size());
Valerie Haud251afb2019-03-29 14:19:02 -0700228 }
229
Dominik Laskowski1c99a002023-01-20 17:10:36 -0500230 void modulateVsync() {
231 static_cast<void>(
232 mFlinger.mutableScheduler().mutableVsyncModulator().onRefreshRateChangeInitiated());
233 }
234
Valerie Haud251afb2019-03-29 14:19:02 -0700235 bool mHasListenerCallbacks = false;
236 std::vector<ListenerCallbacks> mCallbacks;
237 int mTransactionNumber = 0;
238};
239
Vishnu Nair60d902e2022-07-20 02:55:37 +0000240TEST_F(TransactionApplicationTest, AddToPendingQueue) {
241 ASSERT_TRUE(mFlinger.getTransactionQueue().isEmpty());
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700242 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Valerie Haud251afb2019-03-29 14:19:02 -0700243
Valerie Haud251afb2019-03-29 14:19:02 -0700244 TransactionInfo transactionA; // transaction to go on pending queue
Patrick Williams641f7f22022-06-22 19:25:35 +0000245 setupSingle(transactionA, /*flags*/ 0, /*desiredPresentTime*/ s2ns(1), false,
246 FrameTimelineInfo{});
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000247 mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states,
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700248 transactionA.displays, transactionA.flags, transactionA.applyToken,
249 transactionA.inputWindowCommands, transactionA.desiredPresentTime,
Patrick Williams75ce1ea2023-01-19 15:02:30 -0600250 transactionA.isAutoTimestamp, transactionA.uncacheBuffers,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800251 mHasListenerCallbacks, mCallbacks, transactionA.id);
Valerie Haud251afb2019-03-29 14:19:02 -0700252
Zhuoyao Zhang3d3540d2021-01-14 05:14:54 +0000253 auto& transactionQueue = mFlinger.getTransactionQueue();
Vishnu Nair60d902e2022-07-20 02:55:37 +0000254 ASSERT_FALSE(transactionQueue.isEmpty());
Valerie Haud251afb2019-03-29 14:19:02 -0700255
Vishnu Nair60d902e2022-07-20 02:55:37 +0000256 auto transactionState = transactionQueue.pop().value();
Valerie Haud251afb2019-03-29 14:19:02 -0700257 checkEqual(transactionA, transactionState);
Vishnu Nair60d902e2022-07-20 02:55:37 +0000258}
259
260TEST_F(TransactionApplicationTest, Flush_RemovesFromQueue) {
261 ASSERT_TRUE(mFlinger.getTransactionQueue().isEmpty());
262 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
263
264 TransactionInfo transactionA; // transaction to go on pending queue
265 setupSingle(transactionA, /*flags*/ 0, /*desiredPresentTime*/ s2ns(1), false,
266 FrameTimelineInfo{});
267 mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states,
268 transactionA.displays, transactionA.flags, transactionA.applyToken,
269 transactionA.inputWindowCommands, transactionA.desiredPresentTime,
Patrick Williams75ce1ea2023-01-19 15:02:30 -0600270 transactionA.isAutoTimestamp, transactionA.uncacheBuffers,
Vishnu Nair60d902e2022-07-20 02:55:37 +0000271 mHasListenerCallbacks, mCallbacks, transactionA.id);
272
273 auto& transactionQueue = mFlinger.getTransactionQueue();
274 ASSERT_FALSE(transactionQueue.isEmpty());
Valerie Haud251afb2019-03-29 14:19:02 -0700275
276 // because flushing uses the cached expected present time, we send an empty
277 // transaction here (sending a null applyToken to fake it as from a
278 // different process) to re-query and reset the cached expected present time
279 TransactionInfo empty;
280 empty.applyToken = sp<IBinder>();
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000281 mFlinger.setTransactionState(empty.frameTimelineInfo, empty.states, empty.displays, empty.flags,
282 empty.applyToken, empty.inputWindowCommands,
Ady Abrahamf0c56492020-12-17 18:04:15 -0800283 empty.desiredPresentTime, empty.isAutoTimestamp,
Patrick Williams75ce1ea2023-01-19 15:02:30 -0600284 empty.uncacheBuffers, mHasListenerCallbacks, mCallbacks, empty.id);
Valerie Haud251afb2019-03-29 14:19:02 -0700285
Zhuoyao Zhang3d3540d2021-01-14 05:14:54 +0000286 // flush transaction queue should flush as desiredPresentTime has
Valerie Haud251afb2019-03-29 14:19:02 -0700287 // passed
Zhuoyao Zhang3d3540d2021-01-14 05:14:54 +0000288 mFlinger.flushTransactionQueues();
Valerie Haud251afb2019-03-29 14:19:02 -0700289
Vishnu Nair60d902e2022-07-20 02:55:37 +0000290 EXPECT_TRUE(mFlinger.getTransactionQueue().isEmpty());
Valerie Haud251afb2019-03-29 14:19:02 -0700291}
292
Valerie Haud251afb2019-03-29 14:19:02 -0700293TEST_F(TransactionApplicationTest, NotPlacedOnTransactionQueue_SyncInputWindows) {
Patrick Williams641f7f22022-06-22 19:25:35 +0000294 NotPlacedOnTransactionQueue(/*flags*/ 0);
Valerie Haud251afb2019-03-29 14:19:02 -0700295}
296
Valerie Haud251afb2019-03-29 14:19:02 -0700297TEST_F(TransactionApplicationTest, PlaceOnTransactionQueue_SyncInputWindows) {
Patrick Williams641f7f22022-06-22 19:25:35 +0000298 PlaceOnTransactionQueue(/*flags*/ 0);
Valerie Haud251afb2019-03-29 14:19:02 -0700299}
300
Valerie Hau09e60052019-12-15 14:51:15 -0800301TEST_F(TransactionApplicationTest, FromHandle) {
302 sp<IBinder> badHandle;
303 auto ret = mFlinger.fromHandle(badHandle);
Vishnu Nair07e2a482022-10-18 19:18:16 +0000304 EXPECT_EQ(nullptr, ret.get());
Valerie Hau09e60052019-12-15 14:51:15 -0800305}
ramindani4d48f902021-09-20 21:07:45 +0000306
Ady Abraham9dada822022-02-03 10:26:59 -0800307class LatchUnsignaledTest : public TransactionApplicationTest {
308public:
309 void TearDown() override {
310 // Clear all transaction queues to release all transactions we sent
311 // in the tests. Otherwise, gmock complains about memory leaks.
Vishnu Nair60d902e2022-07-20 02:55:37 +0000312 while (!mFlinger.getTransactionQueue().isEmpty()) {
313 mFlinger.getTransactionQueue().pop();
314 }
Ady Abraham9dada822022-02-03 10:26:59 -0800315 mFlinger.getPendingTransactionQueue().clear();
Ady Abraham9dada822022-02-03 10:26:59 -0800316 mFlinger.commitTransactionsLocked(eTransactionMask);
317 mFlinger.mutableCurrentState().layersSortedByZ.clear();
318 mFlinger.mutableDrawingState().layersSortedByZ.clear();
319 }
320
321 static sp<Fence> fence(Fence::Status status) {
322 const auto fence = sp<mock::MockFence>::make();
323 EXPECT_CALL(*fence, getStatus()).WillRepeatedly(Return(status));
324 return fence;
325 }
326
327 ComposerState createComposerState(int layerId, sp<Fence> fence, uint64_t what) {
328 ComposerState state;
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700329 state.state.bufferData =
330 std::make_shared<fake::BufferData>(/* bufferId */ 123L, /* width */ 1,
331 /* height */ 2, /* pixelFormat */ 0,
332 /* outUsage */ 0);
Ady Abraham9dada822022-02-03 10:26:59 -0800333 state.state.bufferData->acquireFence = std::move(fence);
334 state.state.layerId = layerId;
335 state.state.surface =
Patrick Williams83f36b22022-09-14 17:57:35 +0000336 sp<Layer>::make(LayerCreationArgs(mFlinger.flinger(), nullptr, "TestLayer", 0, {}))
Ady Abraham9dada822022-02-03 10:26:59 -0800337 ->getHandle();
338 state.state.bufferData->flags = BufferData::BufferDataChange::fenceChanged;
339
340 state.state.what = what;
341 if (what & layer_state_t::eCropChanged) {
342 state.state.crop = Rect(1, 2, 3, 4);
343 }
344 return state;
345 }
346
347 TransactionInfo createTransactionInfo(const sp<IBinder>& applyToken,
348 const std::vector<ComposerState>& states) {
349 TransactionInfo transaction;
Vishnu Nair1523dad2022-09-29 16:05:18 -0700350 const uint32_t kFlags = 0;
Ady Abraham9dada822022-02-03 10:26:59 -0800351 const nsecs_t kDesiredPresentTime = systemTime();
352 const bool kIsAutoTimestamp = true;
353 const auto kFrameTimelineInfo = FrameTimelineInfo{};
354
Patrick Williams641f7f22022-06-22 19:25:35 +0000355 setupSingle(transaction, kFlags, kDesiredPresentTime, kIsAutoTimestamp, kFrameTimelineInfo);
Ady Abraham9dada822022-02-03 10:26:59 -0800356 transaction.applyToken = applyToken;
357 for (const auto& state : states) {
358 transaction.states.push_back(state);
359 }
360
361 return transaction;
362 }
363
364 void setTransactionStates(const std::vector<TransactionInfo>& transactions,
Ady Abraham9dada822022-02-03 10:26:59 -0800365 size_t expectedTransactionsPending) {
Vishnu Nair60d902e2022-07-20 02:55:37 +0000366 EXPECT_TRUE(mFlinger.getTransactionQueue().isEmpty());
Ady Abraham9dada822022-02-03 10:26:59 -0800367 EXPECT_EQ(0u, mFlinger.getPendingTransactionQueue().size());
368
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000369 for (auto transaction : transactions) {
370 std::vector<ResolvedComposerState> resolvedStates;
371 resolvedStates.reserve(transaction.states.size());
372 for (auto& state : transaction.states) {
373 resolvedStates.emplace_back(std::move(state));
374 }
375
376 TransactionState transactionState(transaction.frameTimelineInfo, resolvedStates,
377 transaction.displays, transaction.flags,
378 transaction.applyToken,
379 transaction.inputWindowCommands,
380 transaction.desiredPresentTime,
Patrick Williams75ce1ea2023-01-19 15:02:30 -0600381 transaction.isAutoTimestamp, {}, systemTime(), 0,
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000382 mHasListenerCallbacks, mCallbacks, getpid(),
383 static_cast<int>(getuid()), transaction.id);
384 mFlinger.setTransactionStateInternal(transactionState);
Ady Abraham9dada822022-02-03 10:26:59 -0800385 }
386 mFlinger.flushTransactionQueues();
Vishnu Nair60d902e2022-07-20 02:55:37 +0000387 EXPECT_TRUE(mFlinger.getTransactionQueue().isEmpty());
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700388 EXPECT_EQ(expectedTransactionsPending, mFlinger.getPendingTransactionCount());
Ady Abraham9dada822022-02-03 10:26:59 -0800389 }
390};
391
392class LatchUnsignaledAutoSingleLayerTest : public LatchUnsignaledTest {
393public:
394 void SetUp() override {
395 LatchUnsignaledTest::SetUp();
396 SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::AutoSingleLayer;
397 }
398};
399
400TEST_F(LatchUnsignaledAutoSingleLayerTest, Flush_RemovesSingleSignaledFromTheQueue) {
401 const sp<IBinder> kApplyToken =
402 IInterface::asBinder(TransactionCompletedListener::getIInstance());
403 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800404 const auto kExpectedTransactionsPending = 0u;
405
406 const auto signaledTransaction =
407 createTransactionInfo(kApplyToken,
408 {createComposerState(kLayerId, fence(Fence::Status::Signaled),
409 layer_state_t::eBufferChanged)});
Vishnu Nair1523dad2022-09-29 16:05:18 -0700410 setTransactionStates({signaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000411}
412
Ady Abraham9dada822022-02-03 10:26:59 -0800413TEST_F(LatchUnsignaledAutoSingleLayerTest, Flush_RemovesSingleUnSignaledFromTheQueue) {
414 const sp<IBinder> kApplyToken =
415 IInterface::asBinder(TransactionCompletedListener::getIInstance());
416 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800417 const auto kExpectedTransactionsPending = 0u;
418
419 const auto unsignaledTransaction =
420 createTransactionInfo(kApplyToken,
421 {
422 createComposerState(kLayerId,
423 fence(Fence::Status::Unsignaled),
424 layer_state_t::eBufferChanged),
425 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700426 setTransactionStates({unsignaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000427}
428
Ady Abraham9dada822022-02-03 10:26:59 -0800429TEST_F(LatchUnsignaledAutoSingleLayerTest, Flush_KeepsUnSignaledInTheQueue_NonBufferCropChange) {
430 const sp<IBinder> kApplyToken =
431 IInterface::asBinder(TransactionCompletedListener::getIInstance());
432 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800433 const auto kExpectedTransactionsPending = 1u;
434
435 const auto unsignaledTransaction =
436 createTransactionInfo(kApplyToken,
437 {
438 createComposerState(kLayerId,
439 fence(Fence::Status::Unsignaled),
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700440 layer_state_t::eCropChanged |
441 layer_state_t::
442 eBufferChanged),
Ady Abraham9dada822022-02-03 10:26:59 -0800443 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700444 setTransactionStates({unsignaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000445}
446
Ady Abraham9dada822022-02-03 10:26:59 -0800447TEST_F(LatchUnsignaledAutoSingleLayerTest, Flush_KeepsUnSignaledInTheQueue_NonBufferChangeClubed) {
448 const sp<IBinder> kApplyToken =
449 IInterface::asBinder(TransactionCompletedListener::getIInstance());
450 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800451 const auto kExpectedTransactionsPending = 1u;
452
453 const auto unsignaledTransaction =
454 createTransactionInfo(kApplyToken,
455 {
456 createComposerState(kLayerId,
457 fence(Fence::Status::Unsignaled),
458 layer_state_t::eCropChanged |
459 layer_state_t::
460 eBufferChanged),
461 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700462 setTransactionStates({unsignaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000463}
464
Ady Abraham9dada822022-02-03 10:26:59 -0800465TEST_F(LatchUnsignaledAutoSingleLayerTest, Flush_KeepsInTheQueueSameApplyTokenMultiState) {
466 const sp<IBinder> kApplyToken =
467 IInterface::asBinder(TransactionCompletedListener::getIInstance());
468 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800469 const auto kExpectedTransactionsPending = 1u;
470
471 const auto mixedTransaction =
472 createTransactionInfo(kApplyToken,
473 {
474 createComposerState(kLayerId,
475 fence(Fence::Status::Unsignaled),
476 layer_state_t::eBufferChanged),
477 createComposerState(kLayerId,
478 fence(Fence::Status::Signaled),
479 layer_state_t::eBufferChanged),
480 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700481 setTransactionStates({mixedTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000482}
483
Ady Abraham9dada822022-02-03 10:26:59 -0800484TEST_F(LatchUnsignaledAutoSingleLayerTest, Flush_KeepsInTheQueue_MultipleStateTransaction) {
485 const sp<IBinder> kApplyToken =
486 IInterface::asBinder(TransactionCompletedListener::getIInstance());
487 const auto kLayerId1 = 1;
488 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800489 const auto kExpectedTransactionsPending = 1u;
490
491 const auto mixedTransaction =
492 createTransactionInfo(kApplyToken,
493 {
494 createComposerState(kLayerId1,
495 fence(Fence::Status::Unsignaled),
496 layer_state_t::eBufferChanged),
497 createComposerState(kLayerId2,
498 fence(Fence::Status::Signaled),
499 layer_state_t::eBufferChanged),
500 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700501 setTransactionStates({mixedTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000502}
503
Ady Abraham9dada822022-02-03 10:26:59 -0800504TEST_F(LatchUnsignaledAutoSingleLayerTest, Flush_RemovesSignaledFromTheQueue) {
505 const sp<IBinder> kApplyToken =
506 IInterface::asBinder(TransactionCompletedListener::getIInstance());
507 const auto kLayerId1 = 1;
508 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800509 const auto kExpectedTransactionsPending = 0u;
510
511 const auto signaledTransaction =
512 createTransactionInfo(kApplyToken,
513 {
514 createComposerState(kLayerId1,
515 fence(Fence::Status::Signaled),
516 layer_state_t::eBufferChanged),
517 });
518 const auto signaledTransaction2 =
519 createTransactionInfo(kApplyToken,
520 {
521 createComposerState(kLayerId2,
522 fence(Fence::Status::Signaled),
523 layer_state_t::eBufferChanged),
524 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700525 setTransactionStates({signaledTransaction, signaledTransaction2}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000526}
527
Ady Abrahame1bfaac2022-02-22 21:32:08 -0800528TEST_F(LatchUnsignaledAutoSingleLayerTest,
529 UnsignaledNotAppliedWhenThereAreSignaled_UnsignaledFirst) {
Ady Abraham9dada822022-02-03 10:26:59 -0800530 const sp<IBinder> kApplyToken1 =
531 IInterface::asBinder(TransactionCompletedListener::getIInstance());
532 const sp<IBinder> kApplyToken2 = sp<BBinder>::make();
Ady Abrahame1bfaac2022-02-22 21:32:08 -0800533 const sp<IBinder> kApplyToken3 = sp<BBinder>::make();
Ady Abraham9dada822022-02-03 10:26:59 -0800534 const auto kLayerId1 = 1;
535 const auto kLayerId2 = 2;
Ady Abrahame1bfaac2022-02-22 21:32:08 -0800536 const auto kExpectedTransactionsPending = 1u;
537
538 const auto unsignaledTransaction =
539 createTransactionInfo(kApplyToken1,
540 {
541 createComposerState(kLayerId1,
542 fence(Fence::Status::Unsignaled),
543 layer_state_t::eBufferChanged),
544 });
545
546 const auto signaledTransaction =
547 createTransactionInfo(kApplyToken2,
548 {
549 createComposerState(kLayerId2,
550 fence(Fence::Status::Signaled),
551 layer_state_t::eBufferChanged),
552 });
553 const auto signaledTransaction2 =
554 createTransactionInfo(kApplyToken3,
555 {
556 createComposerState(kLayerId2,
557 fence(Fence::Status::Signaled),
558 layer_state_t::eBufferChanged),
559 });
560
561 setTransactionStates({unsignaledTransaction, signaledTransaction, signaledTransaction2},
Vishnu Nair1523dad2022-09-29 16:05:18 -0700562 kExpectedTransactionsPending);
Ady Abrahame1bfaac2022-02-22 21:32:08 -0800563}
564
Ady Abraham9dada822022-02-03 10:26:59 -0800565TEST_F(LatchUnsignaledAutoSingleLayerTest, Flush_KeepsTransactionInTheQueueSameApplyToken) {
566 const sp<IBinder> kApplyToken =
567 IInterface::asBinder(TransactionCompletedListener::getIInstance());
568 const auto kLayerId1 = 1;
569 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800570 const auto kExpectedTransactionsPending = 1u;
571
572 const auto unsignaledTransaction =
573 createTransactionInfo(kApplyToken,
574 {
575 createComposerState(kLayerId1,
576 fence(Fence::Status::Unsignaled),
577 layer_state_t::eBufferChanged),
578 });
579 const auto signaledTransaction =
580 createTransactionInfo(kApplyToken,
581 {
582 createComposerState(kLayerId2,
583 fence(Fence::Status::Signaled),
584 layer_state_t::eBufferChanged),
585 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700586 setTransactionStates({unsignaledTransaction, signaledTransaction},
Ady Abraham9dada822022-02-03 10:26:59 -0800587 kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000588}
589
Ady Abraham9dada822022-02-03 10:26:59 -0800590TEST_F(LatchUnsignaledAutoSingleLayerTest, Flush_KeepsTransactionInTheQueue) {
591 const sp<IBinder> kApplyToken1 =
592 IInterface::asBinder(TransactionCompletedListener::getIInstance());
593 const sp<IBinder> kApplyToken2 = sp<BBinder>::make();
594 const auto kLayerId1 = 1;
595 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800596 const auto kExpectedTransactionsPending = 1u;
597
598 const auto unsignaledTransaction =
599 createTransactionInfo(kApplyToken1,
600 {
601 createComposerState(kLayerId1,
602 fence(Fence::Status::Unsignaled),
603 layer_state_t::eBufferChanged),
604 });
605 const auto unsignaledTransaction2 =
606 createTransactionInfo(kApplyToken2,
607 {
608 createComposerState(kLayerId2,
609 fence(Fence::Status::Unsignaled),
610 layer_state_t::eBufferChanged),
611 });
612 setTransactionStates({unsignaledTransaction, unsignaledTransaction2},
Vishnu Nair1523dad2022-09-29 16:05:18 -0700613 kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000614}
615
Ady Abraham2739e832022-02-14 17:42:00 -0800616TEST_F(LatchUnsignaledAutoSingleLayerTest, DontLatchUnsignaledWhenEarlyOffset) {
617 const sp<IBinder> kApplyToken =
618 IInterface::asBinder(TransactionCompletedListener::getIInstance());
619 const auto kLayerId = 1;
Ady Abraham2739e832022-02-14 17:42:00 -0800620 const auto kExpectedTransactionsPending = 1u;
621
622 const auto unsignaledTransaction =
623 createTransactionInfo(kApplyToken,
624 {
625 createComposerState(kLayerId,
626 fence(Fence::Status::Unsignaled),
627 layer_state_t::eBufferChanged),
628 });
629
Dominik Laskowski1c99a002023-01-20 17:10:36 -0500630 modulateVsync();
Vishnu Nair1523dad2022-09-29 16:05:18 -0700631 setTransactionStates({unsignaledTransaction}, kExpectedTransactionsPending);
Ady Abraham2739e832022-02-14 17:42:00 -0800632}
633
Ady Abraham9dada822022-02-03 10:26:59 -0800634class LatchUnsignaledDisabledTest : public LatchUnsignaledTest {
635public:
636 void SetUp() override {
637 LatchUnsignaledTest::SetUp();
638 SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Disabled;
639 }
640};
641
642TEST_F(LatchUnsignaledDisabledTest, Flush_RemovesSignaledFromTheQueue) {
643 const sp<IBinder> kApplyToken =
644 IInterface::asBinder(TransactionCompletedListener::getIInstance());
645 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800646 const auto kExpectedTransactionsPending = 0u;
647
648 const auto signaledTransaction =
649 createTransactionInfo(kApplyToken,
650 {createComposerState(kLayerId, fence(Fence::Status::Signaled),
651 layer_state_t::eBufferChanged)});
Vishnu Nair1523dad2022-09-29 16:05:18 -0700652 setTransactionStates({signaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000653}
654
Ady Abraham9dada822022-02-03 10:26:59 -0800655TEST_F(LatchUnsignaledDisabledTest, Flush_KeepsInTheQueue) {
656 const sp<IBinder> kApplyToken =
657 IInterface::asBinder(TransactionCompletedListener::getIInstance());
658 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800659 const auto kExpectedTransactionsPending = 1u;
660
661 const auto unsignaledTransaction =
662 createTransactionInfo(kApplyToken,
663 {
664 createComposerState(kLayerId,
665 fence(Fence::Status::Unsignaled),
666 layer_state_t::eBufferChanged),
667 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700668 setTransactionStates({unsignaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000669}
670
Ady Abraham9dada822022-02-03 10:26:59 -0800671TEST_F(LatchUnsignaledDisabledTest, Flush_KeepsInTheQueueSameLayerId) {
672 const sp<IBinder> kApplyToken =
673 IInterface::asBinder(TransactionCompletedListener::getIInstance());
674 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800675 const auto kExpectedTransactionsPending = 1u;
676
677 const auto unsignaledTransaction =
678 createTransactionInfo(kApplyToken,
679 {
680 createComposerState(kLayerId,
681 fence(Fence::Status::Unsignaled),
682 layer_state_t::eBufferChanged),
683 createComposerState(kLayerId,
684 fence(Fence::Status::Unsignaled),
685 layer_state_t::eBufferChanged),
686 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700687 setTransactionStates({unsignaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000688}
689
Ady Abraham9dada822022-02-03 10:26:59 -0800690TEST_F(LatchUnsignaledDisabledTest, Flush_KeepsInTheQueueDifferentLayerId) {
691 const sp<IBinder> kApplyToken =
692 IInterface::asBinder(TransactionCompletedListener::getIInstance());
693 const auto kLayerId1 = 1;
694 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800695 const auto kExpectedTransactionsPending = 1u;
696
697 const auto unsignaledTransaction =
698 createTransactionInfo(kApplyToken,
699 {
700 createComposerState(kLayerId1,
701 fence(Fence::Status::Unsignaled),
702 layer_state_t::eBufferChanged),
703 createComposerState(kLayerId2,
704 fence(Fence::Status::Unsignaled),
705 layer_state_t::eBufferChanged),
706 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700707 setTransactionStates({unsignaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000708}
709
Ady Abraham9dada822022-02-03 10:26:59 -0800710TEST_F(LatchUnsignaledDisabledTest, Flush_RemovesSignaledFromTheQueue_MultipleLayers) {
711 const sp<IBinder> kApplyToken =
712 IInterface::asBinder(TransactionCompletedListener::getIInstance());
713 const auto kLayerId1 = 1;
714 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800715 const auto kExpectedTransactionsPending = 0u;
716
717 const auto signaledTransaction =
718 createTransactionInfo(kApplyToken,
719 {
720 createComposerState(kLayerId1,
721 fence(Fence::Status::Signaled),
722 layer_state_t::eBufferChanged),
723 });
724 const auto signaledTransaction2 =
725 createTransactionInfo(kApplyToken,
726 {
727 createComposerState(kLayerId2,
728 fence(Fence::Status::Signaled),
729 layer_state_t::eBufferChanged),
730 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700731 setTransactionStates({signaledTransaction, signaledTransaction2}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000732}
733
Ady Abraham9dada822022-02-03 10:26:59 -0800734TEST_F(LatchUnsignaledDisabledTest, Flush_KeepInTheQueueDifferentApplyToken) {
735 const sp<IBinder> kApplyToken1 =
736 IInterface::asBinder(TransactionCompletedListener::getIInstance());
737 const sp<IBinder> kApplyToken2 = sp<BBinder>::make();
738 const auto kLayerId1 = 1;
739 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800740 const auto kExpectedTransactionsPending = 1u;
741
742 const auto unsignaledTransaction =
743 createTransactionInfo(kApplyToken1,
744 {
745 createComposerState(kLayerId1,
746 fence(Fence::Status::Unsignaled),
747 layer_state_t::eBufferChanged),
748 });
749 const auto signaledTransaction =
750 createTransactionInfo(kApplyToken2,
751 {
752 createComposerState(kLayerId2,
753 fence(Fence::Status::Signaled),
754 layer_state_t::eBufferChanged),
755 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700756 setTransactionStates({unsignaledTransaction, signaledTransaction},
Ady Abraham9dada822022-02-03 10:26:59 -0800757 kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000758}
759
Ady Abraham9dada822022-02-03 10:26:59 -0800760TEST_F(LatchUnsignaledDisabledTest, Flush_KeepInTheQueueSameApplyToken) {
761 const sp<IBinder> kApplyToken =
762 IInterface::asBinder(TransactionCompletedListener::getIInstance());
763 const auto kLayerId1 = 1;
764 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800765 const auto kExpectedTransactionsPending = 1u;
766
767 const auto signaledTransaction =
768 createTransactionInfo(kApplyToken,
769 {
770 createComposerState(kLayerId1,
771 fence(Fence::Status::Signaled),
772 layer_state_t::eBufferChanged),
773 });
774 const auto unsignaledTransaction =
775 createTransactionInfo(kApplyToken,
776 {
777 createComposerState(kLayerId2,
778 fence(Fence::Status::Unsignaled),
779 layer_state_t::eBufferChanged),
780 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700781 setTransactionStates({signaledTransaction, unsignaledTransaction},
Ady Abraham9dada822022-02-03 10:26:59 -0800782 kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000783}
784
Ady Abraham9dada822022-02-03 10:26:59 -0800785TEST_F(LatchUnsignaledDisabledTest, Flush_KeepInTheUnsignaledTheQueue) {
786 const sp<IBinder> kApplyToken =
787 IInterface::asBinder(TransactionCompletedListener::getIInstance());
788 const auto kLayerId1 = 1;
789 const auto kLayerId2 = 2;
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700790 const auto kExpectedTransactionsPending = 2u;
Ady Abraham9dada822022-02-03 10:26:59 -0800791
792 const auto unsignaledTransaction =
793 createTransactionInfo(kApplyToken,
794 {
795 createComposerState(kLayerId1,
796 fence(Fence::Status::Unsignaled),
797 layer_state_t::eBufferChanged),
798 });
799 const auto unsignaledTransaction2 =
800 createTransactionInfo(kApplyToken,
801 {
802 createComposerState(kLayerId2,
803 fence(Fence::Status::Unsignaled),
804 layer_state_t::eBufferChanged),
805 });
806 setTransactionStates({unsignaledTransaction, unsignaledTransaction2},
Vishnu Nair1523dad2022-09-29 16:05:18 -0700807 kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000808}
809
Ady Abraham9dada822022-02-03 10:26:59 -0800810class LatchUnsignaledAlwaysTest : public LatchUnsignaledTest {
811public:
812 void SetUp() override {
813 LatchUnsignaledTest::SetUp();
814 SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Always;
815 }
816};
817
818TEST_F(LatchUnsignaledAlwaysTest, Flush_RemovesSignaledFromTheQueue) {
819 const sp<IBinder> kApplyToken =
820 IInterface::asBinder(TransactionCompletedListener::getIInstance());
821 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800822 const auto kExpectedTransactionsPending = 0u;
823
824 const auto signaledTransaction =
825 createTransactionInfo(kApplyToken,
826 {createComposerState(kLayerId, fence(Fence::Status::Signaled),
827 layer_state_t::eBufferChanged)});
Vishnu Nair1523dad2022-09-29 16:05:18 -0700828 setTransactionStates({signaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000829}
830
Ady Abraham9dada822022-02-03 10:26:59 -0800831TEST_F(LatchUnsignaledAlwaysTest, Flush_RemovesFromTheQueue) {
832 const sp<IBinder> kApplyToken =
833 IInterface::asBinder(TransactionCompletedListener::getIInstance());
834 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800835 const auto kExpectedTransactionsPending = 0u;
836
837 const auto unsignaledTransaction =
838 createTransactionInfo(kApplyToken,
839 {createComposerState(kLayerId, fence(Fence::Status::Unsignaled),
840 layer_state_t::eBufferChanged)});
Vishnu Nair1523dad2022-09-29 16:05:18 -0700841 setTransactionStates({unsignaledTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000842}
843
Ady Abraham9dada822022-02-03 10:26:59 -0800844TEST_F(LatchUnsignaledAlwaysTest, Flush_RemovesFromTheQueueSameLayerId) {
845 const sp<IBinder> kApplyToken =
846 IInterface::asBinder(TransactionCompletedListener::getIInstance());
847 const auto kLayerId = 1;
Ady Abraham9dada822022-02-03 10:26:59 -0800848 const auto kExpectedTransactionsPending = 0u;
849
850 const auto mixedTransaction =
851 createTransactionInfo(kApplyToken,
852 {createComposerState(kLayerId, fence(Fence::Status::Unsignaled),
853 layer_state_t::eBufferChanged),
854 createComposerState(kLayerId, fence(Fence::Status::Signaled),
855 layer_state_t::eBufferChanged)});
Vishnu Nair1523dad2022-09-29 16:05:18 -0700856 setTransactionStates({mixedTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000857}
858
Ady Abraham9dada822022-02-03 10:26:59 -0800859TEST_F(LatchUnsignaledAlwaysTest, Flush_RemovesFromTheQueueDifferentLayerId) {
860 const sp<IBinder> kApplyToken =
861 IInterface::asBinder(TransactionCompletedListener::getIInstance());
862 const auto kLayerId1 = 1;
863 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800864 const auto kExpectedTransactionsPending = 0u;
865
866 const auto mixedTransaction =
867 createTransactionInfo(kApplyToken,
868 {createComposerState(kLayerId1, fence(Fence::Status::Unsignaled),
869 layer_state_t::eBufferChanged),
870 createComposerState(kLayerId2, fence(Fence::Status::Signaled),
871 layer_state_t::eBufferChanged)});
Vishnu Nair1523dad2022-09-29 16:05:18 -0700872 setTransactionStates({mixedTransaction}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000873}
874
Ady Abraham9dada822022-02-03 10:26:59 -0800875TEST_F(LatchUnsignaledAlwaysTest, Flush_RemovesSignaledFromTheQueue_MultipleLayers) {
876 const sp<IBinder> kApplyToken =
877 IInterface::asBinder(TransactionCompletedListener::getIInstance());
878 const auto kLayerId1 = 1;
879 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800880 const auto kExpectedTransactionsPending = 0u;
881
882 const auto signaledTransaction =
883 createTransactionInfo(kApplyToken,
884 {
885 createComposerState(kLayerId1,
886 fence(Fence::Status::Signaled),
887 layer_state_t::eBufferChanged),
888 });
889 const auto signaledTransaction2 =
890 createTransactionInfo(kApplyToken,
891 {
892 createComposerState(kLayerId2,
893 fence(Fence::Status::Signaled),
894 layer_state_t::eBufferChanged),
895 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700896 setTransactionStates({signaledTransaction, signaledTransaction2}, kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000897}
898
Ady Abraham9dada822022-02-03 10:26:59 -0800899TEST_F(LatchUnsignaledAlwaysTest, Flush_RemovesFromTheQueueDifferentApplyToken) {
900 const sp<IBinder> kApplyToken1 =
901 IInterface::asBinder(TransactionCompletedListener::getIInstance());
902 const sp<IBinder> kApplyToken2 = sp<BBinder>::make();
903 const auto kLayerId1 = 1;
904 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800905 const auto kExpectedTransactionsPending = 0u;
906
907 const auto signaledTransaction =
908 createTransactionInfo(kApplyToken1,
909 {
910 createComposerState(kLayerId1,
911 fence(Fence::Status::Signaled),
912 layer_state_t::eBufferChanged),
913 });
914 const auto unsignaledTransaction =
915 createTransactionInfo(kApplyToken2,
916 {
917 createComposerState(kLayerId2,
918 fence(Fence::Status::Unsignaled),
919 layer_state_t::eBufferChanged),
920 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700921 setTransactionStates({signaledTransaction, unsignaledTransaction},
Ady Abraham9dada822022-02-03 10:26:59 -0800922 kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000923}
924
Ady Abraham9dada822022-02-03 10:26:59 -0800925TEST_F(LatchUnsignaledAlwaysTest, Flush_RemovesUnsignaledFromTheQueueSameApplyToken) {
926 const sp<IBinder> kApplyToken =
927 IInterface::asBinder(TransactionCompletedListener::getIInstance());
928 const auto kLayerId1 = 1;
929 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800930 const auto kExpectedTransactionsPending = 0u;
931
932 const auto unsignaledTransaction =
933 createTransactionInfo(kApplyToken,
934 {
935 createComposerState(kLayerId1,
936 fence(Fence::Status::Unsignaled),
937 layer_state_t::eBufferChanged),
938 });
939 const auto signaledTransaction =
940 createTransactionInfo(kApplyToken,
941 {
942 createComposerState(kLayerId2,
943 fence(Fence::Status::Signaled),
944 layer_state_t::eBufferChanged),
945 });
Vishnu Nair1523dad2022-09-29 16:05:18 -0700946 setTransactionStates({unsignaledTransaction, signaledTransaction},
Ady Abraham9dada822022-02-03 10:26:59 -0800947 kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000948}
949
Ady Abraham9dada822022-02-03 10:26:59 -0800950TEST_F(LatchUnsignaledAlwaysTest, Flush_RemovesUnsignaledFromTheQueue) {
951 const sp<IBinder> kApplyToken1 =
952 IInterface::asBinder(TransactionCompletedListener::getIInstance());
953 const sp<IBinder> kApplyToken2 = sp<BBinder>::make();
954 const auto kLayerId1 = 1;
955 const auto kLayerId2 = 2;
Ady Abraham9dada822022-02-03 10:26:59 -0800956 const auto kExpectedTransactionsPending = 0u;
957
958 const auto unsignaledTransaction =
959 createTransactionInfo(kApplyToken1,
960 {
961 createComposerState(kLayerId1,
962 fence(Fence::Status::Unsignaled),
963 layer_state_t::eBufferChanged),
964 });
965 const auto unsignaledTransaction2 =
966 createTransactionInfo(kApplyToken2,
967 {
968 createComposerState(kLayerId2,
969 fence(Fence::Status::Unsignaled),
970 layer_state_t::eBufferChanged),
971 });
972 setTransactionStates({unsignaledTransaction, unsignaledTransaction2},
Vishnu Nair1523dad2022-09-29 16:05:18 -0700973 kExpectedTransactionsPending);
ramindani4d48f902021-09-20 21:07:45 +0000974}
975
Ady Abraham2739e832022-02-14 17:42:00 -0800976TEST_F(LatchUnsignaledAlwaysTest, LatchUnsignaledWhenEarlyOffset) {
977 const sp<IBinder> kApplyToken =
978 IInterface::asBinder(TransactionCompletedListener::getIInstance());
979 const auto kLayerId = 1;
Ady Abraham2739e832022-02-14 17:42:00 -0800980 const auto kExpectedTransactionsPending = 0u;
981
982 const auto unsignaledTransaction =
983 createTransactionInfo(kApplyToken,
984 {
985 createComposerState(kLayerId,
986 fence(Fence::Status::Unsignaled),
987 layer_state_t::eBufferChanged),
988 });
989
Dominik Laskowski1c99a002023-01-20 17:10:36 -0500990 modulateVsync();
Vishnu Nair1523dad2022-09-29 16:05:18 -0700991 setTransactionStates({unsignaledTransaction}, kExpectedTransactionsPending);
Ady Abraham2739e832022-02-14 17:42:00 -0800992}
993
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700994TEST(TransactionHandlerTest, QueueTransaction) {
995 TransactionHandler handler;
996 TransactionState transaction;
997 transaction.applyToken = sp<BBinder>::make();
998 transaction.id = 42;
999 handler.queueTransaction(std::move(transaction));
1000 std::vector<TransactionState> transactionsReadyToBeApplied = handler.flushTransactions();
1001
1002 EXPECT_EQ(transactionsReadyToBeApplied.size(), 1u);
1003 EXPECT_EQ(transactionsReadyToBeApplied.front().id, 42u);
1004}
1005
Valerie Haud251afb2019-03-29 14:19:02 -07001006} // namespace android