| 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 "SkBitmapAlphaThresholdShader.h" | 8 #include "SkBitmapAlphaThresholdShader.h" | 
| 9 | 9 | 
| 10 class BATShader : public SkShader { | 10 class BATShader : public SkShader { | 
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 109         GLEffect(const GrBackendEffectFactory& factory, | 109         GLEffect(const GrBackendEffectFactory& factory, | 
| 110                     const GrDrawEffect& e) | 110                     const GrDrawEffect& e) | 
| 111         : GrGLEffect(factory) | 111         : GrGLEffect(factory) | 
| 112         , fPrevThreshold(-SK_Scalar1) { | 112         , fPrevThreshold(-SK_Scalar1) { | 
| 113         } | 113         } | 
| 114 | 114 | 
| 115         virtual void emitCode(GrGLShaderBuilder* builder, | 115         virtual void emitCode(GrGLShaderBuilder* builder, | 
| 116                               const GrDrawEffect& drawEffect, | 116                               const GrDrawEffect& drawEffect, | 
| 117                               EffectKey key, | 117                               EffectKey key, | 
| 118                               const char* outputColor, | 118                               const char* outputColor, | 
| 119                               const char* inputColor, | 119                               const GrGLSLExpr4& inputColor, | 
| 120                               const TransformedCoordsArray& coords, | 120                               const TransformedCoordsArray& coords, | 
| 121                               const TextureSamplerArray& samplers) SK_OVERRIDE { | 121                               const TextureSamplerArray& samplers) SK_OVERRIDE { | 
| 122             // put bitmap color in "color" | 122             // put bitmap color in "color" | 
| 123             builder->fsCodeAppend("\t\tvec4 color = "); | 123             builder->fsCodeAppend("\t\tvec4 color = "); | 
| 124             builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coord
     s[0].type()); | 124             builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coord
     s[0].type()); | 
| 125             builder->fsCodeAppend(";\n"); | 125             builder->fsCodeAppend(";\n"); | 
| 126 | 126 | 
| 127             // put alpha from mask texture in "mask" | 127             // put alpha from mask texture in "mask" | 
| 128             builder->fsCodeAppend("\t\tfloat mask = "); | 128             builder->fsCodeAppend("\t\tfloat mask = "); | 
| 129             builder->fsAppendTextureLookup(samplers[1], coords[1].c_str(), coord
     s[1].type()); | 129             builder->fsAppendTextureLookup(samplers[1], coords[1].c_str(), coord
     s[1].type()); | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 143                                     "\t\t\t\tcolor.rgb *= scale;\n" | 143                                     "\t\t\t\tcolor.rgb *= scale;\n" | 
| 144                                     "\t\t\t\tcolor.a = thresh;\n" | 144                                     "\t\t\t\tcolor.a = thresh;\n" | 
| 145                                     "\t\t\t}\n" | 145                                     "\t\t\t}\n" | 
| 146                                     "\t\t} else if (color.a < thresh) {\n" | 146                                     "\t\t} else if (color.a < thresh) {\n" | 
| 147                                     "\t\t\tfloat scale = thresh / color.a;\n" | 147                                     "\t\t\tfloat scale = thresh / color.a;\n" | 
| 148                                     "\t\t\tcolor.rgb *= scale;\n" | 148                                     "\t\t\tcolor.rgb *= scale;\n" | 
| 149                                     "\t\t\tcolor.a = thresh;\n" | 149                                     "\t\t\tcolor.a = thresh;\n" | 
| 150                                     "\t\t}\n"); | 150                                     "\t\t}\n"); | 
| 151 | 151 | 
| 152             builder->fsCodeAppendf("color = %s = %s;\n", outputColor, | 152             builder->fsCodeAppendf("color = %s = %s;\n", outputColor, | 
| 153                                    (GrGLSLExpr4(inputColor) * GrGLSLExpr4("color
     ")).c_str()); | 153                                    (inputColor * GrGLSLExpr4("color")).c_str()); | 
| 154         } | 154         } | 
| 155 | 155 | 
| 156         virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&
      e) SK_OVERRIDE { | 156         virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&
      e) SK_OVERRIDE { | 
| 157             const ThresholdEffect& effect = e.castEffect<ThresholdEffect>(); | 157             const ThresholdEffect& effect = e.castEffect<ThresholdEffect>(); | 
| 158             if (fPrevThreshold != effect.fThreshold) { | 158             if (fPrevThreshold != effect.fThreshold) { | 
| 159                 uman.set1f(fThresholdUniHandle, effect.fThreshold); | 159                 uman.set1f(fThresholdUniHandle, effect.fThreshold); | 
| 160             } | 160             } | 
| 161         } | 161         } | 
| 162 | 162 | 
| 163     private: | 163     private: | 
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 268     GrEffectRef* effect = ThresholdEffect::Create(bmpTexture, bmpMatrix, | 268     GrEffectRef* effect = ThresholdEffect::Create(bmpTexture, bmpMatrix, | 
| 269                                                   maskTexture, maskMatrix, | 269                                                   maskTexture, maskMatrix, | 
| 270                                                   fThreshold); | 270                                                   fThreshold); | 
| 271 | 271 | 
| 272     GrUnlockAndUnrefCachedBitmapTexture(bmpTexture); | 272     GrUnlockAndUnrefCachedBitmapTexture(bmpTexture); | 
| 273 | 273 | 
| 274     return effect; | 274     return effect; | 
| 275 } | 275 } | 
| 276 | 276 | 
| 277 #endif | 277 #endif | 
| OLD | NEW | 
|---|