Update copyOp to split-opList world

Change-Id: Ib18fc0a589185b11b21241e50acb7b506c44bfac
Reviewed-on: https://skia-review.googlesource.com/17325
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 4e6dc35..c72c4d1 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -138,8 +138,8 @@
     SkDEBUGCODE(this->validate();)
     GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::onCopy");
 
-    return this->getOpList()->copySurface(fContext->resourceProvider(),
-                                          this, srcProxy, srcRect, dstPoint);
+    return this->getOpList()->copySurface(*this->caps(),
+                                          this->asSurfaceProxy(), srcProxy, srcRect, dstPoint);
 }
 
 void GrRenderTargetContext::drawText(const GrClip& clip, const SkPaint& skPaint,
diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp
index 5618bdc..f7aecdd 100644
--- a/src/gpu/GrRenderTargetOpList.cpp
+++ b/src/gpu/GrRenderTargetOpList.cpp
@@ -209,15 +209,13 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 // MDB TODO: fuse with GrTextureOpList::copySurface
-bool GrRenderTargetOpList::copySurface(GrResourceProvider* resourceProvider,
-                                       GrRenderTargetContext* dst,
+bool GrRenderTargetOpList::copySurface(const GrCaps& caps,
+                                       GrSurfaceProxy* dst,
                                        GrSurfaceProxy* src,
                                        const SkIRect& srcRect,
                                        const SkIPoint& dstPoint) {
     SkASSERT(dst->asRenderTargetProxy() == fTarget.get());
-
-    std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(resourceProvider, dst->asSurfaceProxy(),
-                                                     src, srcRect, dstPoint);
+    std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
     if (!op) {
         return false;
     }
@@ -225,7 +223,7 @@
     this->addDependency(src);
 #endif
 
-    this->recordOp(std::move(op), *resourceProvider->caps());
+    this->recordOp(std::move(op), caps);
     return true;
 }
 
diff --git a/src/gpu/GrRenderTargetOpList.h b/src/gpu/GrRenderTargetOpList.h
index 79dbd74..216ede4 100644
--- a/src/gpu/GrRenderTargetOpList.h
+++ b/src/gpu/GrRenderTargetOpList.h
@@ -88,8 +88,8 @@
      * depending on the type of surface, configs, etc, and the backend-specific
      * limitations.
      */
-    bool copySurface(GrResourceProvider* resourceProvider,
-                     GrRenderTargetContext* dst,
+    bool copySurface(const GrCaps& caps,
+                     GrSurfaceProxy* dst,
                      GrSurfaceProxy* src,
                      const SkIRect& srcRect,
                      const SkIPoint& dstPoint);
diff --git a/src/gpu/GrTextureContext.cpp b/src/gpu/GrTextureContext.cpp
index 0021c23..b4e76cb 100644
--- a/src/gpu/GrTextureContext.cpp
+++ b/src/gpu/GrTextureContext.cpp
@@ -77,7 +77,7 @@
     SkDEBUGCODE(this->validate();)
     GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::onCopy");
 
-    return this->getOpList()->copySurface(fContext->resourceProvider(),
+    return this->getOpList()->copySurface(*fContext->caps(),
                                           fTextureProxy.get(), srcProxy, srcRect, dstPoint);
 }
 
diff --git a/src/gpu/GrTextureOpList.cpp b/src/gpu/GrTextureOpList.cpp
index d15c778..3c127f6 100644
--- a/src/gpu/GrTextureOpList.cpp
+++ b/src/gpu/GrTextureOpList.cpp
@@ -78,12 +78,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 // MDB TODO: fuse with GrRenderTargetOpList::copySurface
-bool GrTextureOpList::copySurface(GrResourceProvider* resourceProvider,
+bool GrTextureOpList::copySurface(const GrCaps& caps,
                                   GrSurfaceProxy* dst,
                                   GrSurfaceProxy* src,
                                   const SkIRect& srcRect,
                                   const SkIPoint& dstPoint) {
-    std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(resourceProvider, dst, src, srcRect, dstPoint);
+    SkASSERT(dst == fTarget.get());
+
+    std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
     if (!op) {
         return false;
     }
diff --git a/src/gpu/GrTextureOpList.h b/src/gpu/GrTextureOpList.h
index 0cc138d..1ca45b5 100644
--- a/src/gpu/GrTextureOpList.h
+++ b/src/gpu/GrTextureOpList.h
@@ -51,7 +51,7 @@
      * depending on the type of surface, configs, etc, and the backend-specific
      * limitations.
      */
-    bool copySurface(GrResourceProvider* resourceProvider,
+    bool copySurface(const GrCaps& caps,
                      GrSurfaceProxy* dst,
                      GrSurfaceProxy* src,
                      const SkIRect& srcRect,
diff --git a/src/gpu/ops/GrCopySurfaceOp.cpp b/src/gpu/ops/GrCopySurfaceOp.cpp
index 9cbde0e..1a9a5e0 100644
--- a/src/gpu/ops/GrCopySurfaceOp.cpp
+++ b/src/gpu/ops/GrCopySurfaceOp.cpp
@@ -58,8 +58,7 @@
     return !clippedSrcRect->isEmpty();
 }
 
-std::unique_ptr<GrOp> GrCopySurfaceOp::Make(GrResourceProvider* resourceProvider,
-                                            GrSurfaceProxy* dstProxy, GrSurfaceProxy* srcProxy,
+std::unique_ptr<GrOp> GrCopySurfaceOp::Make(GrSurfaceProxy* dstProxy, GrSurfaceProxy* srcProxy,
                                             const SkIRect& srcRect,
                                             const SkIPoint& dstPoint) {
     SkASSERT(dstProxy);
@@ -75,17 +74,6 @@
         return nullptr;
     }
 
-    // MDB TODO: remove this instantiation
-    GrSurface* dstTex = dstProxy->instantiate(resourceProvider);
-    if (!dstTex) {
-        return nullptr;
-    }
-    GrSurface* srcTex = srcProxy->instantiate(resourceProvider);
-    if (!srcTex) {
-        return nullptr;
-    }
-
-    return std::unique_ptr<GrOp>(new GrCopySurfaceOp(dstTex, srcTex,
-                                                     dstProxy->uniqueID(), srcProxy->uniqueID(),
+    return std::unique_ptr<GrOp>(new GrCopySurfaceOp(dstProxy, srcProxy,
                                                      clippedSrcRect, clippedDstPoint));
 }
diff --git a/src/gpu/ops/GrCopySurfaceOp.h b/src/gpu/ops/GrCopySurfaceOp.h
index f479f28..f1dac8f 100644
--- a/src/gpu/ops/GrCopySurfaceOp.h
+++ b/src/gpu/ops/GrCopySurfaceOp.h
@@ -15,9 +15,7 @@
 public:
     DEFINE_OP_CLASS_ID
 
-    // MDB TODO: remove the resourceProvider parameter
-    static std::unique_ptr<GrOp> Make(GrResourceProvider*,
-                                      GrSurfaceProxy* dst, GrSurfaceProxy* src,
+    static std::unique_ptr<GrOp> Make(GrSurfaceProxy* dst, GrSurfaceProxy* src,
                                       const SkIRect& srcRect,
                                       const SkIPoint& dstPoint);
 
@@ -26,10 +24,10 @@
     SkString dumpInfo() const override {
         SkString string;
         string.append(INHERITED::dumpInfo());
-        string.printf("src: (proxyID: %d, rtID: %d), dst: (proxyID: %d, rtID: %d),\n"
-                      "srcRect: [L: %d, T: %d, R: %d, B: %d], dstPt: [X: %d, Y: %d]\n",
-                      fSrcProxyID.asUInt(), fSrc.get()->uniqueID().asUInt(),
-                      fDstProxyID.asUInt(), fDst.get()->uniqueID().asUInt(),
+        string.printf("srcProxyID: %d, dstProxyID: %d,\n"
+                      "srcRect: [ L: %d, T: %d, R: %d, B: %d ], dstPt: [ X: %d, Y: %d ]\n",
+                      fSrc.get()->uniqueID().asUInt(),
+                      fDst.get()->uniqueID().asUInt(),
                       fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBottom,
                       fDstPoint.fX, fDstPoint.fY);
         return string;
@@ -38,12 +36,9 @@
     bool needsCommandBufferIsolation() const override { return true; }
 
 private:
-    GrCopySurfaceOp(GrSurface* dst, GrSurface* src,
-                    GrSurfaceProxy::UniqueID dstID, GrSurfaceProxy::UniqueID srcID,
+    GrCopySurfaceOp(GrSurfaceProxy* dst, GrSurfaceProxy* src,
                     const SkIRect& srcRect, const SkIPoint& dstPoint)
             : INHERITED(ClassID())
-            , fDstProxyID(dstID)
-            , fSrcProxyID(srcID)
             , fDst(dst)
             , fSrc(src)
             , fSrcRect(srcRect)
@@ -60,17 +55,22 @@
 
     void onExecute(GrOpFlushState* state) override {
         SkASSERT(!state->commandBuffer());
-        state->gpu()->copySurface(fDst.get(), fSrc.get(), fSrcRect, fDstPoint);
+
+        GrSurface* dst = fDst.get()->instantiate(state->resourceProvider());
+        GrSurface* src = fSrc.get()->instantiate(state->resourceProvider());
+        if (!dst || !src) {
+            return;
+        }
+
+        state->gpu()->copySurface(dst, src, fSrcRect, fDstPoint);
     }
 
-    // MDB TODO: remove the proxy IDs once the GrSurfaceProxy carries the ref since they will
-    // be redundant
-    GrSurfaceProxy::UniqueID                        fDstProxyID;
-    GrSurfaceProxy::UniqueID                        fSrcProxyID;
-    GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst;
-    GrPendingIOResource<GrSurface, kRead_GrIOType>  fSrc;
-    SkIRect                                         fSrcRect;
-    SkIPoint                                        fDstPoint;
+    // For RenderTargetContexts 'fDst' is redundant with the RenderTarget that will be passed
+    // into onExecute in the drawOpArgs.
+    GrPendingIOResource<GrSurfaceProxy, kWrite_GrIOType> fDst;
+    GrPendingIOResource<GrSurfaceProxy, kRead_GrIOType>  fSrc;
+    SkIRect                                              fSrcRect;
+    SkIPoint                                             fDstPoint;
 
     typedef GrOp INHERITED;
 };