Update OnFlushResourceProvider for views.

Bug: skia:9556
Change-Id: I4c76192b9c4a5af9383ed131491e967741c3c743
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/269909
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrDynamicAtlas.cpp b/src/gpu/GrDynamicAtlas.cpp
index 3ba2e8c..6128db5 100644
--- a/src/gpu/GrDynamicAtlas.cpp
+++ b/src/gpu/GrDynamicAtlas.cpp
@@ -182,7 +182,8 @@
 #endif
         fBackingTexture = std::move(backingTexture);
     }
-    auto rtc = onFlushRP->makeRenderTargetContext(fTextureProxy, fColorType, nullptr, nullptr);
+    auto rtc = onFlushRP->makeRenderTargetContext(fTextureProxy, kTextureOrigin, fColorType,
+                                                  nullptr, nullptr);
     if (!rtc) {
 #if GR_TEST_UTILS
         if (!onFlushRP->testingOnly_getSuppressAllocationWarnings())
diff --git a/src/gpu/GrOnFlushResourceProvider.cpp b/src/gpu/GrOnFlushResourceProvider.cpp
index 03d7334..a01b31c 100644
--- a/src/gpu/GrOnFlushResourceProvider.cpp
+++ b/src/gpu/GrOnFlushResourceProvider.cpp
@@ -17,8 +17,8 @@
 #include "src/gpu/GrTextureResolveRenderTask.h"
 
 std::unique_ptr<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
-        sk_sp<GrSurfaceProxy> proxy, GrColorType colorType, sk_sp<SkColorSpace> colorSpace,
-        const SkSurfaceProps* props) {
+        sk_sp<GrSurfaceProxy> proxy, GrSurfaceOrigin origin, GrColorType colorType,
+        sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) {
     // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator
     // we have to manually ensure it is allocated here.
     if (!this->instatiateProxy(proxy.get())) {
@@ -31,7 +31,6 @@
         return nullptr;
     }
 
-    GrSurfaceOrigin origin = proxy->origin();
     auto renderTargetContext = GrRenderTargetContext::Make(
             context, colorType, std::move(colorSpace), std::move(proxy),
             origin, props, false);
diff --git a/src/gpu/GrOnFlushResourceProvider.h b/src/gpu/GrOnFlushResourceProvider.h
index 894a21e..1f18d49 100644
--- a/src/gpu/GrOnFlushResourceProvider.h
+++ b/src/gpu/GrOnFlushResourceProvider.h
@@ -65,8 +65,10 @@
 
     explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
 
-    std::unique_ptr<GrRenderTargetContext> makeRenderTargetContext(
-            sk_sp<GrSurfaceProxy>, GrColorType, sk_sp<SkColorSpace>, const SkSurfaceProps*);
+    std::unique_ptr<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
+                                                                   GrSurfaceOrigin, GrColorType,
+                                                                   sk_sp<SkColorSpace>,
+                                                                   const SkSurfaceProps*);
 
     void addTextureResolveTask(sk_sp<GrTextureProxy>, GrSurfaceProxy::ResolveFlags);
 
diff --git a/tests/OnFlushCallbackTest.cpp b/tests/OnFlushCallbackTest.cpp
index 124f221..e149b4d 100644
--- a/tests/OnFlushCallbackTest.cpp
+++ b/tests/OnFlushCallbackTest.cpp
@@ -303,16 +303,16 @@
 
     // Get the fully lazy proxy that is backing the atlas. Its actual width isn't
     // known until flush time.
-    sk_sp<GrTextureProxy> getAtlasProxy(GrProxyProvider* proxyProvider, const GrCaps* caps) {
-        if (fAtlasProxy) {
-            return fAtlasProxy;
+    GrSurfaceProxyView getAtlasView(GrProxyProvider* proxyProvider, const GrCaps* caps) {
+        if (fAtlasView) {
+            return fAtlasView;
         }
 
         const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
                                                                      GrRenderable::kYes);
         GrSwizzle readSwizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888);
 
-        fAtlasProxy = GrProxyProvider::MakeFullyLazyProxy(
+        auto proxy = GrProxyProvider::MakeFullyLazyProxy(
                 [format](GrResourceProvider* resourceProvider)
                         -> GrSurfaceProxy::LazyCallbackResult {
                     SkISize dims;
@@ -334,7 +334,8 @@
                 *proxyProvider->caps(),
                 GrSurfaceProxy::UseAllocator::kNo);
 
-        return fAtlasProxy;
+        fAtlasView = {std::move(proxy), kBottomLeft_GrSurfaceOrigin, readSwizzle};
+        return fAtlasView;
     }
 
     /*
@@ -355,17 +356,18 @@
             return; // nothing to atlas
         }
 
-        if (!resourceProvider->instatiateProxy(fAtlasProxy.get())) {
+        if (!resourceProvider->instatiateProxy(fAtlasView.proxy())) {
             return;
         }
 
-        // At this point 'fAtlasProxy' should be instantiated and have:
-        //    1 ref from the 'fAtlasProxy' sk_sp
+        // At this point 'fAtlasView' proxy should be instantiated and have:
+        //    1 ref from the 'fAtlasView' proxy sk_sp
         //    9 refs from the 9 AtlasedRectOps
         // The backing GrSurface should have only 1 though bc there is only one proxy
-        CheckSingleThreadedProxyRefs(fReporter, fAtlasProxy.get(), 10, 1);
-        auto rtc = resourceProvider->makeRenderTargetContext(fAtlasProxy, GrColorType::kRGBA_8888,
-                                                             nullptr, nullptr);
+        CheckSingleThreadedProxyRefs(fReporter, fAtlasView.proxy(), 10, 1);
+        auto rtc = resourceProvider->makeRenderTargetContext(
+                fAtlasView.refProxy(), fAtlasView.origin(), GrColorType::kRGBA_8888, nullptr,
+                nullptr);
 
         // clear the atlas
         rtc->clear(nullptr, SK_PMColor4fTRANSPARENT,
@@ -425,30 +427,27 @@
     }
 
     // Each opsTask containing AtlasedRectOps gets its own internal singly-linked list
-    SkTDArray<LinkedListHeader>  fOps;
+    SkTDArray<LinkedListHeader> fOps;
 
     // The fully lazy proxy for the atlas
-    sk_sp<GrTextureProxy>        fAtlasProxy;
+    GrSurfaceProxyView fAtlasView;
 
     // Set to true when the testing harness expects this object to be no longer used
-    bool                         fDone;
+    bool fDone;
 
-    skiatest::Reporter*           fReporter;
+    skiatest::Reporter* fReporter;
 };
 
 // This creates an off-screen rendertarget whose ops which eventually pull from the atlas.
-static sk_sp<GrTextureProxy> make_upstream_image(GrContext* context, AtlasObject* object, int start,
-                                                 sk_sp<GrTextureProxy> atlasProxy,
-                                                 SkAlphaType atlasAlphaType) {
+static GrSurfaceProxyView make_upstream_image(GrContext* context, AtlasObject* object, int start,
+                                              GrSurfaceProxyView atlasView,
+                                              SkAlphaType atlasAlphaType) {
     auto rtc = GrRenderTargetContext::Make(
             context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kApprox,
             {3 * kDrawnTileSize, kDrawnTileSize});
 
     rtc->clear(nullptr, { 1, 0, 0, 1 }, GrRenderTargetContext::CanClearFullscreen::kYes);
 
-    GrSurfaceOrigin origin = atlasProxy->origin();
-    GrSwizzle swizzle = atlasProxy->textureSwizzle();
-    GrSurfaceProxyView atlasView(std::move(atlasProxy), origin, swizzle);
     for (int i = 0; i < 3; ++i) {
         SkRect r = SkRect::MakeXYWH(i*kDrawnTileSize, 0, kDrawnTileSize, kDrawnTileSize);
 
@@ -469,7 +468,7 @@
         object->addOp(opsTaskID, sparePtr);
     }
 
-    return rtc->asTextureProxyRef();
+    return rtc->readSurfaceView();
 }
 
 // Enable this if you want to debug the final draws w/o having the atlasCallback create the
@@ -538,7 +537,7 @@
  *           R G B C M Y K Grey White
  */
 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(OnFlushCallbackTest, reporter, ctxInfo) {
-    static const int kNumProxies = 3;
+    static const int kNumViews = 3;
 
     GrContext* context = ctxInfo.grContext();
     auto proxyProvider = context->priv().proxyProvider();
@@ -547,11 +546,11 @@
 
     context->priv().addOnFlushCallbackObject(&object);
 
-    sk_sp<GrTextureProxy> proxies[kNumProxies];
-    for (int i = 0; i < kNumProxies; ++i) {
-        proxies[i] = make_upstream_image(
-                context, &object, i*3,
-                object.getAtlasProxy(proxyProvider, context->priv().caps()), kPremul_SkAlphaType);
+    GrSurfaceProxyView views[kNumViews];
+    for (int i = 0; i < kNumViews; ++i) {
+        views[i] = make_upstream_image(context, &object, i * 3,
+                                       object.getAtlasView(proxyProvider, context->priv().caps()),
+                                       kPremul_SkAlphaType);
     }
 
     static const int kFinalWidth = 6*kDrawnTileSize;
@@ -564,16 +563,13 @@
     rtc->clear(nullptr, SK_PMColor4fWHITE, GrRenderTargetContext::CanClearFullscreen::kYes);
 
     // Note that this doesn't include the third texture proxy
-    for (int i = 0; i < kNumProxies-1; ++i) {
+    for (int i = 0; i < kNumViews - 1; ++i) {
         SkRect r = SkRect::MakeXYWH(i*3*kDrawnTileSize, 0, 3*kDrawnTileSize, kDrawnTileSize);
 
         SkMatrix t = SkMatrix::MakeTrans(-i*3*kDrawnTileSize, 0);
 
         GrPaint paint;
-        GrSurfaceOrigin origin = proxies[i]->origin();
-        GrSwizzle swizzle = proxies[i]->textureSwizzle();
-        GrSurfaceProxyView view(std::move(proxies[i]), origin, swizzle);
-        auto fp = GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, t);
+        auto fp = GrTextureEffect::Make(std::move(views[i]), kPremul_SkAlphaType, t);
         paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
         paint.addColorFragmentProcessor(std::move(fp));
 
diff --git a/tests/TestUtils.cpp b/tests/TestUtils.cpp
index ed7edce..9dda6fb 100644
--- a/tests/TestUtils.cpp
+++ b/tests/TestUtils.cpp
@@ -294,7 +294,7 @@
 }
 
 void CheckSingleThreadedProxyRefs(skiatest::Reporter* reporter,
-                                  GrTextureProxy* proxy,
+                                  GrSurfaceProxy* proxy,
                                   int32_t expectedProxyRefs,
                                   int32_t expectedBackingRefs) {
     int32_t actualBackingRefs = proxy->testingOnly_getBackingRefCnt();
diff --git a/tests/TestUtils.h b/tests/TestUtils.h
index 6d5206e..4d09ab4 100644
--- a/tests/TestUtils.h
+++ b/tests/TestUtils.h
@@ -93,6 +93,6 @@
  * resource are both used on a single thread.
  */
 void CheckSingleThreadedProxyRefs(skiatest::Reporter* reporter,
-                                  GrTextureProxy* proxy,
+                                  GrSurfaceProxy* proxy,
                                   int32_t expectedProxyRefs,
                                   int32_t expectedBackingRefs);