summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Robert Carr <racarr@google.com> 2020-04-08 10:53:30 -0700
committer Robert Carr <racarr@google.com> 2020-04-08 10:54:00 -0700
commit158531d044690c52dfd1889e699a5f723df44b95 (patch)
tree4d4db53c263d16cb0be7c52c1b29fba61a5d47b6
parentbbc8562601d272343df7649f2561ad475f8639f0 (diff)
SurfaceComposerClient BLAST: cacheBuffers before writing transaction to parcel.
If we write the Transaction to a parcel, we want to ensure the Buffers are cached before crossing the IPC boundary. Otherwise the receiving party will cache the buffers but is unlikely to use them again as they are owned by the other process. You may be asking yourself, is this const cast safe? Const cast is safe up until the point where you try and write to an object that was originally const at which point we enter undefined behavior. In this case we are safe though, because there are two possibilities: 1. The SurfaceComposerClient::Transaction was originally non-const. Safe. 2. It was originall const! In this case not only was it useless, but it by definition contains no composer states and so cacheBuffers will not perform any writes. Bug: 153561718 Test: Existing tests pass. Manual test of BLAST Sync Engine. Change-Id: Ibb5425955f3d8c40f8c227d8911989dd76f8afe4
-rw-r--r--libs/gui/SurfaceComposerClient.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 8a7412e116..e89863f48b 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -430,6 +430,19 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel
}
status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const {
+ // If we write the Transaction to a parcel, we want to ensure the Buffers are cached
+ // before crossing the IPC boundary. Otherwise the receiving party will cache the buffers
+ // but is unlikely to use them again as they are owned by the other process.
+ // You may be asking yourself, is this const cast safe? Const cast is safe up
+ // until the point where you try and write to an object that was originally const at which
+ // point we enter undefined behavior. In this case we are safe though, because there are
+ // two possibilities:
+ // 1. The SurfaceComposerClient::Transaction was originally non-const. Safe.
+ // 2. It was originall const! In this case not only was it useless, but it by definition
+ // contains no composer states and so cacheBuffers will not perform any writes.
+
+ const_cast<SurfaceComposerClient::Transaction*>(this)->cacheBuffers();
+
parcel->writeUint32(mForceSynchronous);
parcel->writeUint32(mTransactionNestCount);
parcel->writeBool(mAnimation);