| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkAlphaThresholdFilter.h" | 8 #include "SkAlphaThresholdFilter.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) { | 141 void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) { |
| 142 fInnerThresholdVar = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, | 142 fInnerThresholdVar = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, |
| 143 kFloat_GrSLType, kDefault_GrS
LPrecision, | 143 kFloat_GrSLType, kDefault_GrS
LPrecision, |
| 144 "inner_threshold"); | 144 "inner_threshold"); |
| 145 fOuterThresholdVar = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, | 145 fOuterThresholdVar = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, |
| 146 kFloat_GrSLType, kDefault_GrS
LPrecision, | 146 kFloat_GrSLType, kDefault_GrS
LPrecision, |
| 147 "outer_threshold"); | 147 "outer_threshold"); |
| 148 | 148 |
| 149 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; | 149 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 150 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 150 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 151 SkString maskCoords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 1); | 151 SkString maskCoords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1); |
| 152 | 152 |
| 153 fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); | 153 fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); |
| 154 fsBuilder->codeAppendf("\t\tvec2 mask_coord = %s;\n", maskCoords2D.c_str()); | 154 fragBuilder->codeAppendf("\t\tvec2 mask_coord = %s;\n", maskCoords2D.c_str()
); |
| 155 fsBuilder->codeAppend("\t\tvec4 input_color = "); | 155 fragBuilder->codeAppend("\t\tvec4 input_color = "); |
| 156 fsBuilder->appendTextureLookup(args.fSamplers[0], "coord"); | 156 fragBuilder->appendTextureLookup(args.fSamplers[0], "coord"); |
| 157 fsBuilder->codeAppend(";\n"); | 157 fragBuilder->codeAppend(";\n"); |
| 158 fsBuilder->codeAppend("\t\tvec4 mask_color = "); | 158 fragBuilder->codeAppend("\t\tvec4 mask_color = "); |
| 159 fsBuilder->appendTextureLookup(args.fSamplers[1], "mask_coord"); | 159 fragBuilder->appendTextureLookup(args.fSamplers[1], "mask_coord"); |
| 160 fsBuilder->codeAppend(";\n"); | 160 fragBuilder->codeAppend(";\n"); |
| 161 | 161 |
| 162 fsBuilder->codeAppendf("\t\tfloat inner_thresh = %s;\n", | 162 fragBuilder->codeAppendf("\t\tfloat inner_thresh = %s;\n", |
| 163 args.fBuilder->getUniformCStr(fInnerThresholdVar)); | 163 args.fBuilder->getUniformCStr(fInnerThresholdVar)); |
| 164 fsBuilder->codeAppendf("\t\tfloat outer_thresh = %s;\n", | 164 fragBuilder->codeAppendf("\t\tfloat outer_thresh = %s;\n", |
| 165 args.fBuilder->getUniformCStr(fOuterThresholdVar)); | 165 args.fBuilder->getUniformCStr(fOuterThresholdVar)); |
| 166 fsBuilder->codeAppend("\t\tfloat mask = mask_color.a;\n"); | 166 fragBuilder->codeAppend("\t\tfloat mask = mask_color.a;\n"); |
| 167 | 167 |
| 168 fsBuilder->codeAppend("vec4 color = input_color;\n"); | 168 fragBuilder->codeAppend("vec4 color = input_color;\n"); |
| 169 fsBuilder->codeAppend("\t\tif (mask < 0.5) {\n" | 169 fragBuilder->codeAppend("\t\tif (mask < 0.5) {\n" |
| 170 "\t\t\tif (color.a > outer_thresh) {\n" | 170 "\t\t\tif (color.a > outer_thresh) {\n" |
| 171 "\t\t\t\tfloat scale = outer_thresh / color.a;\n" | 171 "\t\t\t\tfloat scale = outer_thresh / color.a;\n" |
| 172 "\t\t\t\tcolor.rgb *= scale;\n" | 172 "\t\t\t\tcolor.rgb *= scale;\n" |
| 173 "\t\t\t\tcolor.a = outer_thresh;\n" | 173 "\t\t\t\tcolor.a = outer_thresh;\n" |
| 174 "\t\t\t}\n" | 174 "\t\t\t}\n" |
| 175 "\t\t} else if (color.a < inner_thresh) {\n" | 175 "\t\t} else if (color.a < inner_thresh) {\n" |
| 176 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a
);\n" | 176 "\t\t\tfloat scale = inner_thresh / max(0.001, color
.a);\n" |
| 177 "\t\t\tcolor.rgb *= scale;\n" | 177 "\t\t\tcolor.rgb *= scale;\n" |
| 178 "\t\t\tcolor.a = inner_thresh;\n" | 178 "\t\t\tcolor.a = inner_thresh;\n" |
| 179 "\t\t}\n"); | 179 "\t\t}\n"); |
| 180 | 180 |
| 181 fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, | 181 fragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, |
| 182 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color")
).c_str()); | 182 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color
")).c_str()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void GrGLAlphaThresholdEffect::onSetData(const GrGLSLProgramDataManager& pdman, | 185 void GrGLAlphaThresholdEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
| 186 const GrProcessor& proc) { | 186 const GrProcessor& proc) { |
| 187 const AlphaThresholdEffect& alpha_threshold = proc.cast<AlphaThresholdEffect
>(); | 187 const AlphaThresholdEffect& alpha_threshold = proc.cast<AlphaThresholdEffect
>(); |
| 188 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); | 188 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); |
| 189 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold()); | 189 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 ///////////////////////////////////////////////////////////////////// | 192 ///////////////////////////////////////////////////////////////////// |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 370 } |
| 371 | 371 |
| 372 #ifndef SK_IGNORE_TO_STRING | 372 #ifndef SK_IGNORE_TO_STRING |
| 373 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { | 373 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { |
| 374 str->appendf("SkAlphaThresholdImageFilter: ("); | 374 str->appendf("SkAlphaThresholdImageFilter: ("); |
| 375 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); | 375 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); |
| 376 str->append(")"); | 376 str->append(")"); |
| 377 } | 377 } |
| 378 #endif | 378 #endif |
| 379 | 379 |
| OLD | NEW |