Update copy and blitTexture calls to not query origin off of proxies.

Bug: skia:9556
Change-Id: I4042f1339844186b73b807e93b1a3701c32bf112
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/269366
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index a3d5a5d..6a08e46 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -2604,21 +2604,19 @@
     return true;
 }
 
-bool GrRenderTargetContext::blitTexture(GrTextureProxy* src, const SkIRect& srcRect,
+bool GrRenderTargetContext::blitTexture(GrSurfaceProxyView view, const SkIRect& srcRect,
                                         const SkIPoint& dstPoint) {
+    SkASSERT(view.asTextureProxy());
     SkIRect clippedSrcRect;
     SkIPoint clippedDstPoint;
-    if (!GrClipSrcRectAndDstPoint(this->asSurfaceProxy()->dimensions(), src->dimensions(), srcRect,
-                                  dstPoint, &clippedSrcRect, &clippedDstPoint)) {
+    if (!GrClipSrcRectAndDstPoint(this->asSurfaceProxy()->dimensions(), view.proxy()->dimensions(),
+                                  srcRect, dstPoint, &clippedSrcRect, &clippedDstPoint)) {
         return false;
     }
 
     GrPaint paint;
     paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
 
-    GrSurfaceOrigin origin = src->origin();
-    GrSwizzle swizzle = src->textureSwizzle();
-    GrSurfaceProxyView view(sk_ref_sp(src), origin, swizzle);
     auto fp = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType);
     if (!fp) {
         return false;
diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h
index 3101fbe..637e5a1 100644
--- a/src/gpu/GrRenderTargetContext.h
+++ b/src/gpu/GrRenderTargetContext.h
@@ -517,7 +517,7 @@
      * of the srcRect. The srcRect and dstRect are clipped to the bounds of the src and dst surfaces
      * respectively.
      */
-    bool blitTexture(GrTextureProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint);
+    bool blitTexture(GrSurfaceProxyView view, const SkIRect& srcRect, const SkIPoint& dstPoint);
 
     /**
      * Adds the necessary signal and wait semaphores and adds the passed in SkDrawable to the
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 9822462..bfb0344 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -426,7 +426,7 @@
         } else {
             SkIRect srcRect = SkIRect::MakeWH(srcInfo.width(), srcInfo.height());
             SkIPoint dstPoint = SkIPoint::Make(pt.fX, pt.fY);
-            if (!this->copy(tempProxy.get(), srcRect, dstPoint)) {
+            if (!this->copy(tempProxy.get(), tempOrigin, srcRect, dstPoint)) {
                 return false;
             }
         }
@@ -470,7 +470,8 @@
                                                 srcColorType, src, rowBytes);
 }
 
-bool GrSurfaceContext::copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) {
+bool GrSurfaceContext::copy(GrSurfaceProxy* src, GrSurfaceOrigin origin, const SkIRect& srcRect,
+                            const SkIPoint& dstPoint) {
     ASSERT_SINGLE_OWNER
     RETURN_FALSE_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
@@ -479,9 +480,8 @@
     const GrCaps* caps = fContext->priv().caps();
 
     SkASSERT(src->backendFormat().textureType() != GrTextureType::kExternal);
-    SkASSERT(src->origin() == this->asSurfaceProxy()->origin());
-    SkASSERT(src->textureSwizzle() == this->asSurfaceProxy()->textureSwizzle());
     SkASSERT(src->backendFormat() == this->asSurfaceProxy()->backendFormat());
+    SkASSERT(origin == this->origin());
 
     if (this->asSurfaceProxy()->framebufferOnly()) {
         return false;
@@ -493,7 +493,7 @@
 
     // The swizzle doesn't matter for copies and it is not used.
     return this->drawingManager()->newCopyRenderTask(
-            GrSurfaceProxyView(sk_ref_sp(src), src->origin(), GrSwizzle()), srcRect,
+            GrSurfaceProxyView(sk_ref_sp(src), origin, GrSwizzle()), srcRect,
             this->readSurfaceView(), dstPoint);
 }
 
diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h
index 4bb1f2d..20f67b8 100644
--- a/src/gpu/GrSurfaceContext.h
+++ b/src/gpu/GrSurfaceContext.h
@@ -120,12 +120,13 @@
     const GrSurfaceContextPriv surfPriv() const;
 
 #if GR_TEST_UTILS
-    bool testCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) {
-        return this->copy(src, srcRect, dstPoint);
+    bool testCopy(GrSurfaceProxy* src, GrSurfaceOrigin origin, const SkIRect& srcRect,
+                  const SkIPoint& dstPoint) {
+        return this->copy(src, origin, srcRect, dstPoint);
     }
 
-    bool testCopy(GrSurfaceProxy* src) {
-        return this->copy(src);
+    bool testCopy(GrSurfaceProxy* src, GrSurfaceOrigin origin) {
+        return this->copy(src, origin, SkIRect::MakeSize(src->dimensions()),  SkIPoint::Make(0, 0));
     }
 #endif
 
@@ -182,11 +183,8 @@
      *       regions will not be shifted. The 'src' must have the same origin as the backing proxy
      *       of fSurfaceContext.
      */
-    bool copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint);
-
-    bool copy(GrSurfaceProxy* src) {
-        return this->copy(src, SkIRect::MakeSize(src->dimensions()), SkIPoint::Make(0, 0));
-    }
+    bool copy(GrSurfaceProxy* src, GrSurfaceOrigin origin, const SkIRect& srcRect,
+              const SkIPoint& dstPoint);
 
     GrColorInfo fColorInfo;
 
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 7391c01..26720aa 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -313,7 +313,7 @@
                                                  GrRenderable::kNo, 1, mipMapped,
                                                  src->isProtected(), origin, srcColorType,
                                                  kUnknown_SkAlphaType, nullptr, fit, budgeted);
-        if (dstContext && dstContext->copy(src, srcRect, dstPoint)) {
+        if (dstContext && dstContext->copy(src, origin, srcRect, dstPoint)) {
             return dstContext->readSurfaceView();
         }
     }
@@ -322,7 +322,10 @@
                                                       {width, height}, format, 1,
                                                       mipMapped, src->isProtected(), origin,
                                                       budgeted, nullptr);
-        if (dstContext && dstContext->blitTexture(src->asTextureProxy(), srcRect, dstPoint)) {
+        GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(src->backendFormat(),
+                                                                   srcColorType);
+        GrSurfaceProxyView view(sk_ref_sp(src), origin, swizzle);
+        if (dstContext && dstContext->blitTexture(std::move(view), srcRect, dstPoint)) {
             return dstContext->readSurfaceView();
         }
     }
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 0f5d4fb..aef1f6e 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -227,7 +227,7 @@
         }
 
         SkASSERT(fRenderTargetContext->asTextureProxy());
-        SkAssertResult(rtc->blitTexture(fRenderTargetContext->asTextureProxy(),
+        SkAssertResult(rtc->blitTexture(fRenderTargetContext->readSurfaceView(),
                                         SkIRect::MakeWH(this->width(), this->height()),
                                         SkIPoint::Make(0,0)));
     }
diff --git a/tests/CopySurfaceTest.cpp b/tests/CopySurfaceTest.cpp
index e670dec..5cb6dbe 100644
--- a/tests/CopySurfaceTest.cpp
+++ b/tests/CopySurfaceTest.cpp
@@ -115,11 +115,15 @@
 
                                 bool result = false;
                                 if (sOrigin == dOrigin) {
-                                    result = dstContext->testCopy(src.get(), srcRect, dstPoint);
+                                    result = dstContext->testCopy(src.get(), sOrigin, srcRect,
+                                                                  dstPoint);
                                 } else if (dRenderable == GrRenderable::kYes) {
                                     SkASSERT(dstContext->asRenderTargetContext());
+                                    GrSwizzle srcSwizzle = context->priv().caps()->getReadSwizzle(
+                                        src->backendFormat(), grColorType);
+                                    GrSurfaceProxyView view(std::move(src), sOrigin, srcSwizzle);
                                     result = dstContext->asRenderTargetContext()->blitTexture(
-                                            src.get(), srcRect, dstPoint);
+                                            std::move(view), srcRect, dstPoint);
                                 }
 
                                 bool expectedResult = true;
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index 9361ef1..462b6d0 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -420,7 +420,7 @@
         auto[copySrc, grCT] = maker.view(GrMipMapped::kNo);
 
         REPORTER_ASSERT(reporter, copySrc.proxy());
-        auto copyResult = surfContext->testCopy(copySrc.proxy());
+        auto copyResult = surfContext->testCopy(copySrc.proxy(), copySrc.origin());
         REPORTER_ASSERT(reporter, copyResult == (ioType == kRW_GrIOType));
         // Try the low level copy.
         context->flush();
@@ -815,7 +815,7 @@
         auto proxy = context->priv().proxyProvider()->testingOnly_createWrapped(
                 std::move(idleTexture), GrColorType::kRGBA_8888, rtc->asSurfaceProxy()->origin());
         context->flush();
-        SkAssertResult(rtc->testCopy(proxy.get()));
+        SkAssertResult(rtc->testCopy(proxy.get(), rtc->asSurfaceProxy()->origin()));
         proxy.reset();
         REPORTER_ASSERT(reporter, flags == 0);
 
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index 17f19db..7ca4a00 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -119,7 +119,7 @@
                 pixels.get(), 0);
         // If this assert ever fails we can add a fallback to do copy as draw, but until then we can
         // be more restrictive.
-        SkAssertResult(dstContext->testCopy(src.get()));
+        SkAssertResult(dstContext->testCopy(src.get(), origin));
         TestReadPixels(reporter, dstContext, pixels.get(), testName);
     }
 }