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>
diff --git a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
index 22dc082..246d34e 100644
--- a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
+++ b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
@@ -1041,14 +1041,16 @@
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 @@
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 @@
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 18f2abb..18611ed 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -308,6 +308,17 @@
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 @@
}
}
- if (!proxy) {
- return nullptr;
- }
-
return proxy;
}
diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h
index 993bf83..c8990b6 100644
--- a/src/gpu/SkGr.h
+++ b/src/gpu/SkGr.h
@@ -207,6 +207,11 @@
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