Cleanup patch to move all of SkImageFilterUtils into SkImageFilter.

This was a utility class that dates from before GPU code was allowed
in core. Now that it is, there's no reason not to have this
functionality in SkImageFilter.

Covered by existing tests.

R=reed@google.com

Review URL: https://codereview.chromium.org/185973003

git-svn-id: http://skia.googlecode.com/svn/trunk@13646 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index cd7c01b..4a380c5 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -14,8 +14,8 @@
 #include "SkValidationUtils.h"
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
-#include "GrTexture.h"
-#include "SkImageFilterUtils.h"
+#include "SkGrPixelRef.h"
+#include "SkGr.h"
 #endif
 
 SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect)
@@ -146,10 +146,11 @@
 bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
                                    SkBitmap* result, SkIPoint* offset) const {
 #if SK_SUPPORT_GPU
-    SkBitmap input;
+    SkBitmap input = src;
     SkASSERT(fInputCount == 1);
     SkIPoint srcOffset = SkIPoint::Make(0, 0);
-    if (!SkImageFilterUtils::GetInputResultGPU(this->getInput(0), proxy, src, ctm, &input, &srcOffset)) {
+    if (this->getInput(0) &&
+        !this->getInput(0)->getInputResultGPU(proxy, src, ctm, &input, &srcOffset)) {
         return false;
     }
     GrTexture* srcTexture = input.getTexture();
@@ -188,7 +189,7 @@
     context->drawRectToRect(paint, dstRect, srcRect);
 
     SkAutoTUnref<GrTexture> resultTex(dst.detach());
-    SkImageFilterUtils::WrapTexture(resultTex, bounds.width(), bounds.height(), result);
+    WrapTexture(resultTex, bounds.width(), bounds.height(), result);
     return true;
 #else
     return false;
@@ -242,3 +243,40 @@
 bool SkImageFilter::asColorFilter(SkColorFilter**) const {
     return false;
 }
+
+#if SK_SUPPORT_GPU
+
+void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
+    SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
+    result->setConfig(info);
+    result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
+}
+
+bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy,
+                                      const SkBitmap& src, const SkMatrix& ctm,
+                                      SkBitmap* result, SkIPoint* offset) const {
+    // Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity
+    // matrix with no clip and that the matrix, clip, and render target set before this function was
+    // called are restored before we return to the caller.
+    GrContext* context = src.getTexture()->getContext();
+    GrContext::AutoWideOpenIdentityDraw awoid(context, NULL);
+    if (this->canFilterImageGPU()) {
+        return this->filterImageGPU(proxy, src, ctm, result, offset);
+    } else {
+        if (this->filterImage(proxy, src, ctm, result, offset)) {
+            if (!result->getTexture()) {
+                SkImageInfo info;
+                if (!result->asImageInfo(&info)) {
+                    return false;
+                }
+                GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, *result, NULL);
+                result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref();
+                GrUnlockAndUnrefCachedBitmapTexture(resultTex);
+            }
+            return true;
+        } else {
+            return false;
+        }
+    }
+}
+#endif