Fix off by one error in log tracking

bug:8875715

Additionally moves op logging before the op is executed, to print
correctly, in pre-order traversal

Change-Id: I4e9566261f8363c73739d183e6d82b854f72ffad
diff --git a/libs/hwui/DeferredDisplayList.cpp b/libs/hwui/DeferredDisplayList.cpp
index f0084f2..9323a3a 100644
--- a/libs/hwui/DeferredDisplayList.cpp
+++ b/libs/hwui/DeferredDisplayList.cpp
@@ -98,8 +98,8 @@
 #if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
             renderer.eventMark(op->name());
 #endif
-            status |= op->applyDraw(renderer, dirty);
             logBuffer.writeCommand(0, op->name());
+            status |= op->applyDraw(renderer, dirty);
 
 #if DEBUG_MERGE_BEHAVIOR
             Rect& bounds = mOps[i]->state.mBounds;
@@ -200,10 +200,10 @@
         }
 
         DrawOp* op = mOps[0];
-        status_t status = op->multiDraw(renderer, dirty, mOps, mBounds);
         DisplayListLogBuffer& buffer = DisplayListLogBuffer::getInstance();
         buffer.writeCommand(0, "multiDraw");
         buffer.writeCommand(1, op->name());
+        status_t status = op->multiDraw(renderer, dirty, mOps, mBounds);
 
 #if DEBUG_MERGE_BEHAVIOR
         renderer.drawScreenSpaceColorRect(mBounds.left, mBounds.top, mBounds.right, mBounds.bottom,
diff --git a/libs/hwui/DisplayList.cpp b/libs/hwui/DisplayList.cpp
index 3c58797..c11741c 100644
--- a/libs/hwui/DisplayList.cpp
+++ b/libs/hwui/DisplayList.cpp
@@ -511,8 +511,8 @@
     for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
         DisplayListOp *op = mDisplayListData->displayListOps[i];
 
-        handler(op, saveCount, mClipToBounds);
         logBuffer.writeCommand(level, op->name());
+        handler(op, saveCount, mClipToBounds);
     }
 
     DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo);
diff --git a/libs/hwui/DisplayListLogBuffer.cpp b/libs/hwui/DisplayListLogBuffer.cpp
index f039fcd..45aacca 100644
--- a/libs/hwui/DisplayListLogBuffer.cpp
+++ b/libs/hwui/DisplayListLogBuffer.cpp
@@ -77,12 +77,13 @@
         if (tmpBufferPtr == mEnd) {
             break;
         }
+
+        fprintf(file, "%*s%s\n", 2 * tmpBufferPtr->level, "", tmpBufferPtr->label);
+
         OpLog* nextOp = tmpBufferPtr++;
         if (tmpBufferPtr > mBufferLast) {
             tmpBufferPtr = mBufferFirst;
         }
-
-        fprintf(file, "%*s%s\n", tmpBufferPtr->level*2, "", tmpBufferPtr->label);
     }
 }