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 "SkMatrixConvolutionImageFilter.h" | 8 #include "SkMatrixConvolutionImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 typedef GrSingleTextureEffect INHERITED; | 399 typedef GrSingleTextureEffect INHERITED; |
400 }; | 400 }; |
401 | 401 |
402 class GrGLMatrixConvolutionEffect : public GrGLEffect { | 402 class GrGLMatrixConvolutionEffect : public GrGLEffect { |
403 public: | 403 public: |
404 GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory, | 404 GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory, |
405 const GrDrawEffect& effect); | 405 const GrDrawEffect& effect); |
406 virtual void emitCode(GrGLShaderBuilder*, | 406 virtual void emitCode(GrGLShaderBuilder*, |
407 const GrDrawEffect&, | 407 const GrDrawEffect&, |
408 EffectKey, | 408 const GrEffectKey&, |
409 const char* outputColor, | 409 const char* outputColor, |
410 const char* inputColor, | 410 const char* inputColor, |
411 const TransformedCoordsArray&, | 411 const TransformedCoordsArray&, |
412 const TextureSamplerArray&) SK_OVERRIDE; | 412 const TextureSamplerArray&) SK_OVERRIDE; |
413 | 413 |
414 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 414 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
415 | 415 |
416 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 416 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
417 | 417 |
418 private: | 418 private: |
419 typedef GrGLUniformManager::UniformHandle UniformHandle; | 419 typedef GrGLUniformManager::UniformHandle UniformHandle; |
420 typedef SkMatrixConvolutionImageFilter::TileMode TileMode; | 420 typedef SkMatrixConvolutionImageFilter::TileMode TileMode; |
421 SkISize fKernelSize; | 421 SkISize fKernelSize; |
422 TileMode fTileMode; | 422 TileMode fTileMode; |
423 bool fConvolveAlpha; | 423 bool fConvolveAlpha; |
424 | 424 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 break; | 458 break; |
459 case SkMatrixConvolutionImageFilter::kClampToBlack_TileMode: | 459 case SkMatrixConvolutionImageFilter::kClampToBlack_TileMode: |
460 builder->fsCodeAppendf("clamp(%s, %s.xy, %s.zw) != %s ? vec4(0, 0, 0
, 0) : ", coord, bounds, bounds, coord); | 460 builder->fsCodeAppendf("clamp(%s, %s.xy, %s.zw) != %s ? vec4(0, 0, 0
, 0) : ", coord, bounds, bounds, coord); |
461 break; | 461 break; |
462 } | 462 } |
463 builder->fsAppendTextureLookup(sampler, coord); | 463 builder->fsAppendTextureLookup(sampler, coord); |
464 } | 464 } |
465 | 465 |
466 void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder, | 466 void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder, |
467 const GrDrawEffect&, | 467 const GrDrawEffect&, |
468 EffectKey key, | 468 const GrEffectKey& key, |
469 const char* outputColor, | 469 const char* outputColor, |
470 const char* inputColor, | 470 const char* inputColor, |
471 const TransformedCoordsArray& coords, | 471 const TransformedCoordsArray& coords, |
472 const TextureSamplerArray& samplers)
{ | 472 const TextureSamplerArray& samplers)
{ |
473 sk_ignore_unused_variable(inputColor); | 473 sk_ignore_unused_variable(inputColor); |
474 SkString coords2D = builder->ensureFSCoords2D(coords, 0); | 474 SkString coords2D = builder->ensureFSCoords2D(coords, 0); |
475 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 475 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
476 kVec4f_GrSLType, "Bounds"); | 476 kVec4f_GrSLType, "Bounds"); |
477 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, | 477 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, |
478 kVec2f_GrSLType, "ImageIncrement"); | 478 kVec2f_GrSLType, "ImageIncrement"); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 int encodeXY(int x, int y) { | 530 int encodeXY(int x, int y) { |
531 SkASSERT(x >= 1 && y >= 1 && x * y <= 32); | 531 SkASSERT(x >= 1 && y >= 1 && x * y <= 32); |
532 if (y < x) | 532 if (y < x) |
533 return 0x40 | encodeXY(y, x); | 533 return 0x40 | encodeXY(y, x); |
534 else | 534 else |
535 return (0x40 >> x) | (y - x); | 535 return (0x40 >> x) | (y - x); |
536 } | 536 } |
537 | 537 |
538 }; | 538 }; |
539 | 539 |
540 GrGLEffect::EffectKey GrGLMatrixConvolutionEffect::GenKey(const GrDrawEffect& dr
awEffect, | 540 void GrGLMatrixConvolutionEffect::GenKey(const GrDrawEffect& drawEffect, |
541 const GrGLCaps&) { | 541 const GrGLCaps&, GrEffectKeyBuilder* b)
{ |
542 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvoluti
onEffect>(); | 542 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvoluti
onEffect>(); |
543 EffectKey key = encodeXY(m.kernelSize().width(), m.kernelSize().height()); | 543 uint32_t key = encodeXY(m.kernelSize().width(), m.kernelSize().height()); |
544 key |= m.tileMode() << 7; | 544 key |= m.tileMode() << 7; |
545 key |= m.convolveAlpha() ? 1 << 9 : 0; | 545 key |= m.convolveAlpha() ? 1 << 9 : 0; |
546 return key; | 546 b->add32(key); |
547 } | 547 } |
548 | 548 |
549 void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman, | 549 void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman, |
550 const GrDrawEffect& drawEffect) { | 550 const GrDrawEffect& drawEffect) { |
551 const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvol
utionEffect>(); | 551 const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvol
utionEffect>(); |
552 GrTexture& texture = *conv.texture(0); | 552 GrTexture& texture = *conv.texture(0); |
553 // the code we generated was for a specific kernel size | 553 // the code we generated was for a specific kernel size |
554 SkASSERT(conv.kernelSize() == fKernelSize); | 554 SkASSERT(conv.kernelSize() == fKernelSize); |
555 SkASSERT(conv.tileMode() == fTileMode); | 555 SkASSERT(conv.tileMode() == fTileMode); |
556 float imageIncrement[2]; | 556 float imageIncrement[2]; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 fBias, | 677 fBias, |
678 fKernelOffset, | 678 fKernelOffset, |
679 fTileMode, | 679 fTileMode, |
680 fConvolveAlpha); | 680 fConvolveAlpha); |
681 return true; | 681 return true; |
682 } | 682 } |
683 | 683 |
684 /////////////////////////////////////////////////////////////////////////////// | 684 /////////////////////////////////////////////////////////////////////////////// |
685 | 685 |
686 #endif | 686 #endif |
OLD | NEW |