Add GrOpList and rename GrDrawTarget to GrRenderTargetOpList

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3910

Change-Id: I026aa26ecc61a0d002e98892dca728536259e8b1
Reviewed-on: https://skia-review.googlesource.com/3910
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h
index 72de15d..6e9056d 100644
--- a/include/gpu/GrDrawContext.h
+++ b/include/gpu/GrDrawContext.h
@@ -24,12 +24,12 @@
 class GrDrawContextPriv;
 class GrDrawPathBatchBase;
 class GrDrawingManager;
-class GrDrawTarget;
 class GrFixedClip;
 class GrPaint;
 class GrPathProcessor;
 class GrPipelineBuilder;
 class GrRenderTarget;
+class GrRenderTargetOpList;
 class GrStyle;
 class GrSurface;
 struct GrUserStencilSettings;
@@ -366,7 +366,7 @@
 
     friend class GrDrawingManager; // for ctor
     friend class GrDrawContextPriv;
-    friend class GrTestTarget;  // for access to getDrawTarget
+    friend class GrTestTarget;  // for access to getOpList
     friend class GrSWMaskHelper;                 // for access to drawBatch
 
     // All the path renderers currently make their own batches
@@ -412,17 +412,17 @@
                           const GrStyle& style);
 
     // This entry point allows the GrTextContext-derived classes to add their batches to
-    // the drawTarget.
+    // the GrOpList.
     void drawBatch(const GrPipelineBuilder& pipelineBuilder, const GrClip&, GrDrawBatch* batch);
 
-    GrDrawTarget* getDrawTarget();
+    GrRenderTargetOpList* getOpList();
 
     GrDrawingManager*                 fDrawingManager;
     sk_sp<GrRenderTarget>             fRenderTarget;
 
-    // In MDB-mode the drawTarget can be closed by some other drawContext that has picked
-    // it up. For this reason, the drawTarget should only ever be accessed via 'getDrawTarget'.
-    GrDrawTarget*                     fDrawTarget;
+    // In MDB-mode the GrOpList can be closed by some other drawContext that has picked
+    // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
+    GrRenderTargetOpList*             fOpList;
     GrContext*                        fContext;
     GrInstancedPipelineInfo           fInstancedPipelineInfo;
 
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h
index 364a886..d3cfa86 100644
--- a/include/gpu/GrGpuResource.h
+++ b/include/gpu/GrGpuResource.h
@@ -23,7 +23,7 @@
  *
  * Gpu resources can have three types of refs:
  *   1) Normal ref (+ by ref(), - by unref()): These are used by code that is issuing draw calls
- *      that read and write the resource via GrDrawTarget and by any object that must own a
+ *      that read and write the resource via GrOpList and by any object that must own a
  *      GrGpuResource and is itself owned (directly or indirectly) by Skia-client code.
  *   2) Pending read (+ by addPendingRead(), - by completedRead()): GrContext has scheduled a read
  *      of the resource by the GPU as a result of a skia API call but hasn't executed it yet.
diff --git a/include/gpu/GrGpuResourceRef.h b/include/gpu/GrGpuResourceRef.h
index 4511adc..13adbee 100644
--- a/include/gpu/GrGpuResourceRef.h
+++ b/include/gpu/GrGpuResourceRef.h
@@ -63,7 +63,7 @@
         execution. It can only be called once. */
     void markPendingIO() const;
 
-    /** Called when the program element/draw state is no longer owned by GrDrawTarget-client code.
+    /** Called when the program element/draw state is no longer owned by GrOpList-client code.
         This lets the cache know that the drawing code will no longer schedule additional reads or
         writes to the resource using the program element or draw state. It can only be called once.
       */
diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h
index 1f87787..445846f 100644
--- a/include/gpu/GrRenderTarget.h
+++ b/include/gpu/GrRenderTarget.h
@@ -12,9 +12,9 @@
 #include "SkRect.h"
 
 class GrCaps;
-class GrDrawTarget;
-class GrStencilAttachment;
+class GrRenderTargetOpList;
 class GrRenderTargetPriv;
+class GrStencilAttachment;
 
 /**
  * GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
@@ -115,8 +115,9 @@
     GrRenderTargetPriv renderTargetPriv();
     const GrRenderTargetPriv renderTargetPriv() const;
 
-    void setLastDrawTarget(GrDrawTarget* dt);
-    GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; }
+    GrRenderTargetOpList* getLastRenderTargetOpList() {
+        return (GrRenderTargetOpList*) this->getLastOpList();
+    }
 
 protected:
     enum class Flags {
@@ -129,7 +130,6 @@
 
     GrRenderTarget(GrGpu*, const GrSurfaceDesc&, Flags = Flags::kNone,
                    GrStencilAttachment* = nullptr);
-    ~GrRenderTarget() override;
 
     // override of GrResource
     void onAbandon() override;
@@ -150,14 +150,6 @@
 
     SkIRect               fResolveRect;
 
-    // The last drawTarget that wrote to or is currently going to write to this renderTarget
-    // The drawTarget can be closed (e.g., no draw context is currently bound
-    // to this renderTarget).
-    // This back-pointer is required so that we can add a dependancy between
-    // the drawTarget used to create the current contents of this renderTarget
-    // and the drawTarget of a destination renderTarget to which this one is being drawn.
-    GrDrawTarget* fLastDrawTarget;
-
     typedef GrSurface INHERITED;
 };
 
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index ac5c5fa..0ac4bf3 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -14,6 +14,7 @@
 #include "SkImageInfo.h"
 #include "SkRect.h"
 
+class GrOpList;
 class GrRenderTarget;
 class GrSurfacePriv;
 class GrTexture;
@@ -127,6 +128,9 @@
 
     static size_t WorstCaseSize(const GrSurfaceDesc& desc);
 
+    void setLastOpList(GrOpList* opList);
+    GrOpList* getLastOpList() { return fLastOpList; }
+
 protected:
     // Methods made available via GrSurfacePriv
     bool savePixels(const char* filename);
@@ -142,12 +146,9 @@
         , fDesc(desc)
         , fReleaseProc(NULL)
         , fReleaseCtx(NULL)
-    {}
-
-    ~GrSurface() override {
-        // check that invokeReleaseProc has been called (if needed)
-        SkASSERT(NULL == fReleaseProc);
+        , fLastOpList(nullptr) {
     }
+    ~GrSurface() override;
 
     GrSurfaceDesc fDesc;
 
@@ -165,6 +166,14 @@
     ReleaseProc fReleaseProc;
     ReleaseCtx  fReleaseCtx;
 
+    // The last opList that wrote to or is currently going to write to this surface
+    // The opList can be closed (e.g., no draw or copy context is currently bound
+    // to this renderTarget or texture).
+    // This back-pointer is required so that we can add a dependancy between
+    // the opList used to create the current contents of this surface
+    // and the opList of a destination surface to which this one is being drawn or copied.
+    GrOpList* fLastOpList;
+
     typedef GrGpuResource INHERITED;
 };
 
diff --git a/include/private/GrRenderTargetProxy.h b/include/private/GrRenderTargetProxy.h
index e4bc70f..59fed59 100644
--- a/include/private/GrRenderTargetProxy.h
+++ b/include/private/GrRenderTargetProxy.h
@@ -28,8 +28,6 @@
                                            SkBackingFit, SkBudgeted);
     static sk_sp<GrRenderTargetProxy> Make(const GrCaps&, sk_sp<GrRenderTarget>);
 
-    ~GrRenderTargetProxy() override;
-
     // TODO: add asTextureProxy variants
     GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
     const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
@@ -60,9 +58,6 @@
      */
     int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; }
 
-    void setLastDrawTarget(GrDrawTarget* dt);
-    GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; }
-
     GrRenderTargetPriv::Flags testingOnly_getFlags() const;
 
 private:
@@ -83,14 +78,6 @@
     // rendertarget's info here.
     GrRenderTargetPriv::Flags   fFlags;
 
-    // The last drawTarget that wrote to or is currently going to write to this renderTarget
-    // The drawTarget can be closed (e.g., no draw context is currently bound
-    // to this renderTarget).
-    // This back-pointer is required so that we can add a dependancy between
-    // the drawTarget used to create the current contents of this renderTarget
-    // and the drawTarget of a destination renderTarget to which this one is being drawn.
-    GrDrawTarget* fLastDrawTarget;
-
     typedef GrSurfaceProxy INHERITED;
 };
 
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index 69656fe..4e2ad3b 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -11,6 +11,7 @@
 #include "GrGpuResource.h"
 #include "SkRect.h"
 
+class GrOpList;
 class GrTextureProxy;
 class GrRenderTargetProxy;
 
@@ -51,13 +52,17 @@
      */
     SkBudgeted isBudgeted() const { return fBudgeted; }
 
+    void setLastOpList(GrOpList* opList);
+    GrOpList* getLastOpList() { return fLastOpList; }
+
 protected:
     // Deferred version
     GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted)
         : fDesc(desc)
         , fFit(fit)
         , fBudgeted(budgeted)
-        , fUniqueID(GrGpuResource::CreateUniqueID()) {
+        , fUniqueID(GrGpuResource::CreateUniqueID())
+        , fLastOpList(nullptr) {
     }
 
     // Wrapped version
@@ -66,10 +71,12 @@
         : fDesc(desc)
         , fFit(fit)
         , fBudgeted(budgeted)
-        , fUniqueID(uniqueID) {
+        , fUniqueID(uniqueID)
+        , fLastOpList(nullptr) {
     }
 
-    virtual ~GrSurfaceProxy() {}
+    virtual ~GrSurfaceProxy();
+
 
     // For wrapped resources, 'fDesc' will always be filled in from the wrapped resource.
     const GrSurfaceDesc fDesc;
@@ -83,6 +90,14 @@
     void notifyAllCntsAreZero(CntType) const { delete this; }
     bool notifyRefCountIsZero() const { return true; }
 
+    // The last opList that wrote to or is currently going to write to this surface
+    // The opList can be closed (e.g., no draw context is currently bound
+    // to this renderTarget).
+    // This back-pointer is required so that we can add a dependancy between
+    // the opList used to create the current contents of this surface
+    // and the opList of a destination surface to which this one is being drawn or copied.
+    GrOpList* fLastOpList;
+
     typedef GrIORef<GrSurfaceProxy> INHERITED;
 
     // to access notifyAllCntsAreZero and notifyRefCntIsZero.