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" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 // enable output of distance information for shape | 61 // enable output of distance information for shape |
62 fUsesDistanceVectorField = true; | 62 fUsesDistanceVectorField = true; |
63 } | 63 } |
64 | 64 |
65 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor { | 65 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor { |
66 public: | 66 public: |
67 GLSLGaussianEdgeFP() {} | 67 GLSLGaussianEdgeFP() {} |
68 | 68 |
69 void emitCode(EmitArgs& args) override { | 69 void emitCode(EmitArgs& args) override { |
70 | |
71 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 70 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
72 | 71 |
73 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); | 72 if (!args.fGpImplementsDistanceVector) { |
74 fragBuilder->codeAppend("float radius = color.g*64.0;"); | 73 fragBuilder->codeAppendf("// GP does not implement fsDistanceVec
tor - " |
75 fragBuilder->codeAppend("float pad = color.b*64.0;"); | 74 " returning grey in GLSLGaussianEdgeFP\
n"); |
| 75 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); |
| 76 fragBuilder->codeAppendf("%s = vec4(0, 0, 0, color.r);", args.fO
utputColor); |
| 77 } else { |
| 78 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); |
| 79 fragBuilder->codeAppend("float radius = color.g*64.0;"); |
| 80 fragBuilder->codeAppend("float pad = color.b*64.0;"); |
76 | 81 |
77 fragBuilder->codeAppendf("float factor = 1.0 - clamp((%s.z - pad)/ra
dius, 0.0, 1.0);", | 82 fragBuilder->codeAppendf("float factor = 1.0 - clamp((%s.z - pad
)/radius," |
78 fragBuilder->distanceVectorName()); | 83 "0.0, 1.0);"
, |
79 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01
8;"); | 84 fragBuilder->distanceVectorName()); |
80 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color.r);"
, args.fOutputColor); | 85 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) -
0.018;"); |
| 86 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color.
r);", |
| 87 args.fOutputColor); |
| 88 } |
81 } | 89 } |
82 | 90 |
83 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 91 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
84 GrProcessorKeyBuilder* b) { | 92 GrProcessorKeyBuilder* b) { |
85 // only one shader generated currently | 93 // only one shader generated currently |
86 b->add32(0x0); | 94 b->add32(0x0); |
87 } | 95 } |
88 | 96 |
89 protected: | 97 protected: |
90 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override {} | 98 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override {} |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 void SkGaussianEdgeShaderImpl::toString(SkString* str) const { | 134 void SkGaussianEdgeShaderImpl::toString(SkString* str) const { |
127 str->appendf("GaussianEdgeShader: ()"); | 135 str->appendf("GaussianEdgeShader: ()"); |
128 } | 136 } |
129 #endif | 137 #endif |
130 | 138 |
131 sk_sp<SkFlattenable> SkGaussianEdgeShaderImpl::CreateProc(SkReadBuffer& buf) { | 139 sk_sp<SkFlattenable> SkGaussianEdgeShaderImpl::CreateProc(SkReadBuffer& buf) { |
132 return sk_make_sp<SkGaussianEdgeShaderImpl>(); | 140 return sk_make_sp<SkGaussianEdgeShaderImpl>(); |
133 } | 141 } |
134 | 142 |
135 void SkGaussianEdgeShaderImpl::flatten(SkWriteBuffer& buf) const { | 143 void SkGaussianEdgeShaderImpl::flatten(SkWriteBuffer& buf) const { |
136 this->INHERITED::flatten(buf); | |
137 } | 144 } |
138 | 145 |
139 /////////////////////////////////////////////////////////////////////////////// | 146 /////////////////////////////////////////////////////////////////////////////// |
140 | 147 |
141 sk_sp<SkShader> SkGaussianEdgeShader::Make() { | 148 sk_sp<SkShader> SkGaussianEdgeShader::Make() { |
142 return sk_make_sp<SkGaussianEdgeShaderImpl>(); | 149 return sk_make_sp<SkGaussianEdgeShaderImpl>(); |
143 } | 150 } |
144 | 151 |
145 /////////////////////////////////////////////////////////////////////////////// | 152 /////////////////////////////////////////////////////////////////////////////// |
146 | 153 |
147 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) | 154 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) |
148 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) | 155 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) |
149 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 156 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
150 | 157 |
151 /////////////////////////////////////////////////////////////////////////////// | 158 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |