diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-07-14 16:17:04 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-14 20:46:34 +0000 |
commit | 0274b30feeacae0bcd12f03ae96cb4721c1393a2 (patch) | |
tree | 24b8932516009d057d898a5741e73c192b32c21a | |
parent | 91982ee8d92a80193915d59760e2ba9ce6f46989 (diff) |
converted GrBlurredEdgeFragmentProcessor to sksl
Bug: skia:
Change-Id: I028c85f692b2e54e64be301940708387014ee0c7
Reviewed-on: https://skia-review.googlesource.com/23540
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
-rw-r--r-- | gn/sksl.gni | 1 | ||||
-rw-r--r-- | src/gpu/effects/GrBlurredEdgeFragmentProcessor.cpp | 66 | ||||
-rw-r--r-- | src/gpu/effects/GrBlurredEdgeFragmentProcessor.fp | 28 | ||||
-rw-r--r-- | src/gpu/effects/GrBlurredEdgeFragmentProcessor.h | 66 | ||||
-rw-r--r-- | src/utils/SkShadowUtils.cpp | 2 |
5 files changed, 79 insertions, 84 deletions
diff --git a/gn/sksl.gni b/gn/sksl.gni index a349d9b87d..c1b6abaf02 100644 --- a/gn/sksl.gni +++ b/gn/sksl.gni @@ -26,6 +26,7 @@ skia_sksl_sources = [ skia_gpu_processor_sources = [ "$_src/effects/GrAlphaThresholdFragmentProcessor.fp", "$_src/effects/GrCircleBlurFragmentProcessor.fp", + "$_src/gpu/effects/GrBlurredEdgeFragmentProcessor.fp", "$_src/gpu/effects/GrCircleEffect.fp", "$_src/gpu/effects/GrDitherEffect.fp", "$_src/gpu/effects/GrEllipseEffect.fp", diff --git a/src/gpu/effects/GrBlurredEdgeFragmentProcessor.cpp b/src/gpu/effects/GrBlurredEdgeFragmentProcessor.cpp index 1996a942c2..a66de57e7a 100644 --- a/src/gpu/effects/GrBlurredEdgeFragmentProcessor.cpp +++ b/src/gpu/effects/GrBlurredEdgeFragmentProcessor.cpp @@ -5,54 +5,40 @@ * found in the LICENSE file. */ -#include "effects/GrBlurredEdgeFragmentProcessor.h" - +/* + * This file was autogenerated from GrBlurredEdgeFragmentProcessor.fp; do not modify. + */ +#include "GrBlurredEdgeFragmentProcessor.h" +#if SK_SUPPORT_GPU +#include "glsl/GrGLSLColorSpaceXformHelper.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" - -class GLSLBlurredEdgeFP : public GrGLSLFragmentProcessor { +#include "glsl/GrGLSLProgramBuilder.h" +#include "SkSLCPP.h" +#include "SkSLUtil.h" +class GrGLSLBlurredEdgeFragmentProcessor : public GrGLSLFragmentProcessor { public: - GLSLBlurredEdgeFP() {} - + GrGLSLBlurredEdgeFragmentProcessor() {} void emitCode(EmitArgs& args) override { - - GrBlurredEdgeFP::Mode mode = args.fFp.cast<GrBlurredEdgeFP>().mode(); - GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; - - fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); - fragBuilder->codeAppendf("// assuming interpolant is set in vertex colors\n"); - fragBuilder->codeAppendf("float factor = 1.0 - color.a;"); - switch (mode) { - case GrBlurredEdgeFP::kGaussian_Mode: - fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.018;"); - break; - case GrBlurredEdgeFP::kSmoothstep_Mode: - fragBuilder->codeAppend("factor = smoothstep(1.0, 0.0, factor);"); - break; - } - fragBuilder->codeAppendf("%s = vec4(factor);", args.fOutputColor); + const GrBlurredEdgeFragmentProcessor& _outer = args.fFp.cast<GrBlurredEdgeFragmentProcessor>(); + (void) _outer; + fragBuilder->codeAppendf("float factor = 1.0 - %s.w;\n@switch (%d) {\n case 0:\n factor = exp((-factor * factor) * 4.0) - 0.017999999999999999;\n break;\n case 1:\n factor = smoothstep(1.0, 0.0, factor);\n break;\n}\n%s = vec4(factor);\n", args.fInputColor ? args.fInputColor : "vec4(1)", _outer.mode(), args.fOutputColor); + } +private: + void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override { } - -protected: - void onSetData(const GrGLSLProgramDataManager& pdman, - const GrFragmentProcessor& proc) override {} - - GrBlurredEdgeFP::Mode fMode; }; - -GrGLSLFragmentProcessor* GrBlurredEdgeFP::onCreateGLSLInstance() const { - return new GLSLBlurredEdgeFP(); +GrGLSLFragmentProcessor* GrBlurredEdgeFragmentProcessor::onCreateGLSLInstance() const { + return new GrGLSLBlurredEdgeFragmentProcessor(); } - -void GrBlurredEdgeFP::onGetGLSLProcessorKey(const GrShaderCaps& caps, - GrProcessorKeyBuilder* b) const { +void GrBlurredEdgeFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const { b->add32(fMode); } - -bool GrBlurredEdgeFP::onIsEqual(const GrFragmentProcessor& other) const { - const GrBlurredEdgeFP& that = other.cast<GrBlurredEdgeFP>(); - return that.fMode == fMode; +bool GrBlurredEdgeFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const { + const GrBlurredEdgeFragmentProcessor& that = other.cast<GrBlurredEdgeFragmentProcessor>(); + (void) that; + if (fMode != that.fMode) return false; + return true; } - - +#endif diff --git a/src/gpu/effects/GrBlurredEdgeFragmentProcessor.fp b/src/gpu/effects/GrBlurredEdgeFragmentProcessor.fp new file mode 100644 index 0000000000..2c4d5ef582 --- /dev/null +++ b/src/gpu/effects/GrBlurredEdgeFragmentProcessor.fp @@ -0,0 +1,28 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +@class { + enum Mode { + kGaussian_Mode = 0, + kSmoothStep_Mode = 1 + }; +} + +layout(key) in int mode; + +void main() { + float factor = 1.0 - sk_InColor.a; + @switch (mode) { + case 0: // kGaussian_Mode + factor = exp(-factor * factor * 4.0) - 0.018; + break; + case 1: // kSmoothstep_Mode + factor = smoothstep(1.0, 0.0, factor); + break; + } + sk_OutColor = vec4(factor); +} diff --git a/src/gpu/effects/GrBlurredEdgeFragmentProcessor.h b/src/gpu/effects/GrBlurredEdgeFragmentProcessor.h index 85504fdc2b..d81ae2318c 100644 --- a/src/gpu/effects/GrBlurredEdgeFragmentProcessor.h +++ b/src/gpu/effects/GrBlurredEdgeFragmentProcessor.h @@ -5,61 +5,41 @@ * found in the LICENSE file. */ +/* + * This file was autogenerated from GrBlurredEdgeFragmentProcessor.fp; do not modify. + */ #ifndef GrBlurredEdgeFragmentProcessor_DEFINED #define GrBlurredEdgeFragmentProcessor_DEFINED - +#include "SkTypes.h" +#if SK_SUPPORT_GPU #include "GrFragmentProcessor.h" - -/** - * Shader for managing a blurred edge for a shadow. - * - * There are two blurring modes supported: Gaussian blur function and smoothstep function. - * - * If the primitive supports an implicit distance to the edge, the radius of the blur is specified - * by r & g values of the color in 14.2 fixed point. For spot shadows, we increase the stroke width - * to set the shadow against the shape. This pad is specified by b, also in 6.2 fixed point. - * The a value represents the max final alpha. - * - * When not using implicit distance, then b in the input color represents the input to the - * blur function, and r the max final alpha. - * - */ -class GrBlurredEdgeFP : public GrFragmentProcessor { +#include "GrCoordTransform.h" +#include "GrColorSpaceXform.h" +#include "effects/GrProxyMove.h" +class GrBlurredEdgeFragmentProcessor : public GrFragmentProcessor { public: - enum Mode { - kGaussian_Mode, - kSmoothstep_Mode, - kLastMode = kSmoothstep_Mode + enum Mode { + kGaussian_Mode = 0, + kSmoothStep_Mode = 1 }; - static const int kModeCnt = kLastMode + 1; - - static sk_sp<GrFragmentProcessor> Make(Mode mode = kGaussian_Mode) { - return sk_sp<GrFragmentProcessor>(new GrBlurredEdgeFP(mode)); + int mode() const { return fMode; } + static sk_sp<GrFragmentProcessor> Make(int mode) { + return sk_sp<GrFragmentProcessor>(new GrBlurredEdgeFragmentProcessor(mode)); } - - const char* name() const override { return "BlurredEdge"; } - - Mode mode() const { return fMode; } - + const char* name() const override { return "BlurredEdgeFragmentProcessor"; } private: - GrBlurredEdgeFP(Mode mode) - : INHERITED(kNone_OptimizationFlags) - , fMode(mode) { - this->initClassID<GrBlurredEdgeFP>(); + GrBlurredEdgeFragmentProcessor(int mode) + : INHERITED(kNone_OptimizationFlags) + , fMode(mode) { + this->initClassID<GrBlurredEdgeFragmentProcessor>(); } - GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; - - void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; - + void onGetGLSLProcessorKey(const GrShaderCaps&,GrProcessorKeyBuilder*) const override; bool onIsEqual(const GrFragmentProcessor&) const override; - GR_DECLARE_FRAGMENT_PROCESSOR_TEST - - Mode fMode; - + int fMode; typedef GrFragmentProcessor INHERITED; }; - +#endif #endif diff --git a/src/utils/SkShadowUtils.cpp b/src/utils/SkShadowUtils.cpp index 11bcd7552c..ceeb191f10 100644 --- a/src/utils/SkShadowUtils.cpp +++ b/src/utils/SkShadowUtils.cpp @@ -70,7 +70,7 @@ void SkGaussianColorFilter::toString(SkString* str) const { sk_sp<GrFragmentProcessor> SkGaussianColorFilter::asFragmentProcessor(GrContext*, SkColorSpace*) const { - return GrBlurredEdgeFP::Make(GrBlurredEdgeFP::kGaussian_Mode); + return GrBlurredEdgeFragmentProcessor::Make(GrBlurredEdgeFragmentProcessor::kGaussian_Mode); } #endif |