Make fully lazy proxies possess an origin

Change-Id: Icd3d68bce78568562aa12167a58b6d6e5064b124
Reviewed-on: https://skia-review.googlesource.com/106901
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp
index b8d2474..90f006a 100644
--- a/src/gpu/GrBackendTextureImageGenerator.cpp
+++ b/src/gpu/GrBackendTextureImageGenerator.cpp
@@ -136,7 +136,7 @@
 
     sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
             [refHelper, releaseProcHelper, semaphore, backendTexture]
-            (GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
+            (GrResourceProvider* resourceProvider) {
                 if (!resourceProvider) {
                     return sk_sp<GrTexture>();
                 }
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index e000dd4..d051bfd 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -221,7 +221,7 @@
 
     sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
             [desc, budgeted, srcImage, fit]
-            (GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
+            (GrResourceProvider* resourceProvider) {
                 if (!resourceProvider) {
                     // Nothing to clean up here. Once the proxy (and thus lambda) is deleted the ref
                     // on srcImage will be released.
@@ -322,7 +322,7 @@
 
     sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
             [desc, baseLevel, mipmaps, mipColorMode]
-            (GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
+            (GrResourceProvider* resourceProvider) {
                 if (!resourceProvider) {
                     return sk_sp<GrTexture>();
                 }
@@ -409,7 +409,7 @@
 
     sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
             [backendTex, ownership, releaseHelper]
-            (GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
+            (GrResourceProvider* resourceProvider) {
                 if (!resourceProvider) {
                     // If this had a releaseHelper it will get unrefed when we delete this lambda
                     // and will call the release proc so that the client knows they can free the
@@ -540,12 +540,13 @@
 
 sk_sp<GrTextureProxy> GrProxyProvider::createFullyLazyProxy(LazyInstantiateCallback&& callback,
                                                             Renderable renderable,
+                                                            GrSurfaceOrigin origin,
                                                             GrPixelConfig config) {
     GrSurfaceDesc desc;
     if (Renderable::kYes == renderable) {
         desc.fFlags = kRenderTarget_GrSurfaceFlag;
     }
-    desc.fOrigin = kTopLeft_GrSurfaceOrigin;
+    desc.fOrigin = origin;
     desc.fWidth = -1;
     desc.fHeight = -1;
     desc.fConfig = config;
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index 4803758..7e7f852 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -141,8 +141,7 @@
                                                          GrSurfaceOrigin origin,
                                                          int sampleCnt);
 
-    using LazyInstantiateCallback = std::function<sk_sp<GrSurface>(GrResourceProvider*,
-                                                                   GrSurfaceOrigin* outOrigin)>;
+    using LazyInstantiateCallback = std::function<sk_sp<GrSurface>(GrResourceProvider*)>;
     enum class Textureable : bool {
         kNo = false,
         kYes = true
@@ -166,8 +165,12 @@
     sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&,
                                           GrMipMapped, SkBackingFit, SkBudgeted);
 
+    /**
+     * Fully lazy proxies have unspecified width and height. Methods that rely on those values
+     * (e.g., width, height, getBoundsRect) should be avoided.
+     */
     sk_sp<GrTextureProxy> createFullyLazyProxy(LazyInstantiateCallback&&,
-                                               Renderable, GrPixelConfig);
+                                               Renderable, GrSurfaceOrigin, GrPixelConfig);
 
     sk_sp<GrRenderTargetProxy> createLazyRenderTargetProxy(LazyInstantiateCallback&&,
                                                            const GrSurfaceDesc&, Textureable,
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 6c81fc0..48d4be1 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -87,7 +87,7 @@
     if (fLazyInstantiateCallback) {
         // We call the callback with a null GrResourceProvider to signal that the lambda should
         // clean itself up if it is holding onto any captured objects.
-        this->fLazyInstantiateCallback(nullptr, nullptr);
+        this->fLazyInstantiateCallback(nullptr);
     }
     // For this to be deleted the opList that held a ref on it (if there was one) must have been
     // deleted. Which would have cleared out this back pointer.
@@ -353,26 +353,14 @@
 bool GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvider) {
     SkASSERT(GrSurfaceProxy::LazyState::kNot != fProxy->lazyInstantiationState());
 
-    GrSurfaceOrigin* outOrigin;
-    if (GrSurfaceProxy::LazyState::kPartially == fProxy->lazyInstantiationState()) {
-        // In the partially instantiated case, we set the origin on the SurfaceProxy at creation
-        // time (via a GrSurfaceDesc). In the lambda, the creation of the texture never needs to
-        // know the origin, and it also can't change or have any effect on it. Thus we just pass in
-        // nullptr in this case since it should never be set.
-        outOrigin = nullptr;
-    } else {
-        outOrigin = &fProxy->fOrigin;
-    }
-
-    sk_sp<GrSurface> surface = fProxy->fLazyInstantiateCallback(resourceProvider, outOrigin);
+    sk_sp<GrSurface> surface = fProxy->fLazyInstantiateCallback(resourceProvider);
     if (GrSurfaceProxy::LazyInstantiationType::kSingleUse == fProxy->fLazyInstantiationType) {
-        fProxy->fLazyInstantiateCallback(nullptr, nullptr);
+        fProxy->fLazyInstantiateCallback(nullptr);
         fProxy->fLazyInstantiateCallback = nullptr;
     }
     if (!surface) {
         fProxy->fWidth = 0;
         fProxy->fHeight = 0;
-        fProxy->fOrigin = kTopLeft_GrSurfaceOrigin;
         return false;
     }
 
diff --git a/src/gpu/ccpr/GrCCAtlas.cpp b/src/gpu/ccpr/GrCCAtlas.cpp
index 5ef39f8..97b28fb 100644
--- a/src/gpu/ccpr/GrCCAtlas.cpp
+++ b/src/gpu/ccpr/GrCCAtlas.cpp
@@ -138,6 +138,8 @@
     SkASSERT(!fTextureProxy);
 
     GrSurfaceDesc desc;
+    desc.fFlags = kRenderTarget_GrSurfaceFlag;
+    desc.fOrigin = kTopLeft_GrSurfaceOrigin;
     desc.fWidth = fWidth;
     desc.fHeight = fHeight;
     desc.fConfig = kAlpha_half_GrPixelConfig;
diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
index da69917..ec3681d 100644
--- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
+++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
@@ -229,7 +229,7 @@
     SkASSERT(this->isUninitialized());
 
     fAtlasLazyProxy = proxyProvider->createFullyLazyProxy(
-            [this](GrResourceProvider* resourceProvider, GrSurfaceOrigin* outOrigin) {
+            [this](GrResourceProvider* resourceProvider) {
                 if (!resourceProvider) {
                     return sk_sp<GrTexture>();
                 }
@@ -243,19 +243,16 @@
                     return sk_sp<GrTexture>();
                 }
 
+                SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin());
+
                 fAtlasScale = {1.f / textureProxy->width(), 1.f / textureProxy->height()};
                 fAtlasTranslate = {fAtlasOffsetX * fAtlasScale.x(),
                                    fAtlasOffsetY * fAtlasScale.y()};
-                if (kBottomLeft_GrSurfaceOrigin == textureProxy->origin()) {
-                    fAtlasScale.fY = -fAtlasScale.y();
-                    fAtlasTranslate.fY = 1 - fAtlasTranslate.y();
-                }
                 SkDEBUGCODE(fHasAtlasTransform = true);
 
-                *outOrigin = textureProxy->origin();
                 return sk_ref_sp(textureProxy->priv().peekTexture());
             },
-            GrProxyProvider::Renderable::kYes, kAlpha_half_GrPixelConfig);
+            GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin, kAlpha_half_GrPixelConfig);
 
     const SkRect& pathDevBounds = deviceSpacePath.getBounds();
     if (SkTMax(pathDevBounds.height(), pathDevBounds.width()) > kPathCropThreshold) {