| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkGaussianEdgeShader.h" | 8 #include "SkGaussianEdgeShader.h" |
| 9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
| 10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
| 11 | 11 |
| 12 /** \class SkGaussianEdgeShaderImpl | 12 /** \class SkGaussianEdgeShaderImpl |
| 13 This subclass of shader applies a Gaussian to shadow edge | 13 This subclass of shader applies a Gaussian to shadow edge |
| 14 | 14 |
| 15 The radius of the Gaussian blur is specified by the g and b values of the color
, | 15 The radius of the Gaussian blur is specified by the g value of the color, in 6.
2 fixed point. |
| 16 where g is the integer component and b is the fractional component. The r value | 16 For spot shadows, we increase the stroke width to set the shadow against the sh
ape. This pad |
| 17 represents the max final alpha. | 17 is specified by b, also in 6.2 fixed point. The r value represents the max fina
l alpha. |
| 18 The incoming alpha should be 1. |
| 18 */ | 19 */ |
| 19 class SkGaussianEdgeShaderImpl : public SkShader { | 20 class SkGaussianEdgeShaderImpl : public SkShader { |
| 20 public: | 21 public: |
| 21 SkGaussianEdgeShaderImpl() {} | 22 SkGaussianEdgeShaderImpl() {} |
| 22 | 23 |
| 23 bool isOpaque() const override; | 24 bool isOpaque() const override; |
| 24 | 25 |
| 25 #if SK_SUPPORT_GPU | 26 #if SK_SUPPORT_GPU |
| 26 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const overri
de; | 27 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const overri
de; |
| 27 #endif | 28 #endif |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 64 |
| 64 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor { | 65 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor { |
| 65 public: | 66 public: |
| 66 GLSLGaussianEdgeFP() {} | 67 GLSLGaussianEdgeFP() {} |
| 67 | 68 |
| 68 void emitCode(EmitArgs& args) override { | 69 void emitCode(EmitArgs& args) override { |
| 69 | 70 |
| 70 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 71 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 71 | 72 |
| 72 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); | 73 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); |
| 73 fragBuilder->codeAppend("float radius = color.g*255.0 + color.b;"); | 74 fragBuilder->codeAppend("float radius = color.g*64.0;"); |
| 75 fragBuilder->codeAppend("float pad = color.b*64.0;"); |
| 74 | 76 |
| 75 fragBuilder->codeAppendf("float factor = 1.0 - clamp(%s.z/radius, 0.
0, 1.0);", | 77 fragBuilder->codeAppendf("float factor = 1.0 - clamp((%s.z - pad)/ra
dius, 0.0, 1.0);", |
| 76 fragBuilder->distanceVectorName()); | 78 fragBuilder->distanceVectorName()); |
| 77 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01
8;"); | 79 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01
8;"); |
| 78 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color.r);"
, args.fOutputColor); | 80 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color.r);"
, args.fOutputColor); |
| 79 } | 81 } |
| 80 | 82 |
| 81 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 83 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
| 82 GrProcessorKeyBuilder* b) { | 84 GrProcessorKeyBuilder* b) { |
| 83 // only one shader generated currently | 85 // only one shader generated currently |
| 84 b->add32(0x0); | 86 b->add32(0x0); |
| 85 } | 87 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return sk_make_sp<SkGaussianEdgeShaderImpl>(); | 142 return sk_make_sp<SkGaussianEdgeShaderImpl>(); |
| 141 } | 143 } |
| 142 | 144 |
| 143 /////////////////////////////////////////////////////////////////////////////// | 145 /////////////////////////////////////////////////////////////////////////////// |
| 144 | 146 |
| 145 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) | 147 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) |
| 146 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) | 148 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) |
| 147 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 149 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 148 | 150 |
| 149 /////////////////////////////////////////////////////////////////////////////// | 151 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |