| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include "GrCoordTransform.h" | 52 #include "GrCoordTransform.h" |
| 53 #include "GrFragmentProcessor.h" | 53 #include "GrFragmentProcessor.h" |
| 54 #include "GrInvariantOutput.h" | 54 #include "GrInvariantOutput.h" |
| 55 #include "GrTextureAccess.h" | 55 #include "GrTextureAccess.h" |
| 56 #include "effects/GrPorterDuffXferProcessor.h" | 56 #include "effects/GrPorterDuffXferProcessor.h" |
| 57 | 57 |
| 58 #include "SkGr.h" | 58 #include "SkGr.h" |
| 59 | 59 |
| 60 #include "gl/GrGLFragmentProcessor.h" | 60 #include "gl/GrGLFragmentProcessor.h" |
| 61 #include "gl/builders/GrGLProgramBuilder.h" | 61 #include "gl/builders/GrGLProgramBuilder.h" |
| 62 #include "glsl/GrGLSLProgramDataManager.h" |
| 62 | 63 |
| 63 class AlphaThresholdEffect : public GrFragmentProcessor { | 64 class AlphaThresholdEffect : public GrFragmentProcessor { |
| 64 | 65 |
| 65 public: | 66 public: |
| 66 static GrFragmentProcessor* Create(GrTexture* texture, | 67 static GrFragmentProcessor* Create(GrTexture* texture, |
| 67 GrTexture* maskTexture, | 68 GrTexture* maskTexture, |
| 68 float innerThreshold, | 69 float innerThreshold, |
| 69 float outerThreshold) { | 70 float outerThreshold) { |
| 70 return new AlphaThresholdEffect(texture, maskTexture, innerThreshold, ou
terThreshold); | 71 return new AlphaThresholdEffect(texture, maskTexture, innerThreshold, ou
terThreshold); |
| 71 } | 72 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 typedef GrFragmentProcessor INHERITED; | 120 typedef GrFragmentProcessor INHERITED; |
| 120 }; | 121 }; |
| 121 | 122 |
| 122 class GrGLAlphaThresholdEffect : public GrGLFragmentProcessor { | 123 class GrGLAlphaThresholdEffect : public GrGLFragmentProcessor { |
| 123 public: | 124 public: |
| 124 GrGLAlphaThresholdEffect(const GrFragmentProcessor&) {} | 125 GrGLAlphaThresholdEffect(const GrFragmentProcessor&) {} |
| 125 | 126 |
| 126 virtual void emitCode(EmitArgs&) override; | 127 virtual void emitCode(EmitArgs&) override; |
| 127 | 128 |
| 128 protected: | 129 protected: |
| 129 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 130 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 130 | 131 |
| 131 private: | 132 private: |
| 132 | 133 |
| 133 GrGLProgramDataManager::UniformHandle fInnerThresholdVar; | 134 GrGLSLProgramDataManager::UniformHandle fInnerThresholdVar; |
| 134 GrGLProgramDataManager::UniformHandle fOuterThresholdVar; | 135 GrGLSLProgramDataManager::UniformHandle fOuterThresholdVar; |
| 135 | 136 |
| 136 typedef GrGLFragmentProcessor INHERITED; | 137 typedef GrGLFragmentProcessor INHERITED; |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) { | 140 void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) { |
| 140 fInnerThresholdVar = args.fBuilder->addUniform( | 141 fInnerThresholdVar = args.fBuilder->addUniform( |
| 141 GrGLProgramBuilder::kFragment_Visibility, | 142 GrGLProgramBuilder::kFragment_Visibility, |
| 142 kFloat_GrSLType, kDefault_GrSLPrecision, | 143 kFloat_GrSLType, kDefault_GrSLPrecision, |
| 143 "inner_threshold"); | 144 "inner_threshold"); |
| 144 fOuterThresholdVar = args.fBuilder->addUniform( | 145 fOuterThresholdVar = args.fBuilder->addUniform( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 175 "\t\t} else if (color.a < inner_thresh) {\n" | 176 "\t\t} else if (color.a < inner_thresh) {\n" |
| 176 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a
);\n" | 177 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a
);\n" |
| 177 "\t\t\tcolor.rgb *= scale;\n" | 178 "\t\t\tcolor.rgb *= scale;\n" |
| 178 "\t\t\tcolor.a = inner_thresh;\n" | 179 "\t\t\tcolor.a = inner_thresh;\n" |
| 179 "\t\t}\n"); | 180 "\t\t}\n"); |
| 180 | 181 |
| 181 fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, | 182 fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, |
| 182 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color")
).c_str()); | 183 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color")
).c_str()); |
| 183 } | 184 } |
| 184 | 185 |
| 185 void GrGLAlphaThresholdEffect::onSetData(const GrGLProgramDataManager& pdman, | 186 void GrGLAlphaThresholdEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
| 186 const GrProcessor& proc) { | 187 const GrProcessor& proc) { |
| 187 const AlphaThresholdEffect& alpha_threshold = proc.cast<AlphaThresholdEffect
>(); | 188 const AlphaThresholdEffect& alpha_threshold = proc.cast<AlphaThresholdEffect
>(); |
| 188 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); | 189 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); |
| 189 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold()); | 190 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold()); |
| 190 } | 191 } |
| 191 | 192 |
| 192 ///////////////////////////////////////////////////////////////////// | 193 ///////////////////////////////////////////////////////////////////// |
| 193 | 194 |
| 194 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect); | 195 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect); |
| 195 | 196 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 371 } |
| 371 | 372 |
| 372 #ifndef SK_IGNORE_TO_STRING | 373 #ifndef SK_IGNORE_TO_STRING |
| 373 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { | 374 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { |
| 374 str->appendf("SkAlphaThresholdImageFilter: ("); | 375 str->appendf("SkAlphaThresholdImageFilter: ("); |
| 375 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); | 376 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); |
| 376 str->append(")"); | 377 str->append(")"); |
| 377 } | 378 } |
| 378 #endif | 379 #endif |
| 379 | 380 |
| OLD | NEW |