SurfaceComposerClient: Expose default apply token
The default apply token specifies which transaction queue transactions
from a process is sent to in surfaceflinger. This queue is used to
ensure transactions from a process are applied in order.
If a transaction from multiple processes need to be applied in order,
we can use a commit callback to act as a barrier or pass transactions
across processes to be applied on a single process. In some cases
where operations are intertwined it may be advantageous to set a
single transaction queue for multiple processes. In this case
this api can be used to set a single queue to apply transactions by
setting the same apply token on both processes.
Note this api if misused can result in surprising out of order
transactions.
Test: manually set the same applytoken on multiple processes and
verify they go into the same queue.
Bug: 242193885
Bug: 242193885
Change-Id: I106fa701cc844d675e2ff2a05b5edcfed8cf85ff
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index d16ddb9..e7c1d7f 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -1038,9 +1038,7 @@
flags |= ISurfaceComposer::eEarlyWakeupEnd;
}
- sp<IBinder> applyToken = mApplyToken
- ? mApplyToken
- : IInterface::asBinder(TransactionCompletedListener::getIInstance());
+ sp<IBinder> applyToken = mApplyToken ? mApplyToken : sApplyToken;
sf->setTransactionState(mFrameTimelineInfo, composerStates, displayStates, flags, applyToken,
mInputWindowCommands, mDesiredPresentTime, mIsAutoTimestamp,
@@ -1055,6 +1053,15 @@
return NO_ERROR;
}
+sp<IBinder> SurfaceComposerClient::Transaction::sApplyToken = new BBinder();
+
+sp<IBinder> SurfaceComposerClient::Transaction::getDefaultApplyToken() {
+ return sApplyToken;
+}
+
+void SurfaceComposerClient::Transaction::setDefaultApplyToken(sp<IBinder> applyToken) {
+ sApplyToken = applyToken;
+}
// ---------------------------------------------------------------------------
sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) {
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 20c38d8..ea62b7e 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -390,6 +390,7 @@
class Transaction : public Parcelable {
private:
+ static sp<IBinder> sApplyToken;
void releaseBufferIfOverwriting(const layer_state_t& state);
static void mergeFrameTimelineInfo(FrameTimelineInfo& t, const FrameTimelineInfo& other);
static void clearFrameTimelineInfo(FrameTimelineInfo& t);
@@ -669,6 +670,9 @@
* TODO (b/213644870): Remove all permissioned things from Transaction
*/
void sanitize();
+
+ static sp<IBinder> getDefaultApplyToken();
+ static void setDefaultApplyToken(sp<IBinder> applyToken);
};
status_t clearLayerFrameStats(const sp<IBinder>& token) const;