Expand use of GrMakeCachedBitmapProxy
authorRobert Phillips <robertphillips@google.com>
Fri, 17 Feb 2017 18:00:28 +0000 (13:00 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 17 Feb 2017 19:15:51 +0000 (19:15 +0000)
Change-Id: Ic276b9d772763dc16ac6b15a0896578d2d02e06e
Reviewed-on: https://skia-review.googlesource.com/8666
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>

experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
src/core/SkSpecialImage.cpp
src/effects/SkPerlinNoiseShader.cpp
src/effects/SkTableColorFilter.cpp

index 898f49b..980593f 100644 (file)
@@ -20,6 +20,7 @@
 #include "GrContext.h"
 #include "GrCoordTransform.h"
 #include "SkGr.h"
+#include "SkGrPriv.h"
 #include "effects/GrConstColorProcessor.h"
 #include "glsl/GrGLSLFragmentProcessor.h"
 #include "glsl/GrGLSLFragmentShaderBuilder.h"
@@ -621,14 +622,16 @@ private:
 
 class GrPerlinNoise2Effect : public GrFragmentProcessor {
 public:
-    static sk_sp<GrFragmentProcessor> Make(SkPerlinNoiseShader2::Type type,
+    static sk_sp<GrFragmentProcessor> Make(GrTextureProvider* textureProvider,
+                                           SkPerlinNoiseShader2::Type type,
                                            int numOctaves, bool stitchTiles,
                                            SkPerlinNoiseShader2::PaintingData* paintingData,
-                                           GrTexture* permutationsTexture, GrTexture* noiseTexture,
+                                           sk_sp<GrTextureProxy> permutationsProxy,
+                                           sk_sp<GrTextureProxy> noiseProxy,
                                            const SkMatrix& matrix) {
         return sk_sp<GrFragmentProcessor>(
-            new GrPerlinNoise2Effect(type, numOctaves, stitchTiles, paintingData,
-                                     permutationsTexture, noiseTexture, matrix));
+            new GrPerlinNoise2Effect(textureProvider, type, numOctaves, stitchTiles, paintingData,
+                                     std::move(permutationsProxy), std::move(noiseProxy), matrix));
     }
 
     virtual ~GrPerlinNoise2Effect() { delete fPaintingData; }
@@ -662,16 +665,18 @@ private:
                fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataInit;
     }
 
-    GrPerlinNoise2Effect(SkPerlinNoiseShader2::Type type, int numOctaves, bool stitchTiles,
+    GrPerlinNoise2Effect(GrTextureProvider* textureProvider,
+                         SkPerlinNoiseShader2::Type type, int numOctaves, bool stitchTiles,
                          SkPerlinNoiseShader2::PaintingData* paintingData,
-                         GrTexture* permutationsTexture, GrTexture* noiseTexture,
+                         sk_sp<GrTextureProxy> permutationsProxy,
+                         sk_sp<GrTextureProxy> noiseProxy,
                          const SkMatrix& matrix)
             : INHERITED(kNone_OptimizationFlags)
             , fType(type)
             , fNumOctaves(numOctaves)
             , fStitchTiles(stitchTiles)
-            , fPermutationsSampler(permutationsTexture)
-            , fNoiseSampler(noiseTexture)
+            , fPermutationsSampler(textureProvider, std::move(permutationsProxy))
+            , fNoiseSampler(textureProvider, std::move(noiseProxy))
             , fPaintingData(paintingData) {
         this->initClassID<GrPerlinNoise2Effect>();
         this->addTextureSampler(&fPermutationsSampler);
@@ -1334,20 +1339,21 @@ sk_sp<GrFragmentProcessor> SkPerlinNoiseShader2::asFragmentProcessor(const AsFPA
                                            GrConstColorProcessor::kIgnore_InputMode);
     }
 
-    sk_sp<GrTexture> permutationsTexture(
-        GrRefCachedBitmapTexture(args.fContext, paintingData->getPermutationsBitmap(),
-                                 GrSamplerParams::ClampNoFilter(), nullptr));
-    sk_sp<GrTexture> noiseTexture(
-        GrRefCachedBitmapTexture(args.fContext, paintingData->getNoiseBitmap(),
-                                 GrSamplerParams::ClampNoFilter(), nullptr));
+    sk_sp<GrTextureProxy> permutationsProxy = GrMakeCachedBitmapProxy(
+                                                         args.fContext,
+                                                         paintingData->getPermutationsBitmap());
+    sk_sp<GrTextureProxy> noiseProxy = GrMakeCachedBitmapProxy(args.fContext,
+                                                               paintingData->getNoiseBitmap());
 
-    if ((permutationsTexture) && (noiseTexture)) {
+    if (permutationsProxy && noiseProxy) {
         sk_sp<GrFragmentProcessor> inner(
-            GrPerlinNoise2Effect::Make(fType,
+            GrPerlinNoise2Effect::Make(args.fContext->textureProvider(),
+                                       fType,
                                        fNumOctaves,
                                        fStitchTiles,
                                        paintingData,
-                                       permutationsTexture.get(), noiseTexture.get(),
+                                       std::move(permutationsProxy),
+                                       std::move(noiseProxy),
                                        m));
         return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
     }
index cef87b7..0ae84d3 100644 (file)
@@ -261,9 +261,7 @@ public:
 
     sk_sp<GrTextureProxy> onAsTextureProxy(GrContext* context) const override {
         if (context) {
-            sk_sp<GrTexture> tex(sk_ref_sp(GrRefCachedBitmapTexture(
-                context, fBitmap, GrSamplerParams::ClampNoFilter(), nullptr)));
-            return GrSurfaceProxy::MakeWrapped(std::move(tex));
+            return GrMakeCachedBitmapProxy(context, fBitmap);
         }
 
         return nullptr;
index b67fb34..5f8fe32 100644 (file)
@@ -19,6 +19,7 @@
 #include "GrContext.h"
 #include "GrCoordTransform.h"
 #include "SkGr.h"
+#include "SkGrPriv.h"
 #include "effects/GrConstColorProcessor.h"
 #include "glsl/GrGLSLFragmentProcessor.h"
 #include "glsl/GrGLSLFragmentShaderBuilder.h"
@@ -485,14 +486,16 @@ private:
 
 class GrPerlinNoiseEffect : public GrFragmentProcessor {
 public:
-    static sk_sp<GrFragmentProcessor> Make(SkPerlinNoiseShader::Type type,
+    static sk_sp<GrFragmentProcessor> Make(GrTextureProvider* textureProvider,
+                                           SkPerlinNoiseShader::Type type,
                                            int numOctaves, bool stitchTiles,
                                            SkPerlinNoiseShader::PaintingData* paintingData,
-                                           GrTexture* permutationsTexture, GrTexture* noiseTexture,
+                                           sk_sp<GrTextureProxy> permutationsProxy,
+                                           sk_sp<GrTextureProxy> noiseProxy,
                                            const SkMatrix& matrix) {
         return sk_sp<GrFragmentProcessor>(
-            new GrPerlinNoiseEffect(type, numOctaves, stitchTiles, paintingData,
-                                    permutationsTexture, noiseTexture, matrix));
+            new GrPerlinNoiseEffect(textureProvider, type, numOctaves, stitchTiles, paintingData,
+                                    std::move(permutationsProxy), std::move(noiseProxy), matrix));
     }
 
     virtual ~GrPerlinNoiseEffect() { delete fPaintingData; }
@@ -525,17 +528,18 @@ private:
                fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataInit;
     }
 
-    GrPerlinNoiseEffect(SkPerlinNoiseShader::Type type, int numOctaves, bool stitchTiles,
+    GrPerlinNoiseEffect(GrTextureProvider* textureProvider,
+                        SkPerlinNoiseShader::Type type, int numOctaves, bool stitchTiles,
                         SkPerlinNoiseShader::PaintingData* paintingData,
-                        GrTexture* permutationsTexture, GrTexture* noiseTexture,
+                        sk_sp<GrTextureProxy> permutationsProxy, sk_sp<GrTextureProxy> noiseProxy,
                         const SkMatrix& matrix)
             : INHERITED(kNone_OptimizationFlags)
             , fType(type)
             , fCoordTransform(matrix)
             , fNumOctaves(numOctaves)
             , fStitchTiles(stitchTiles)
-            , fPermutationsSampler(permutationsTexture)
-            , fNoiseSampler(noiseTexture)
+            , fPermutationsSampler(textureProvider, std::move(permutationsProxy))
+            , fNoiseSampler(textureProvider, std::move(noiseProxy))
             , fPaintingData(paintingData) {
         this->initClassID<GrPerlinNoiseEffect>();
         this->addTextureSampler(&fPermutationsSampler);
@@ -911,23 +915,24 @@ sk_sp<GrFragmentProcessor> SkPerlinNoiseShader::asFragmentProcessor(const AsFPAr
 
     SkPerlinNoiseShader::PaintingData* paintingData =
             new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix);
-    sk_sp<GrTexture> permutationsTexture(
-        GrRefCachedBitmapTexture(args.fContext, paintingData->getPermutationsBitmap(),
-                                 GrSamplerParams::ClampNoFilter(), nullptr));
-    sk_sp<GrTexture> noiseTexture(
-        GrRefCachedBitmapTexture(args.fContext, paintingData->getNoiseBitmap(),
-                                 GrSamplerParams::ClampNoFilter(), nullptr));
+    sk_sp<GrTextureProxy> permutationsProxy(GrMakeCachedBitmapProxy(
+                                                            args.fContext,
+                                                            paintingData->getPermutationsBitmap()));
+    sk_sp<GrTextureProxy> noiseProxy(GrMakeCachedBitmapProxy(args.fContext,
+                                                             paintingData->getNoiseBitmap()));
 
     SkMatrix m = *args.fViewMatrix;
     m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1);
     m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1);
-    if ((permutationsTexture) && (noiseTexture)) {
+    if (permutationsProxy && noiseProxy) {
         sk_sp<GrFragmentProcessor> inner(
-            GrPerlinNoiseEffect::Make(fType,
+            GrPerlinNoiseEffect::Make(args.fContext->textureProvider(),
+                                      fType,
                                       fNumOctaves,
                                       fStitchTiles,
                                       paintingData,
-                                      permutationsTexture.get(), noiseTexture.get(),
+                                      std::move(permutationsProxy),
+                                      std::move(noiseProxy),
                                       m));
         return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
     }
index 8960449..8e660f8 100644 (file)
@@ -10,6 +10,7 @@
 #include "SkArenaAlloc.h"
 #include "SkBitmap.h"
 #include "SkColorPriv.h"
+#include "SkGrPriv.h"
 #include "SkRasterPipeline.h"
 #include "SkReadBuffer.h"
 #include "SkString.h"
@@ -370,7 +371,9 @@ sk_sp<SkColorFilter> SkTable_ColorFilter::makeComposed(sk_sp<SkColorFilter> inne
 
 class ColorTableEffect : public GrFragmentProcessor {
 public:
-    static sk_sp<GrFragmentProcessor> Make(GrContext* context, SkBitmap bitmap, unsigned flags);
+    static sk_sp<GrFragmentProcessor> Make(GrContext* context,
+                                           const SkBitmap& bitmap,
+                                           unsigned flags);
 
     virtual ~ColorTableEffect();
 
@@ -480,7 +483,7 @@ void GLColorTableEffect::emitCode(EmitArgs& args) {
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-sk_sp<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context, SkBitmap bitmap,
+sk_sp<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context, const SkBitmap& bitmap,
                                                   unsigned flags) {
 
     GrTextureStripAtlas::Desc desc;
@@ -494,12 +497,19 @@ sk_sp<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context, SkBitmap b
     sk_sp<GrTexture> texture;
     if (-1 == row) {
         atlas = nullptr;
-        texture.reset(
-            GrRefCachedBitmapTexture(context, bitmap, GrSamplerParams::ClampNoFilter(), nullptr));
+
+        sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(context, bitmap);
+        if (proxy) {
+            texture.reset(proxy->instantiate(context->textureProvider()));
+        }
     } else {
         texture.reset(SkRef(atlas->getTexture()));
     }
 
+    if (!texture) {
+        return nullptr;
+    }
+
     return sk_sp<GrFragmentProcessor>(new ColorTableEffect(texture.get(), atlas, row, flags));
 }