| 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 |
| 15 The radius of the Gaussian blur is specified by the g and b values of the color
, |
| 16 where g is the integer component and b is the fractional component. The r value |
| 17 represents the max final alpha. |
| 14 */ | 18 */ |
| 15 class SkGaussianEdgeShaderImpl : public SkShader { | 19 class SkGaussianEdgeShaderImpl : public SkShader { |
| 16 public: | 20 public: |
| 17 SkGaussianEdgeShaderImpl() {} | 21 SkGaussianEdgeShaderImpl() {} |
| 18 | 22 |
| 19 bool isOpaque() const override; | 23 bool isOpaque() const override; |
| 20 | 24 |
| 21 #if SK_SUPPORT_GPU | 25 #if SK_SUPPORT_GPU |
| 22 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const overri
de; | 26 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const overri
de; |
| 23 #endif | 27 #endif |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 62 } |
| 59 | 63 |
| 60 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor { | 64 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor { |
| 61 public: | 65 public: |
| 62 GLSLGaussianEdgeFP() {} | 66 GLSLGaussianEdgeFP() {} |
| 63 | 67 |
| 64 void emitCode(EmitArgs& args) override { | 68 void emitCode(EmitArgs& args) override { |
| 65 | 69 |
| 66 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 70 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 67 | 71 |
| 68 fragBuilder->codeAppendf("vec4 output = %s;", args.fInputColor); | 72 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); |
| 69 // outside the outer edge | 73 fragBuilder->codeAppend("float radius = color.g*255.0 + color.b;"); |
| 70 fragBuilder->codeAppendf("if (%s.z <= 0) {", fragBuilder->distanceVe
ctorName()); | 74 |
| 71 fragBuilder->codeAppend("output *= 0.0;"); | 75 fragBuilder->codeAppendf("float factor = 1.0 - clamp(%s.z/radius, 0.
0, 1.0);", |
| 72 // inside the stroke | |
| 73 fragBuilder->codeAppendf("} else if (%s.w > 0) {", fragBuilder->dist
anceVectorName()); | |
| 74 fragBuilder->codeAppendf("float factor = %s.w/(%s.z + %s.w);", | |
| 75 fragBuilder->distanceVectorName(), | |
| 76 fragBuilder->distanceVectorName(), | |
| 77 fragBuilder->distanceVectorName()); | 76 fragBuilder->distanceVectorName()); |
| 78 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01
8;"); | 77 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01
8;"); |
| 79 fragBuilder->codeAppend("output *= factor;"); | 78 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color.r);"
, args.fOutputColor); |
| 80 fragBuilder->codeAppend("}"); | |
| 81 fragBuilder->codeAppendf("%s = output;", args.fOutputColor); | |
| 82 } | 79 } |
| 83 | 80 |
| 84 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 81 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
| 85 GrProcessorKeyBuilder* b) { | 82 GrProcessorKeyBuilder* b) { |
| 86 // only one shader generated currently | 83 // only one shader generated currently |
| 87 b->add32(0x0); | 84 b->add32(0x0); |
| 88 } | 85 } |
| 89 | 86 |
| 90 protected: | 87 protected: |
| 91 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override {} | 88 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override {} |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return sk_make_sp<SkGaussianEdgeShaderImpl>(); | 140 return sk_make_sp<SkGaussianEdgeShaderImpl>(); |
| 144 } | 141 } |
| 145 | 142 |
| 146 /////////////////////////////////////////////////////////////////////////////// | 143 /////////////////////////////////////////////////////////////////////////////// |
| 147 | 144 |
| 148 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) | 145 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) |
| 149 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) | 146 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) |
| 150 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 147 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 151 | 148 |
| 152 /////////////////////////////////////////////////////////////////////////////// | 149 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |