SurfaceFlinger: Emit TransactionCompleted callbacks directly.
Transaction complete callbacks (BLAST Buffer release callbacks), are
emitted from a TransactionCompletedThread. There's no clear reason
for this behavior, as the actual runtime is exceedingly minimal. This
opens us to scheduling delays when we call
TransactionCompletedThread.sendCallbacks. In this CL we both remove the
threaded nature of TransactionCompletedThread, and also take advantage
of it running on the main thread to reduce some unnecessary copying and
further reduce its runtime.
Bug: 176691195
Test: Existing tests pass
Change-Id: Ib1661df24c4a2ee39fc28c29a395158ce0ee7b7f
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index e9b5875..a131118 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2195,8 +2195,8 @@
}
});
- mTransactionCompletedThread.addPresentFence(mPreviousPresentFences[0]);
- mTransactionCompletedThread.sendCallbacks();
+ mTransactionCallbackInvoker.addPresentFence(mPreviousPresentFences[0]);
+ mTransactionCallbackInvoker.sendCallbacks();
if (display && display->isPrimary() && display->getPowerMode() == hal::PowerMode::ON &&
presentFenceTime->isValid()) {
@@ -3547,8 +3547,8 @@
// that listeners with SurfaceControls will start registration during setClientStateLocked
// below.
for (const auto& listener : listenerCallbacks) {
- mTransactionCompletedThread.startRegistration(listener);
- mTransactionCompletedThread.endRegistration(listener);
+ mTransactionCallbackInvoker.startRegistration(listener);
+ mTransactionCallbackInvoker.endRegistration(listener);
}
std::unordered_set<ListenerCallbacks, ListenerCallbacksHash> listenerCallbacksWithSurfaces;
@@ -3567,12 +3567,12 @@
}
for (const auto& listenerCallback : listenerCallbacksWithSurfaces) {
- mTransactionCompletedThread.endRegistration(listenerCallback);
+ mTransactionCallbackInvoker.endRegistration(listenerCallback);
}
// If the state doesn't require a traversal and there are callbacks, send them now
if (!(clientStateFlags & eTraversalNeeded) && hasListenerCallbacks) {
- mTransactionCompletedThread.sendCallbacks();
+ mTransactionCallbackInvoker.sendCallbacks();
}
transactionFlags |= clientStateFlags;
@@ -3687,7 +3687,7 @@
for (auto& listener : s.listeners) {
// note that startRegistration will not re-register if the listener has
// already be registered for a prior surface control
- mTransactionCompletedThread.startRegistration(listener);
+ mTransactionCallbackInvoker.startRegistration(listener);
listenerCallbacks.insert(listener);
}
@@ -3700,7 +3700,7 @@
}
if (layer == nullptr) {
for (auto& [listener, callbackIds] : s.listeners) {
- mTransactionCompletedThread.registerUnpresentedCallbackHandle(
+ mTransactionCallbackInvoker.registerUnpresentedCallbackHandle(
new CallbackHandle(listener, callbackIds, s.surface));
}
return 0;