| 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 "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 GrCoordTransform fImageCoordTransform; | 111 GrCoordTransform fImageCoordTransform; |
| 112 GrTextureAccess fImageTextureAccess; | 112 GrTextureAccess fImageTextureAccess; |
| 113 GrCoordTransform fMaskCoordTransform; | 113 GrCoordTransform fMaskCoordTransform; |
| 114 GrTextureAccess fMaskTextureAccess; | 114 GrTextureAccess fMaskTextureAccess; |
| 115 | 115 |
| 116 typedef GrEffect INHERITED; | 116 typedef GrEffect INHERITED; |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 class GrGLAlphaThresholdEffect : public GrGLEffect { | 119 class GrGLAlphaThresholdEffect : public GrGLEffect { |
| 120 public: | 120 public: |
| 121 GrGLAlphaThresholdEffect(const GrBackendEffectFactory&, const GrDrawEffect&)
; | 121 GrGLAlphaThresholdEffect(const GrBackendEffectFactory&, const GrEffect&); |
| 122 | 122 |
| 123 virtual void emitCode(GrGLProgramBuilder*, | 123 virtual void emitCode(GrGLProgramBuilder*, |
| 124 const GrDrawEffect&, | 124 const GrEffect&, |
| 125 const GrEffectKey&, | 125 const GrEffectKey&, |
| 126 const char* outputColor, | 126 const char* outputColor, |
| 127 const char* inputColor, | 127 const char* inputColor, |
| 128 const TransformedCoordsArray&, | 128 const TransformedCoordsArray&, |
| 129 const TextureSamplerArray&) SK_OVERRIDE; | 129 const TextureSamplerArray&) SK_OVERRIDE; |
| 130 | 130 |
| 131 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 131 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; |
| 132 | 132 |
| 133 private: | 133 private: |
| 134 | 134 |
| 135 GrGLProgramDataManager::UniformHandle fInnerThresholdVar; | 135 GrGLProgramDataManager::UniformHandle fInnerThresholdVar; |
| 136 GrGLProgramDataManager::UniformHandle fOuterThresholdVar; | 136 GrGLProgramDataManager::UniformHandle fOuterThresholdVar; |
| 137 | 137 |
| 138 typedef GrGLEffect INHERITED; | 138 typedef GrGLEffect INHERITED; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 GrGLAlphaThresholdEffect::GrGLAlphaThresholdEffect(const GrBackendEffectFactory&
factory, const GrDrawEffect&) | 141 GrGLAlphaThresholdEffect::GrGLAlphaThresholdEffect(const GrBackendEffectFactory&
factory, |
| 142 const GrEffect&) |
| 142 : INHERITED(factory) { | 143 : INHERITED(factory) { |
| 143 } | 144 } |
| 144 | 145 |
| 145 void GrGLAlphaThresholdEffect::emitCode(GrGLProgramBuilder* builder, | 146 void GrGLAlphaThresholdEffect::emitCode(GrGLProgramBuilder* builder, |
| 146 const GrDrawEffect&, | 147 const GrEffect&, |
| 147 const GrEffectKey& key, | 148 const GrEffectKey& key, |
| 148 const char* outputColor, | 149 const char* outputColor, |
| 149 const char* inputColor, | 150 const char* inputColor, |
| 150 const TransformedCoordsArray& coords, | 151 const TransformedCoordsArray& coords, |
| 151 const TextureSamplerArray& samplers) { | 152 const TextureSamplerArray& samplers) { |
| 152 fInnerThresholdVar = builder->addUniform( | 153 fInnerThresholdVar = builder->addUniform( |
| 153 GrGLProgramBuilder::kFragment_Visibility, | 154 GrGLProgramBuilder::kFragment_Visibility, |
| 154 kFloat_GrSLType, "inner_threshold"); | 155 kFloat_GrSLType, "inner_threshold"); |
| 155 fOuterThresholdVar = builder->addUniform( | 156 fOuterThresholdVar = builder->addUniform( |
| 156 GrGLProgramBuilder::kFragment_Visibility, | 157 GrGLProgramBuilder::kFragment_Visibility, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 186 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a
);\n" | 187 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a
);\n" |
| 187 "\t\t\tcolor.rgb *= scale;\n" | 188 "\t\t\tcolor.rgb *= scale;\n" |
| 188 "\t\t\tcolor.a = inner_thresh;\n" | 189 "\t\t\tcolor.a = inner_thresh;\n" |
| 189 "\t\t}\n"); | 190 "\t\t}\n"); |
| 190 | 191 |
| 191 fsBuilder->codeAppendf("%s = %s;\n", outputColor, | 192 fsBuilder->codeAppendf("%s = %s;\n", outputColor, |
| 192 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("color")).c_st
r()); | 193 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("color")).c_st
r()); |
| 193 } | 194 } |
| 194 | 195 |
| 195 void GrGLAlphaThresholdEffect::setData(const GrGLProgramDataManager& pdman, | 196 void GrGLAlphaThresholdEffect::setData(const GrGLProgramDataManager& pdman, |
| 196 const GrDrawEffect& drawEffect) { | 197 const GrEffect& effect) { |
| 197 const AlphaThresholdEffect& alpha_threshold = | 198 const AlphaThresholdEffect& alpha_threshold = |
| 198 drawEffect.castEffect<AlphaThresholdEffect>(); | 199 GrEffect::CastEffect<AlphaThresholdEffect>(effect); |
| 199 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); | 200 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); |
| 200 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold()); | 201 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold()); |
| 201 } | 202 } |
| 202 | 203 |
| 203 ///////////////////////////////////////////////////////////////////// | 204 ///////////////////////////////////////////////////////////////////// |
| 204 | 205 |
| 205 GR_DEFINE_EFFECT_TEST(AlphaThresholdEffect); | 206 GR_DEFINE_EFFECT_TEST(AlphaThresholdEffect); |
| 206 | 207 |
| 207 GrEffect* AlphaThresholdEffect::TestCreate(SkRandom* random, | 208 GrEffect* AlphaThresholdEffect::TestCreate(SkRandom* random, |
| 208 GrContext* context, | 209 GrContext* context, |
| 209 const GrDrawTargetCaps&, | 210 const GrDrawTargetCaps&, |
| 210 GrTexture** textures) { | 211 GrTexture** textures) { |
| 211 GrTexture* bmpTex = textures[GrEffectUnitTest::kSkiaPMTextureIdx]; | 212 GrTexture* bmpTex = textures[GrEffectUnitTest::kSkiaPMTextureIdx]; |
| 212 GrTexture* maskTex = textures[GrEffectUnitTest::kAlphaTextureIdx]; | 213 GrTexture* maskTex = textures[GrEffectUnitTest::kAlphaTextureIdx]; |
| 213 float inner_thresh = random->nextUScalar1(); | 214 float inner_thresh = random->nextUScalar1(); |
| 214 float outer_thresh = random->nextUScalar1(); | 215 float outer_thresh = random->nextUScalar1(); |
| 215 return AlphaThresholdEffect::Create(bmpTex, maskTex, inner_thresh, outer_thr
esh); | 216 return AlphaThresholdEffect::Create(bmpTex, maskTex, inner_thresh, outer_thr
esh); |
| 216 } | 217 } |
| 217 | 218 |
| 218 /////////////////////////////////////////////////////////////////////////////// | 219 /////////////////////////////////////////////////////////////////////////////// |
| 219 | 220 |
| 220 const GrBackendEffectFactory& AlphaThresholdEffect::getFactory() const { | 221 const GrBackendEffectFactory& AlphaThresholdEffect::getFactory() const { |
| 221 return GrTBackendEffectFactory<AlphaThresholdEffect>::getInstance(); | 222 return GrTBackendEffectFactory<AlphaThresholdEffect>::getInstance(); |
| 222 } | 223 } |
| 223 | 224 |
| 224 bool AlphaThresholdEffect::onIsEqual(const GrEffect& sBase) const { | 225 bool AlphaThresholdEffect::onIsEqual(const GrEffect& sBase) const { |
| 225 const AlphaThresholdEffect& s = CastEffect<AlphaThresholdEffect>(sBase); | 226 const AlphaThresholdEffect& s = GrEffect::CastEffect<AlphaThresholdEffect>(s
Base); |
| 226 return (this->texture(0) == s.texture(0) && | 227 return (this->texture(0) == s.texture(0) && |
| 227 this->fInnerThreshold == s.fInnerThreshold && | 228 this->fInnerThreshold == s.fInnerThreshold && |
| 228 this->fOuterThreshold == s.fOuterThreshold); | 229 this->fOuterThreshold == s.fOuterThreshold); |
| 229 } | 230 } |
| 230 | 231 |
| 231 void AlphaThresholdEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { | 232 void AlphaThresholdEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { |
| 232 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && | 233 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && |
| 233 GrPixelConfigIsOpaque(this->texture(0)->config())) { | 234 GrPixelConfigIsOpaque(this->texture(0)->config())) { |
| 234 *validFlags = kA_GrColorComponentFlag; | 235 *validFlags = kA_GrColorComponentFlag; |
| 235 } else { | 236 } else { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 (U8CPU)(SkColorGetG(source) *
scale), | 378 (U8CPU)(SkColorGetG(source) *
scale), |
| 378 (U8CPU)(SkColorGetB(source) *
scale)); | 379 (U8CPU)(SkColorGetB(source) *
scale)); |
| 379 } | 380 } |
| 380 } | 381 } |
| 381 dptr[y * dst->width() + x] = output_color; | 382 dptr[y * dst->width() + x] = output_color; |
| 382 } | 383 } |
| 383 } | 384 } |
| 384 | 385 |
| 385 return true; | 386 return true; |
| 386 } | 387 } |
| OLD | NEW |