Refactor to use GrWrapTextureInBitmap more
authorrobertphillips <robertphillips@google.com>
Thu, 14 Jan 2016 14:03:29 +0000 (06:03 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 14 Jan 2016 14:03:29 +0000 (06:03 -0800)
Too many wrap_texture methods!

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1584933002

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

12 files changed:
include/core/SkImageFilter.h
src/core/SkImageFilter.cpp
src/core/SkMaskFilter.cpp
src/effects/SkBlurImageFilter.cpp
src/effects/SkBlurMaskFilter.cpp
src/effects/SkDisplacementMapEffect.cpp
src/effects/SkLightingImageFilter.cpp
src/effects/SkMorphologyImageFilter.cpp
src/effects/SkXfermodeImageFilter.cpp
src/gpu/GrLayerHoister.cpp
src/gpu/GrRecordReplaceDraw.cpp
src/gpu/SkGpuDevice.cpp

index eb5d2a1b062c25ae4e49487036f2a2d5bdc5895b..8153bacb793a8d8c70f10c6f404ad7887af9df3b 100644 (file)
@@ -250,11 +250,6 @@ public:
                                              SkImageFilter* input = NULL);
 
 #if SK_SUPPORT_GPU
-    /**
-     * Wrap the given texture in a texture-backed SkBitmap.
-     */
-    static void WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result);
-
     // Helper function which invokes GPU filter processing on the
     // input at the specified "index". If the input is null, it leaves
     // "result" and "offset" untouched, and returns true. If the input
index b068644d556c6fb42a8a9b0ef399bdc1ca8ddafa..489a52bf8751363b7313016f92b5cc25dd7dff82 100644 (file)
@@ -368,7 +368,7 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont
         if (drawContext) {
             drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
 
-            WrapTexture(dst, bounds.width(), bounds.height(), result);
+            GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, result);
             return true;
         }
     }
@@ -502,12 +502,6 @@ SkImageFilter* SkImageFilter::newWithLocalMatrix(const SkMatrix& matrix) const {
 
 #if SK_SUPPORT_GPU
 
-void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
-    SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
-    result->setInfo(info);
-    result->setPixelRef(new SkGrPixelRef(info, texture))->unref();
-}
-
 bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy,
                                    const SkBitmap& src, const Context& ctx,
                                    SkBitmap* result, SkIPoint* offset) const {
index 8749f50c4d1b64ec460712754a89270b3a8a74cf..51c489721d4b8f8594a713474d7fd99723f189d4 100644 (file)
@@ -19,7 +19,6 @@
 #if SK_SUPPORT_GPU
 #include "GrTexture.h"
 #include "SkGr.h"
-#include "SkGrPixelRef.h"
 #endif
 
 SkMaskFilter::NinePatch::~NinePatch() {
index 97cc8a9544faee3e5263513f4f1e38a6cd590b18..5d58369bc765cd561f6836a702145c7b4af0b6f1 100644 (file)
@@ -15,6 +15,7 @@
 #include "SkWriteBuffer.h"
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
+#include "SkGr.h"
 #endif
 
 // This rather arbitrary-looking value results in a maximum box blur kernel size
@@ -227,7 +228,7 @@ bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
     if (!tex) {
         return false;
     }
-    WrapTexture(tex, dstBounds.width(), dstBounds.height(), result);
+    GrWrapTextureInBitmap(tex, dstBounds.width(), dstBounds.height(), false, result);
     return true;
 #else
     SkDEBUGFAIL("Should not call in GPU-less build");
index ca448bc2d0cbf110354c45d3bf9e7a47b344ff52..edd2fa4f695d0d96a1f856edaf4146317eb94d2d 100644 (file)
@@ -24,7 +24,6 @@
 #include "GrTexture.h"
 #include "GrFragmentProcessor.h"
 #include "GrInvariantOutput.h"
-#include "SkGrPixelRef.h"
 #include "SkDraw.h"
 #include "effects/GrSimpleTextureEffect.h"
 #include "glsl/GrGLSLFragmentProcessor.h"
index c50b1f2c18344e08af66979a242346f2eff399f8..9c640e3a984fe9a62aee43f2da104b4e1bf27dff 100644 (file)
@@ -16,6 +16,7 @@
 #include "GrDrawContext.h"
 #include "GrCoordTransform.h"
 #include "GrInvariantOutput.h"
+#include "SkGr.h"
 #include "effects/GrTextureDomain.h"
 #include "glsl/GrGLSLFragmentProcessor.h"
 #include "glsl/GrGLSLFragmentShaderBuilder.h"
@@ -465,7 +466,7 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
     drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(colorBounds));
     offset->fX = bounds.left();
     offset->fY = bounds.top();
-    WrapTexture(dst, bounds.width(), bounds.height(), result);
+    GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, result);
     return true;
 }
 
index 6c2ec72c226fc50f3f20b016c130f9b5ff1e8d15..f701b4c8945952f619404479d11d226574b51bc9 100644 (file)
@@ -20,6 +20,7 @@
 #include "GrFragmentProcessor.h"
 #include "GrInvariantOutput.h"
 #include "GrPaint.h"
+#include "SkGr.h"
 #include "effects/GrSingleTextureEffect.h"
 #include "glsl/GrGLSLFragmentProcessor.h"
 #include "glsl/GrGLSLFragmentShaderBuilder.h"
@@ -424,7 +425,7 @@ bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy,
     this->drawRect(drawContext, srcTexture, matrix, clip, bottom, kBottom_BoundaryMode, bounds);
     this->drawRect(drawContext, srcTexture, matrix, clip, bottomRight,
                    kBottomRight_BoundaryMode, bounds);
-    WrapTexture(dst, bounds.width(), bounds.height(), result);
+    GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, result);
     return true;
 }
 #endif
index 895000e86e93b834446689c78e2e71210faff8fb..3f6bc947cfcbc0f209496593b1e0770bca37c242 100644 (file)
@@ -18,6 +18,7 @@
 #include "GrDrawContext.h"
 #include "GrInvariantOutput.h"
 #include "GrTexture.h"
+#include "SkGr.h"
 #include "effects/Gr1DKernelEffect.h"
 #include "glsl/GrGLSLFragmentProcessor.h"
 #include "glsl/GrGLSLFragmentShaderBuilder.h"
@@ -606,7 +607,7 @@ bool apply_morphology(const SkBitmap& input,
 
         srcTexture.reset(scratch);
     }
-    SkImageFilter::WrapTexture(srcTexture, rect.width(), rect.height(), dst);
+    GrWrapTextureInBitmap(srcTexture, rect.width(), rect.height(), false, dst);
     return true;
 }
 
index c2013fdb86d04f812d22c4c830ea1dea4ed8caec..5f88240481b316c7e0c6b7d57f0a22ed815d004a 100644 (file)
@@ -212,7 +212,7 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
 
     offset->fX = bounds.left();
     offset->fY = bounds.top();
-    WrapTexture(dst, bounds.width(), bounds.height(), result);
+    GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, result);
     return true;
 }
 
index 2c45a7f9e55a008532cc89a26d5cb9c51489bb16..842ab56dfbdd1c84d09206a27f4216043af2963e 100644 (file)
@@ -12,7 +12,6 @@
 #include "SkBigPicture.h"
 #include "SkCanvas.h"
 #include "SkGpuDevice.h"
-#include "SkGrPixelRef.h"
 #include "SkLayerInfo.h"
 #include "SkRecordDraw.h"
 #include "SkSurface.h"
@@ -277,15 +276,6 @@ void GrLayerHoister::DrawLayersToAtlas(GrContext* context,
     }
 }
 
-SkBitmap wrap_texture(GrTexture* texture) {
-    SkASSERT(texture);
-
-    SkBitmap result;
-    result.setInfo(texture->surfacePriv().info(kPremul_SkAlphaType));
-    result.setPixelRef(new SkGrPixelRef(result.info(), texture))->unref();
-    return result;
-}
-
 void GrLayerHoister::FilterLayer(GrContext* context,
                                  SkGpuDevice* device,
                                  const GrHoistedLayer& info) {
@@ -314,7 +304,9 @@ void GrLayerHoister::FilterLayer(GrContext* context,
     SkImageFilter::Context filterContext(totMat, clipBounds, cache);
 
     SkImageFilter::DeviceProxy proxy(device);
-    const SkBitmap src = wrap_texture(layer->texture());
+    SkBitmap src;
+    GrWrapTextureInBitmap(layer->texture(), layer->texture()->width(), layer->texture()->height(),
+                          false, &src);
 
     if (!layer->filter()->filterImage(&proxy, src, filterContext, &filteredBitmap, &offset)) {
         // Filtering failed. Press on with the unfiltered version.
index 28f27dfc1c7821642a18a3f2050e8954a7a71a21..1fe60407895ac8bebe67d3f24687c6ad0c4d4b8a 100644 (file)
 #include "GrRecordReplaceDraw.h"
 #include "SkBigPicture.h"
 #include "SkCanvasPriv.h"
-#include "SkGrPixelRef.h"
+#include "SkGr.h"
 #include "SkImage.h"
 #include "SkRecordDraw.h"
 #include "SkRecords.h"
 
-static inline void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* result) {
-    SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
-    result->setInfo(info);
-    result->setPixelRef(new SkGrPixelRef(info, texture))->unref();
-}
 
 static inline void draw_replacement_bitmap(GrCachedLayer* layer, SkCanvas* canvas) {
 
@@ -30,10 +25,11 @@ static inline void draw_replacement_bitmap(GrCachedLayer* layer, SkCanvas* canva
     }
 
     SkBitmap bm;
-    wrap_texture(layer->texture(),
-                 !layer->isAtlased() ? layer->rect().width()  : layer->texture()->width(),
-                 !layer->isAtlased() ? layer->rect().height() : layer->texture()->height(),
-                 &bm);
+    GrWrapTextureInBitmap(layer->texture(),
+                          !layer->isAtlased() ? layer->rect().width()  : layer->texture()->width(),
+                          !layer->isAtlased() ? layer->rect().height() : layer->texture()->height(),
+                          false,
+                          &bm);
 
     canvas->save();
     canvas->setMatrix(SkMatrix::I());
index 5de10000857fddbedc6298d341e0112aab87a973..a3f00c1434f43f504d1cae0acf27cb77971169a7 100644 (file)
@@ -641,13 +641,6 @@ void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint
 
 ///////////////////////////////////////////////////////////////////////////////
 
-static SkBitmap wrap_texture(GrTexture* texture, int width, int height) {
-    SkBitmap result;
-    result.setInfo(SkImageInfo::MakeN32Premul(width, height));
-    result.setPixelRef(new SkGrPixelRef(result.info(), texture))->unref();
-    return result;
-}
-
 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
                            const SkPaint& paint, const SkMatrix* prePathMatrix,
                            bool pathIsMutable) {
@@ -1139,8 +1132,9 @@ bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
     SkImageFilter::DeviceProxy proxy(this);
 
     if (filter->canFilterImageGPU()) {
-        return filter->filterImageGPU(&proxy, wrap_texture(texture, width, height),
-                                      ctx, result, offset);
+        SkBitmap bm;
+        GrWrapTextureInBitmap(texture, width, height, false, &bm);
+        return filter->filterImageGPU(&proxy, bm, ctx, result, offset);
     } else {
         return false;
     }