OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
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 "SkMorphologyImageFilter.h" | 8 #include "SkMorphologyImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 /////////////////////////////////////////////////////////////////////////////// | 305 /////////////////////////////////////////////////////////////////////////////// |
306 | 306 |
307 class GrGLMorphologyEffect : public GrGLEffect { | 307 class GrGLMorphologyEffect : public GrGLEffect { |
308 public: | 308 public: |
309 GrGLMorphologyEffect (const GrBackendEffectFactory&, const GrDrawEffect&); | 309 GrGLMorphologyEffect (const GrBackendEffectFactory&, const GrDrawEffect&); |
310 | 310 |
311 virtual void emitCode(GrGLShaderBuilder*, | 311 virtual void emitCode(GrGLShaderBuilder*, |
312 const GrDrawEffect&, | 312 const GrDrawEffect&, |
313 EffectKey, | 313 EffectKey, |
314 const char* outputColor, | 314 const char* outputColor, |
315 const char* inputColor, | 315 const GrGLSLExpr4& inputColor, |
316 const TransformedCoordsArray&, | 316 const TransformedCoordsArray&, |
317 const TextureSamplerArray&) SK_OVERRIDE; | 317 const TextureSamplerArray&) SK_OVERRIDE; |
318 | 318 |
319 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 319 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); |
320 | 320 |
321 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 321 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
322 | 322 |
323 private: | 323 private: |
324 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } | 324 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } |
325 | 325 |
326 int fRadius; | 326 int fRadius; |
327 GrMorphologyEffect::MorphologyType fType; | 327 GrMorphologyEffect::MorphologyType fType; |
328 GrGLUniformManager::UniformHandle fImageIncrementUni; | 328 GrGLUniformManager::UniformHandle fImageIncrementUni; |
329 | 329 |
330 typedef GrGLEffect INHERITED; | 330 typedef GrGLEffect INHERITED; |
331 }; | 331 }; |
332 | 332 |
333 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory
, | 333 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory
, |
334 const GrDrawEffect& drawEffect) | 334 const GrDrawEffect& drawEffect) |
335 : INHERITED(factory) { | 335 : INHERITED(factory) { |
336 const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>(); | 336 const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>(); |
337 fRadius = m.radius(); | 337 fRadius = m.radius(); |
338 fType = m.type(); | 338 fType = m.type(); |
339 } | 339 } |
340 | 340 |
341 void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder, | 341 void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder, |
342 const GrDrawEffect&, | 342 const GrDrawEffect&, |
343 EffectKey key, | 343 EffectKey key, |
344 const char* outputColor, | 344 const char* outputColor, |
345 const char* inputColor, | 345 const GrGLSLExpr4& inputColor, |
346 const TransformedCoordsArray& coords, | 346 const TransformedCoordsArray& coords, |
347 const TextureSamplerArray& samplers) { | 347 const TextureSamplerArray& samplers) { |
348 SkString coords2D = builder->ensureFSCoords2D(coords, 0); | 348 SkString coords2D = builder->ensureFSCoords2D(coords, 0); |
349 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, | 349 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, |
350 kVec2f_GrSLType, "ImageIncrement"); | 350 kVec2f_GrSLType, "ImageIncrement"); |
351 | 351 |
352 const char* func; | 352 const char* func; |
353 switch (fType) { | 353 switch (fType) { |
354 case GrMorphologyEffect::kErode_MorphologyType: | 354 case GrMorphologyEffect::kErode_MorphologyType: |
355 builder->fsCodeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor); | 355 builder->fsCodeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 | 581 |
582 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy
pe, radius(), result)) { | 582 if (!apply_morphology(input, bounds, GrMorphologyEffect::kErode_MorphologyTy
pe, radius(), result)) { |
583 return false; | 583 return false; |
584 } | 584 } |
585 offset->fX += bounds.left(); | 585 offset->fX += bounds.left(); |
586 offset->fY += bounds.top(); | 586 offset->fY += bounds.top(); |
587 return true; | 587 return true; |
588 } | 588 } |
589 | 589 |
590 #endif | 590 #endif |
OLD | NEW |