Refactor surfacefinger latchBuffer: Create method

Shortens latchBuffer method, extracting transaction
credential verification to dedicated function.

Test: On device
Change-Id: Ia7c2f977a85d1c1afd87425588c07eb756b00f15
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 8da5202..a3c1734 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -1787,6 +1787,32 @@
 #endif
 }
 
+bool Layer::allTransactionsSignaled() {
+    auto headFrameNumber = getHeadFrameNumber();
+    bool matchingFramesFound = false;
+    bool allTransactionsApplied = true;
+    Mutex::Autolock lock(mLocalSyncPointMutex);
+
+    for (auto& point : mLocalSyncPoints) {
+        if (point->getFrameNumber() > headFrameNumber) {
+            break;
+        }
+        matchingFramesFound = true;
+
+        if (!point->frameIsAvailable()) {
+           // We haven't notified the remote layer that the frame for
+           // this point is available yet. Notify it now, and then
+           // abort this attempt to latch.
+           point->setFrameAvailable();
+           allTransactionsApplied = false;
+           break;
+        }
+
+        allTransactionsApplied = allTransactionsApplied && point->transactionIsApplied();
+    }
+    return !matchingFramesFound || allTransactionsApplied;
+}
+
 Region Layer::latchBuffer(bool& recomputeVisibleRegions)
 {
     ATRACE_CALL();
@@ -1830,36 +1856,7 @@
     const bool oldOpacity = isOpaque(s);
     sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer;
 
-    // Check all of our local sync points to ensure that all transactions
-    // which need to have been applied prior to the frame which is about to
-    // be latched have signaled
-
-    auto headFrameNumber = getHeadFrameNumber();
-    bool matchingFramesFound = false;
-    bool allTransactionsApplied = true;
-    {
-        Mutex::Autolock lock(mLocalSyncPointMutex);
-        for (auto& point : mLocalSyncPoints) {
-            if (point->getFrameNumber() > headFrameNumber) {
-                break;
-            }
-
-            matchingFramesFound = true;
-
-            if (!point->frameIsAvailable()) {
-                // We haven't notified the remote layer that the frame for
-                // this point is available yet. Notify it now, and then
-                // abort this attempt to latch.
-                point->setFrameAvailable();
-                allTransactionsApplied = false;
-                break;
-            }
-
-            allTransactionsApplied &= point->transactionIsApplied();
-        }
-    }
-
-    if (matchingFramesFound && !allTransactionsApplied) {
+    if (!allTransactionsSignaled()) {
         mFlinger->signalLayerUpdate();
         return outDirtyRegion;
     }
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index efb0fb8..64b049c 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -558,6 +558,11 @@
 
     // -----------------------------------------------------------------------
 
+    // Check all of the local sync points to ensure that all transactions
+    // which need to have been applied prior to the frame which is about to
+    // be latched have signaled
+    bool allTransactionsSignaled();
+
     // constants
     sp<SurfaceFlingerConsumer> mSurfaceFlingerConsumer;
     sp<IGraphicBufferProducer> mProducer;