Add GrFragmentProcessor::clone(), implementation for ColorTableEffect, and unit test.
We occasionally make copies of GrPaints. clone() fill facilitate this case when GrFragmentProcessors are non-shareable..
Change-Id: I004e34f6ce8c293f9e0664d26532e44bd6b9fdff
Reviewed-on: https://skia-review.googlesource.com/26360
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 2e8e57e..34c962c 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -323,9 +323,7 @@
class ColorTableEffect : public GrFragmentProcessor {
public:
- static sk_sp<GrFragmentProcessor> Make(GrContext* context,
- const SkBitmap& bitmap,
- unsigned flags);
+ static sk_sp<GrFragmentProcessor> Make(GrContext* context, const SkBitmap& bitmap);
~ColorTableEffect() override;
@@ -334,6 +332,8 @@
const GrTextureStripAtlas* atlas() const { return fAtlas; }
int atlasRow() const { return fRow; }
+ sk_sp<GrFragmentProcessor> clone() override;
+
private:
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
@@ -341,8 +341,7 @@
bool onIsEqual(const GrFragmentProcessor&) const override;
- ColorTableEffect(sk_sp<GrTextureProxy> proxy,
- GrTextureStripAtlas* atlas, int row, unsigned flags);
+ ColorTableEffect(sk_sp<GrTextureProxy> proxy, GrTextureStripAtlas* atlas, int row);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
@@ -437,9 +436,7 @@
}
///////////////////////////////////////////////////////////////////////////////
-sk_sp<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context, const SkBitmap& bitmap,
- unsigned flags) {
-
+sk_sp<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context, const SkBitmap& bitmap) {
GrTextureStripAtlas::Desc desc;
desc.fWidth = bitmap.width();
desc.fHeight = 128;
@@ -463,11 +460,10 @@
return nullptr;
}
- return sk_sp<GrFragmentProcessor>(new ColorTableEffect(std::move(proxy), atlas, row, flags));
+ return sk_sp<GrFragmentProcessor>(new ColorTableEffect(std::move(proxy), atlas, row));
}
-ColorTableEffect::ColorTableEffect(sk_sp<GrTextureProxy> proxy,
- GrTextureStripAtlas* atlas, int row, unsigned flags)
+ColorTableEffect::ColorTableEffect(sk_sp<GrTextureProxy> proxy, GrTextureStripAtlas* atlas, int row)
: INHERITED(kNone_OptimizationFlags) // Not bothering with table-specific optimizations.
, fTextureSampler(std::move(proxy))
, fAtlas(atlas)
@@ -482,6 +478,12 @@
}
}
+sk_sp<GrFragmentProcessor> ColorTableEffect::clone() {
+ fAtlas->lockRow(fRow);
+ return sk_sp<GrFragmentProcessor>(
+ new ColorTableEffect(sk_ref_sp(fTextureSampler.proxy()), fAtlas, fRow));
+}
+
void ColorTableEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
GLColorTableEffect::GenKey(*this, caps, b);
@@ -539,7 +541,7 @@
SkBitmap bitmap;
this->asComponentTable(&bitmap);
- return ColorTableEffect::Make(context, bitmap, fFlags);
+ return ColorTableEffect::Make(context, bitmap);
}
#endif // SK_SUPPORT_GPU