diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h index e539714b34..18af9a42fb 100644 --- a/include/core/SkColorFilter.h +++ b/include/core/SkColorFilter.h @@ -61,10 +61,10 @@ public: bool appendStages(const SkStageRec& rec, bool shaderIsOpaque) const; - virtual bool program(skvm::Builder*, - SkColorSpace* dstCS, - skvm::Uniforms* uniforms, - skvm::F32* r, skvm::F32* g, skvm::F32* b, skvm::F32* a) const; + bool program(skvm::Builder*, + SkColorSpace* dstCS, + skvm::Uniforms* uniforms, + skvm::F32* r, skvm::F32* g, skvm::F32* b, skvm::F32* a) const; enum Flags { /** If set the filter methods will not change the alpha channel of the colors. @@ -148,6 +148,11 @@ private: virtual bool onAppendStages(const SkStageRec& rec, bool shaderIsOpaque) const = 0; + virtual bool onProgram(skvm::Builder*, + SkColorSpace* dstCS, + skvm::Uniforms* uniforms, + skvm::F32* r, skvm::F32* g, skvm::F32* b, skvm::F32* a) const; + friend class SkComposeColorFilter; typedef SkFlattenable INHERITED; diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp index 844f8bf0bb..4c88a85986 100644 --- a/src/core/SkColorFilter.cpp +++ b/src/core/SkColorFilter.cpp @@ -45,10 +45,24 @@ bool SkColorFilter::appendStages(const SkStageRec& rec, bool shaderIsOpaque) con return this->onAppendStages(rec, shaderIsOpaque); } -bool SkColorFilter::program(skvm::Builder*, +bool SkColorFilter::program(skvm::Builder* p, SkColorSpace* dstCS, skvm::Uniforms* uniforms, skvm::F32* r, skvm::F32* g, skvm::F32* b, skvm::F32* a) const { + skvm::F32 original = *a; + if (this->onProgram(p, dstCS, uniforms, r,g,b,a)) { + if (this->getFlags() & kAlphaUnchanged_Flag) { + *a = original; + } + return true; + } + return false; +} + +bool SkColorFilter::onProgram(skvm::Builder*, + SkColorSpace* dstCS, + skvm::Uniforms* uniforms, + skvm::F32* r, skvm::F32* g, skvm::F32* b, skvm::F32* a) const { return false; } diff --git a/src/core/SkColorFilter_Matrix.cpp b/src/core/SkColorFilter_Matrix.cpp index 53368fbdf8..aaf808c049 100644 --- a/src/core/SkColorFilter_Matrix.cpp +++ b/src/core/SkColorFilter_Matrix.cpp @@ -79,10 +79,10 @@ bool SkColorFilter_Matrix::onAppendStages(const SkStageRec& rec, bool shaderIsOp return true; } -bool SkColorFilter_Matrix::program(skvm::Builder* p, - SkColorSpace* /*dstCS*/, - skvm::Uniforms* uniforms, - skvm::F32* r, skvm::F32* g, skvm::F32* b, skvm::F32* a) const { +bool SkColorFilter_Matrix::onProgram(skvm::Builder* p, + SkColorSpace* /*dstCS*/, + skvm::Uniforms* uniforms, + skvm::F32* r, skvm::F32* g, skvm::F32* b, skvm::F32* a) const { // TODO: specialize generated code on the 0/1 values of fMatrix? if (fDomain == Domain::kRGBA) { // Unpremul. diff --git a/src/core/SkColorFilter_Matrix.h b/src/core/SkColorFilter_Matrix.h index 5fe5dd83d1..87a3095d2e 100644 --- a/src/core/SkColorFilter_Matrix.h +++ b/src/core/SkColorFilter_Matrix.h @@ -33,10 +33,10 @@ private: SK_FLATTENABLE_HOOKS(SkColorFilter_Matrix) bool onAppendStages(const SkStageRec& rec, bool shaderIsOpaque) const override; - bool program(skvm::Builder*, - SkColorSpace* dstCS, - skvm::Uniforms* uniforms, - skvm::F32* r, skvm::F32* g, skvm::F32* b, skvm::F32* a) const override; + bool onProgram(skvm::Builder*, + SkColorSpace* dstCS, + skvm::Uniforms* uniforms, + skvm::F32* r, skvm::F32* g, skvm::F32* b, skvm::F32* a) const override; float fMatrix[20]; uint16_t fFlags;