SF: Fix a race between layer creation and apply transaction
Between commitCreatedLayers and applyTransactions in the main
thread, the client could create a new layer and queue a transaction.
This will mean a layer transaction can be applied before the layer
can be committed.
Fix this by flushing the transactions to be applied before
committing any new layers.
Test: presubmit
Fixes: b/262336014
Change-Id: Id2848af4fbb7afe4e6a20a48f6a8a13f322e1cd7
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 5457be8..fa2a6f4 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -725,7 +725,11 @@
int originPid, int originUid, uint64_t transactionId)
REQUIRES(mStateLock);
// Flush pending transactions that were presented after desiredPresentTime.
+ // For test only
bool flushTransactionQueues(VsyncId) REQUIRES(kMainThreadContext);
+
+ bool applyTransactions(std::vector<TransactionState>&, VsyncId) REQUIRES(kMainThreadContext);
+
// Returns true if there is at least one transaction that needs to be flushed
bool transactionFlushNeeded();
void addTransactionReadyFilters();
@@ -756,7 +760,7 @@
static LatchUnsignaledConfig getLatchUnsignaledConfig();
bool shouldLatchUnsignaled(const sp<Layer>& layer, const layer_state_t&, size_t numStates,
bool firstTransaction) const;
- bool applyTransactions(std::vector<TransactionState>& transactions, VsyncId)
+ bool applyTransactionsLocked(std::vector<TransactionState>& transactions, VsyncId)
REQUIRES(mStateLock);
uint32_t setDisplayStateLocked(const DisplayState& s) REQUIRES(mStateLock);
uint32_t addInputWindowCommands(const InputWindowCommands& inputWindowCommands)