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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 321 |
322 GR_DECLARE_EFFECT_TEST; | 322 GR_DECLARE_EFFECT_TEST; |
323 | 323 |
324 typedef Gr1DKernelEffect INHERITED; | 324 typedef Gr1DKernelEffect INHERITED; |
325 }; | 325 }; |
326 | 326 |
327 /////////////////////////////////////////////////////////////////////////////// | 327 /////////////////////////////////////////////////////////////////////////////// |
328 | 328 |
329 class GrGLMorphologyEffect : public GrGLEffect { | 329 class GrGLMorphologyEffect : public GrGLEffect { |
330 public: | 330 public: |
331 GrGLMorphologyEffect (const GrBackendEffectFactory&, const GrEffect&); | 331 GrGLMorphologyEffect (const GrBackendEffectFactory&, const GrDrawEffect&); |
332 | 332 |
333 virtual void emitCode(GrGLProgramBuilder*, | 333 virtual void emitCode(GrGLProgramBuilder*, |
334 const GrEffect&, | 334 const GrDrawEffect&, |
335 const GrEffectKey&, | 335 const GrEffectKey&, |
336 const char* outputColor, | 336 const char* outputColor, |
337 const char* inputColor, | 337 const char* inputColor, |
338 const TransformedCoordsArray&, | 338 const TransformedCoordsArray&, |
339 const TextureSamplerArray&) SK_OVERRIDE; | 339 const TextureSamplerArray&) SK_OVERRIDE; |
340 | 340 |
341 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuild
er* b); | 341 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder* b); |
342 | 342 |
343 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; | 343 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
344 | 344 |
345 private: | 345 private: |
346 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } | 346 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } |
347 | 347 |
348 int fRadius; | 348 int fRadius; |
349 GrMorphologyEffect::MorphologyType fType; | 349 GrMorphologyEffect::MorphologyType fType; |
350 GrGLProgramDataManager::UniformHandle fImageIncrementUni; | 350 GrGLProgramDataManager::UniformHandle fImageIncrementUni; |
351 | 351 |
352 typedef GrGLEffect INHERITED; | 352 typedef GrGLEffect INHERITED; |
353 }; | 353 }; |
354 | 354 |
355 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory
, | 355 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory
, |
356 const GrEffect& effect) | 356 const GrDrawEffect& drawEffect) |
357 : INHERITED(factory) { | 357 : INHERITED(factory) { |
358 const GrMorphologyEffect& m = effect.cast<GrMorphologyEffect>(); | 358 const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>(); |
359 fRadius = m.radius(); | 359 fRadius = m.radius(); |
360 fType = m.type(); | 360 fType = m.type(); |
361 } | 361 } |
362 | 362 |
363 void GrGLMorphologyEffect::emitCode(GrGLProgramBuilder* builder, | 363 void GrGLMorphologyEffect::emitCode(GrGLProgramBuilder* builder, |
364 const GrEffect&, | 364 const GrDrawEffect&, |
365 const GrEffectKey& key, | 365 const GrEffectKey& key, |
366 const char* outputColor, | 366 const char* outputColor, |
367 const char* inputColor, | 367 const char* inputColor, |
368 const TransformedCoordsArray& coords, | 368 const TransformedCoordsArray& coords, |
369 const TextureSamplerArray& samplers) { | 369 const TextureSamplerArray& samplers) { |
370 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | 370 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
371 kVec2f_GrSLType, "ImageIncrement"); | 371 kVec2f_GrSLType, "ImageIncrement"); |
372 | 372 |
373 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 373 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
374 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); | 374 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); |
(...skipping 19 matching lines...) Expand all Loading... |
394 fsBuilder->codeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor)
; | 394 fsBuilder->codeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor)
; |
395 fsBuilder->appendTextureLookup(samplers[0], "coord"); | 395 fsBuilder->appendTextureLookup(samplers[0], "coord"); |
396 fsBuilder->codeAppend(");\n"); | 396 fsBuilder->codeAppend(");\n"); |
397 fsBuilder->codeAppendf("\t\t\tcoord += %s;\n", imgInc); | 397 fsBuilder->codeAppendf("\t\t\tcoord += %s;\n", imgInc); |
398 fsBuilder->codeAppend("\t\t}\n"); | 398 fsBuilder->codeAppend("\t\t}\n"); |
399 SkString modulate; | 399 SkString modulate; |
400 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 400 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
401 fsBuilder->codeAppend(modulate.c_str()); | 401 fsBuilder->codeAppend(modulate.c_str()); |
402 } | 402 } |
403 | 403 |
404 void GrGLMorphologyEffect::GenKey(const GrEffect& effect, | 404 void GrGLMorphologyEffect::GenKey(const GrDrawEffect& drawEffect, |
405 const GrGLCaps&, GrEffectKeyBuilder* b) { | 405 const GrGLCaps&, GrEffectKeyBuilder* b) { |
406 const GrMorphologyEffect& m = effect.cast<GrMorphologyEffect>(); | 406 const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>(); |
407 uint32_t key = static_cast<uint32_t>(m.radius()); | 407 uint32_t key = static_cast<uint32_t>(m.radius()); |
408 key |= (m.type() << 8); | 408 key |= (m.type() << 8); |
409 b->add32(key); | 409 b->add32(key); |
410 } | 410 } |
411 | 411 |
412 void GrGLMorphologyEffect::setData(const GrGLProgramDataManager& pdman, | 412 void GrGLMorphologyEffect::setData(const GrGLProgramDataManager& pdman, |
413 const GrEffect& effect) { | 413 const GrDrawEffect& drawEffect) { |
414 const Gr1DKernelEffect& kern = effect.cast<Gr1DKernelEffect>(); | 414 const Gr1DKernelEffect& kern = drawEffect.castEffect<Gr1DKernelEffect>(); |
415 GrTexture& texture = *kern.texture(0); | 415 GrTexture& texture = *kern.texture(0); |
416 // the code we generated was for a specific kernel radius | 416 // the code we generated was for a specific kernel radius |
417 SkASSERT(kern.radius() == fRadius); | 417 SkASSERT(kern.radius() == fRadius); |
418 float imageIncrement[2] = { 0 }; | 418 float imageIncrement[2] = { 0 }; |
419 switch (kern.direction()) { | 419 switch (kern.direction()) { |
420 case Gr1DKernelEffect::kX_Direction: | 420 case Gr1DKernelEffect::kX_Direction: |
421 imageIncrement[0] = 1.0f / texture.width(); | 421 imageIncrement[0] = 1.0f / texture.width(); |
422 break; | 422 break; |
423 case Gr1DKernelEffect::kY_Direction: | 423 case Gr1DKernelEffect::kY_Direction: |
424 imageIncrement[1] = 1.0f / texture.height(); | 424 imageIncrement[1] = 1.0f / texture.height(); |
(...skipping 15 matching lines...) Expand all Loading... |
440 } | 440 } |
441 | 441 |
442 GrMorphologyEffect::~GrMorphologyEffect() { | 442 GrMorphologyEffect::~GrMorphologyEffect() { |
443 } | 443 } |
444 | 444 |
445 const GrBackendEffectFactory& GrMorphologyEffect::getFactory() const { | 445 const GrBackendEffectFactory& GrMorphologyEffect::getFactory() const { |
446 return GrTBackendEffectFactory<GrMorphologyEffect>::getInstance(); | 446 return GrTBackendEffectFactory<GrMorphologyEffect>::getInstance(); |
447 } | 447 } |
448 | 448 |
449 bool GrMorphologyEffect::onIsEqual(const GrEffect& sBase) const { | 449 bool GrMorphologyEffect::onIsEqual(const GrEffect& sBase) const { |
450 const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>(); | 450 const GrMorphologyEffect& s = CastEffect<GrMorphologyEffect>(sBase); |
451 return (this->texture(0) == s.texture(0) && | 451 return (this->texture(0) == s.texture(0) && |
452 this->radius() == s.radius() && | 452 this->radius() == s.radius() && |
453 this->direction() == s.direction() && | 453 this->direction() == s.direction() && |
454 this->type() == s.type()); | 454 this->type() == s.type()); |
455 } | 455 } |
456 | 456 |
457 void GrMorphologyEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { | 457 void GrMorphologyEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { |
458 // This is valid because the color components of the result of the kernel al
l come | 458 // This is valid because the color components of the result of the kernel al
l come |
459 // exactly from existing values in the source texture. | 459 // exactly from existing values in the source texture. |
460 this->updateConstantColorComponentsForModulation(color, validFlags); | 460 this->updateConstantColorComponentsForModulation(color, validFlags); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 SkBitmap* result, SkIPoint* offset) con
st { | 601 SkBitmap* result, SkIPoint* offset) con
st { |
602 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 602 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
603 } | 603 } |
604 | 604 |
605 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 605 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
606 SkBitmap* result, SkIPoint* offset) cons
t { | 606 SkBitmap* result, SkIPoint* offset) cons
t { |
607 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 607 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
608 } | 608 } |
609 | 609 |
610 #endif | 610 #endif |
OLD | NEW |