SurfaceView: Ensure we don't fill unused BLAST Transaction.

If BLAST is enabled and we somehow end up in positionLost or
setParentSpaceRectangle without having called setUseBLASTSyncTransaction
we will end up putting operations in to a Transaction which will never be
applied. This condition should be considered a bug, but it's best to
defend against it. To compensate, rather than checking the global
use BLAST flag, we check if the current draw is actually using
BLAST.

Bug: 152663327
Bug: 152780239
Test: Existing tests pass
Change-Id: I3c05b83400b59be82a339933fc8ef1382d4f0e21
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index c89e0c9..b098173 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -1241,7 +1241,7 @@
     private void applySurfaceTransforms(SurfaceControl surface, SurfaceControl.Transaction t,
             Rect position, long frameNumber) {
         final ViewRootImpl viewRoot = getViewRootImpl();
-        if (frameNumber > 0 && viewRoot != null && !viewRoot.useBLAST()) {
+        if (frameNumber > 0 && viewRoot != null && !viewRoot.isDrawingToBLASTTransaction()) {
             t.deferTransactionUntil(surface, viewRoot.getRenderSurfaceControl(),
                     frameNumber);
         }
@@ -1258,7 +1258,7 @@
 
     private void setParentSpaceRectangle(Rect position, long frameNumber) {
         final ViewRootImpl viewRoot = getViewRootImpl();
-        final boolean useBLAST = viewRoot.useBLAST();
+        final boolean useBLAST = viewRoot.isDrawingToBLASTTransaction();
         final SurfaceControl.Transaction t = useBLAST ? viewRoot.getBLASTSyncTransaction() :
             mRtTransaction;
 
@@ -1319,7 +1319,7 @@
         @Override
         public void positionLost(long frameNumber) {
             final ViewRootImpl viewRoot = getViewRootImpl();
-            boolean useBLAST = viewRoot != null && viewRoot.useBLAST();
+            boolean useBLAST = viewRoot != null && viewRoot.isDrawingToBLASTTransaction();
             if (DEBUG) {
                 Log.d(TAG, String.format("%d windowPositionLost, frameNr = %d",
                         System.identityHashCode(this), frameNumber));
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 35f955f..95e0f94 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -9595,4 +9595,12 @@
     boolean useBLAST() {
         return mUseBLASTAdapter;
     }
+
+    /**
+     * Returns true if we are about to or currently processing a draw directed
+     * in to a BLAST transaction.
+     */
+    boolean isDrawingToBLASTTransaction() {
+        return mNextReportConsumeBLAST;
+    }
 }