blast: fix 30 hz with desiredPresentTime

When a transaction is applied on the main thread, first the transaction
is applied and then handleTransaction is called. If we realize a
transaction requires a traversal when we are applying it, handleTransaction
will do a traversal. Since handleTransaction will preform the traversal,
there is no need to schedule a wake up for the next frame to preform
an unneeded traversal.

Bug: 128520233
Test: run chrome video and look at the systrace.
Change-Id: Idf9dda8ddfdf88b34abe5a3fe648ef693998b9a0
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index f7e4afd..fae4b81 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -280,6 +280,7 @@
         mFactory(factory),
         mTransactionPending(false),
         mAnimTransactionPending(false),
+        mTraversalNeededMainThread(false),
         mLayersRemoved(false),
         mLayersAdded(false),
         mBootTime(systemTime()),
@@ -2782,7 +2783,7 @@
      * (perform the transaction for each of them if needed)
      */
 
-    if (transactionFlags & eTraversalNeeded) {
+    if ((transactionFlags & eTraversalNeeded) || mTraversalNeededMainThread) {
         mCurrentState.traverseInZOrder([&](Layer* layer) {
             uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded);
             if (!trFlags) return;
@@ -2795,6 +2796,7 @@
                 mInputInfoChanged = true;
             }
         });
+        mTraversalNeededMainThread = false;
     }
 
     /*
@@ -3682,6 +3684,13 @@
         transactionFlags = eTransactionNeeded;
     }
 
+    // If we are on the main thread, we are about to preform a traversal. Clear the traversal bit
+    // so we don't have to wake up again next frame to preform an uneeded traversal.
+    if (isMainThread && (transactionFlags & eTraversalNeeded)) {
+        transactionFlags = transactionFlags & (~eTraversalNeeded);
+        mTraversalNeededMainThread = true;
+    }
+
     if (transactionFlags) {
         if (mInterceptor->isEnabled()) {
             mInterceptor->saveTransaction(states, mCurrentState.displays, displays, flags);