diff options
author | Robert Phillips <robertphillips@google.com> | 2017-03-21 08:48:40 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-21 19:38:55 +0000 |
commit | bbd7a3be407ce94fcc4f8b1eb475de8b6f49026e (patch) | |
tree | 8d2aabdf69316d15483e0af8f86d44c64a2c1a4f | |
parent | 7322b52e616a6cec2ed0e88456c4b43f944b8b69 (diff) |
Make experimental Perlin noise shader take texture proxies
This is split out of: https://skia-review.googlesource.com/c/8823/ (Remove GrFragmentProcessor-derived class' GrTexture-based ctors)
Change-Id: I18c444981f5c72e9688866e045c90844bc4945b1
Reviewed-on: https://skia-review.googlesource.com/9917
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r-- | experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp | 43 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 15 | ||||
-rw-r--r-- | src/gpu/SkGr.h | 5 |
3 files changed, 41 insertions, 22 deletions
diff --git a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp index 22dc0829e4..246d34e9b6 100644 --- a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp +++ b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp @@ -1041,14 +1041,16 @@ private: class GrImprovedPerlinNoiseEffect : public GrFragmentProcessor { public: - static sk_sp<GrFragmentProcessor> Make(int octaves, SkScalar z, + static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, + int octaves, SkScalar z, SkPerlinNoiseShader2::PaintingData* paintingData, - GrTexture* permutationsTexture, - GrTexture* gradientTexture, + sk_sp<GrTextureProxy> permutationsProxy, + sk_sp<GrTextureProxy> gradientProxy, const SkMatrix& matrix) { return sk_sp<GrFragmentProcessor>( - new GrImprovedPerlinNoiseEffect(octaves, z, paintingData, permutationsTexture, - gradientTexture, matrix)); + new GrImprovedPerlinNoiseEffect(resourceProvider, octaves, z, paintingData, + std::move(permutationsProxy), + std::move(gradientProxy), matrix)); } virtual ~GrImprovedPerlinNoiseEffect() { delete fPaintingData; } @@ -1075,15 +1077,17 @@ private: fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency; } - GrImprovedPerlinNoiseEffect(int octaves, SkScalar z, + GrImprovedPerlinNoiseEffect(GrResourceProvider* resourceProvider, + int octaves, SkScalar z, SkPerlinNoiseShader2::PaintingData* paintingData, - GrTexture* permutationsTexture, GrTexture* gradientTexture, + sk_sp<GrTextureProxy> permutationsProxy, + sk_sp<GrTextureProxy> gradientProxy, const SkMatrix& matrix) : INHERITED(kNone_OptimizationFlags) , fOctaves(octaves) , fZ(z) - , fPermutationsSampler(permutationsTexture) - , fGradientSampler(gradientTexture) + , fPermutationsSampler(resourceProvider, std::move(permutationsProxy)) + , fGradientSampler(resourceProvider, std::move(gradientProxy)) , fPaintingData(paintingData) { this->initClassID<GrImprovedPerlinNoiseEffect>(); this->addTextureSampler(&fPermutationsSampler); @@ -1311,15 +1315,18 @@ sk_sp<GrFragmentProcessor> SkPerlinNoiseShader2::asFragmentProcessor(const AsFPA if (fType == kImprovedNoise_Type) { GrSamplerParams textureParams(SkShader::TileMode::kRepeat_TileMode, GrSamplerParams::FilterMode::kNone_FilterMode); - sk_sp<GrTexture> permutationsTexture( - GrRefCachedBitmapTexture(args.fContext, paintingData->getImprovedPermutationsBitmap(), - textureParams, nullptr)); - sk_sp<GrTexture> gradientTexture( - GrRefCachedBitmapTexture(args.fContext, paintingData->getGradientBitmap(), - textureParams, nullptr)); - return GrImprovedPerlinNoiseEffect::Make(fNumOctaves, fSeed, paintingData, - permutationsTexture.get(), - gradientTexture.get(), m); + sk_sp<GrTextureProxy> permutationsTexture( + GrRefCachedBitmapTextureProxy(args.fContext, + paintingData->getImprovedPermutationsBitmap(), + textureParams, nullptr)); + sk_sp<GrTextureProxy> gradientTexture( + GrRefCachedBitmapTextureProxy(args.fContext, + paintingData->getGradientBitmap(), + textureParams, nullptr)); + return GrImprovedPerlinNoiseEffect::Make(args.fContext->resourceProvider(), + fNumOctaves, fSeed, paintingData, + std::move(permutationsTexture), + std::move(gradientTexture), m); } if (0 == fNumOctaves) { diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 18f2abb951..18611edad3 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -308,6 +308,17 @@ GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, nullptr, scaleAdjust); } +sk_sp<GrTextureProxy> GrRefCachedBitmapTextureProxy(GrContext* ctx, + const SkBitmap& bitmap, + const GrSamplerParams& params, + SkScalar scaleAdjust[2]) { + // Caller doesn't care about the texture's color space (they can always get it from the bitmap) + sk_sp<GrTexture> tex(GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, nullptr, + nullptr, + scaleAdjust)); + return GrSurfaceProxy::MakeWrapped(std::move(tex)); +} + sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrResourceProvider* resourceProvider, const SkBitmap& bitmap) { GrUniqueKey originalKey; @@ -332,10 +343,6 @@ sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrResourceProvider* resourceProvid } } - if (!proxy) { - return nullptr; - } - return proxy; } diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h index 993bf839bb..c8990b6a0a 100644 --- a/src/gpu/SkGr.h +++ b/src/gpu/SkGr.h @@ -207,6 +207,11 @@ GR_STATIC_ASSERT(SkXfermode::kCoeffCount == 10); GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrSamplerParams&, SkScalar scaleAdjust[2]); +sk_sp<GrTextureProxy> GrRefCachedBitmapTextureProxy(GrContext*, + const SkBitmap&, + const GrSamplerParams&, + SkScalar scaleAdjust[2]); + /** * Creates a new texture for the bitmap. Does not concern itself with cache keys or texture params. * The bitmap must have CPU-accessible pixels. Attempts to take advantage of faster paths for |