Fix drawSpecialImage

W/o this fix the strict constraint on the specialImage draws can sometimes be removed. This CL ensures that the temporary SkImage always has the actual dimensions of the special Image.

Note: the replacement of full screen clears w/ draws revealed this bug b.c. the image filters were only drawing a rect for the content area of the special images. Thus when the final DAG result was drawn to the canvas some of the bleed through (from the removal of the strict constraint) was showing.

Bug: 755871, 768134
skbug.com/7122

Change-Id: Id67b7143225c24b716e260c973f3bbf68f20188a
Reviewed-on: https://skia-review.googlesource.com/57660
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/include/private/GrRenderTargetProxy.h b/include/private/GrRenderTargetProxy.h
index 4794eff..e52588b 100644
--- a/include/private/GrRenderTargetProxy.h
+++ b/include/private/GrRenderTargetProxy.h
@@ -53,10 +53,6 @@
         return GrFSAAType::kMixedSamples == this->fsaaType() ? 0 : fSampleCnt;
     }
 
-    int worstCaseWidth() const;
-
-    int worstCaseHeight() const;
-
     int maxWindowRectangles(const GrCaps& caps) const;
 
     GrRenderTargetFlags testingOnly_getFlags() const;
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index 57724c4..fcccd36 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -217,6 +217,8 @@
     }
     int width() const { return fWidth; }
     int height() const { return fHeight; }
+    int worstCaseWidth() const;
+    int worstCaseHeight() const;
     GrPixelConfig config() const { return fConfig; }
 
     class UniqueID {
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index 111ecf6..77a3e52 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -79,28 +79,6 @@
     return surface;
 }
 
-int GrRenderTargetProxy::worstCaseWidth() const {
-    if (fTarget) {
-        return fTarget->width();
-    }
-
-    if (SkBackingFit::kExact == fFit) {
-        return fWidth;
-    }
-    return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fWidth));
-}
-
-int GrRenderTargetProxy::worstCaseHeight() const {
-    if (fTarget) {
-        return fTarget->height();
-    }
-
-    if (SkBackingFit::kExact == fFit) {
-        return fHeight;
-    }
-    return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fHeight));
-}
-
 size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
     int colorSamplesPerPixel = this->numColorSamples() + 1;
     // TODO: do we have enough information to improve this worst case estimate?
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 1b39363..69d5110 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -147,13 +147,8 @@
         hasMipMaps = tp->isMipMapped();
     }
 
-    int width = this->width();
-    int height = this->height();
-    if (SkBackingFit::kApprox == fFit) {
-        // bin by pow2 with a reasonable min
-        width  = SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(width));
-        height = SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(height));
-    }
+    int width = this->worstCaseWidth();
+    int height = this->worstCaseHeight();
 
     GrTexturePriv::ComputeScratchKey(this->config(), width, height, SkToBool(rtp), sampleCount,
                                      hasMipMaps, key);
@@ -382,6 +377,28 @@
     return GrSurfaceProxy::MakeWrapped(std::move(tex), origin);
 }
 
+int GrSurfaceProxy::worstCaseWidth() const {
+    if (fTarget) {
+        return fTarget->width();
+    }
+
+    if (SkBackingFit::kExact == fFit) {
+        return fWidth;
+    }
+    return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fWidth));
+}
+
+int GrSurfaceProxy::worstCaseHeight() const {
+    if (fTarget) {
+        return fTarget->height();
+    }
+
+    if (SkBackingFit::kExact == fFit) {
+        return fHeight;
+    }
+    return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fHeight));
+}
+
 #ifdef SK_DEBUG
 void GrSurfaceProxy::validate(GrContext* context) const {
     if (fTarget) {
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 2f7d663..3809266 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -40,7 +40,7 @@
 SkImage_Gpu::SkImage_Gpu(GrContext* context, uint32_t uniqueID, SkAlphaType at,
                          sk_sp<GrTextureProxy> proxy,
                          sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted)
-    : INHERITED(proxy->width(), proxy->height(), uniqueID)
+    : INHERITED(proxy->worstCaseWidth(), proxy->worstCaseHeight(), uniqueID)
     , fContext(context)
     , fProxy(std::move(proxy))
     , fAlphaType(at)