Add GrOp::wasRecorded and use in instanced rendering for tracking.

BUG=skia:

Change-Id: I4c5cdf47d42b7adae3649c7f96caabe68f45acbf
Reviewed-on: https://skia-review.googlesource.com/9308
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp
index 1826689..1c98353 100644
--- a/src/gpu/GrRenderTargetOpList.cpp
+++ b/src/gpu/GrRenderTargetOpList.cpp
@@ -274,6 +274,7 @@
     }
     GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op);
     fRecordedOps.emplace_back(std::move(op), renderTarget);
+    fRecordedOps.back().fOp->wasRecorded();
     fLastFullClearOp = nullptr;
     fLastFullClearRenderTargetID.makeInvalid();
     return fRecordedOps.back().fOp.get();
diff --git a/src/gpu/instanced/InstancedRendering.cpp b/src/gpu/instanced/InstancedRendering.cpp
index 1ffaaa4..ef2264b 100644
--- a/src/gpu/instanced/InstancedRendering.cpp
+++ b/src/gpu/instanced/InstancedRendering.cpp
@@ -369,7 +369,10 @@
     }
     fInfo.fUsesLocalCoords = optimizations.readsLocalCoords();
     fInfo.fCannotTweakAlphaForCoverage = !optimizations.canTweakAlphaForCoverage();
+}
 
+void InstancedRendering::Op::wasRecorded() {
+    SkASSERT(!fIsTracked);
     fInstancedRendering->fTrackedOps.addToTail(this);
     fIsTracked = true;
 }
diff --git a/src/gpu/instanced/InstancedRendering.h b/src/gpu/instanced/InstancedRendering.h
index 8002d50..778e8b4 100644
--- a/src/gpu/instanced/InstancedRendering.h
+++ b/src/gpu/instanced/InstancedRendering.h
@@ -141,6 +141,9 @@
         void appendParamsTexel(SkScalar x, SkScalar y, SkScalar z, SkScalar w);
         void appendParamsTexel(SkScalar x, SkScalar y, SkScalar z);
 
+        // Registers the op with the InstancedRendering list of tracked ops.
+        void wasRecorded() override;
+
     protected:
         Op(uint32_t classID, InstancedRendering* ir);
 
diff --git a/src/gpu/ops/GrOp.h b/src/gpu/ops/GrOp.h
index 11198dd..c1bf7f7 100644
--- a/src/gpu/ops/GrOp.h
+++ b/src/gpu/ops/GrOp.h
@@ -126,6 +126,14 @@
     }
 
     /**
+     * This is called to notify the op that it has been recorded into a GrOpList. Ops can use this
+     * to begin preparations for the flush of the op list. Note that the op still may either be
+     * combined into another op or have another op combined into it via combineIfPossible() after
+     * this call is made.
+     */
+    virtual void wasRecorded() {}
+
+    /**
      * Called prior to executing. The op should perform any resource creation or data transfers
      * necessary before execute() is called.
      */