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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 private: | 405 private: |
406 typedef GrGLUniformManager::UniformHandle UniformHandle; | 406 typedef GrGLUniformManager::UniformHandle UniformHandle; |
407 typedef SkMatrixConvolutionImageFilter::TileMode TileMode; | 407 typedef SkMatrixConvolutionImageFilter::TileMode TileMode; |
408 SkISize fKernelSize; | 408 SkISize fKernelSize; |
409 TileMode fTileMode; | 409 TileMode fTileMode; |
410 bool fConvolveAlpha; | 410 bool fConvolveAlpha; |
411 | 411 |
412 UniformHandle fBoundsUni; | 412 UniformHandle fBoundsUni; |
413 UniformHandle fKernelUni; | 413 UniformHandle fKernelUni; |
414 UniformHandle fImageIncrementUni; | 414 UniformHandle fImageIncrementUni; |
415 UniformHandle fTargetUni; | 415 UniformHandle fKernelOffsetUni; |
416 UniformHandle fGainUni; | 416 UniformHandle fGainUni; |
417 UniformHandle fBiasUni; | 417 UniformHandle fBiasUni; |
418 | 418 |
419 typedef GrGLEffect INHERITED; | 419 typedef GrGLEffect INHERITED; |
420 }; | 420 }; |
421 | 421 |
422 GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrBackendEffectFa
ctory& factory, | 422 GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrBackendEffectFa
ctory& factory, |
423 const GrDrawEffect& dra
wEffect) | 423 const GrDrawEffect& dra
wEffect) |
424 : INHERITED(factory) { | 424 : INHERITED(factory) { |
425 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvoluti
onEffect>(); | 425 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvoluti
onEffect>(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 sk_ignore_unused_variable(inputColor); | 460 sk_ignore_unused_variable(inputColor); |
461 SkString coords2D = builder->ensureFSCoords2D(coords, 0); | 461 SkString coords2D = builder->ensureFSCoords2D(coords, 0); |
462 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 462 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
463 kVec4f_GrSLType, "Bounds"); | 463 kVec4f_GrSLType, "Bounds"); |
464 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, | 464 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, |
465 kVec2f_GrSLType, "ImageIncrement"); | 465 kVec2f_GrSLType, "ImageIncrement"); |
466 fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibilit
y, | 466 fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibilit
y, |
467 kFloat_GrSLType, | 467 kFloat_GrSLType, |
468 "Kernel", | 468 "Kernel", |
469 fKernelSize.width() * fKernelSize.h
eight()); | 469 fKernelSize.width() * fKernelSize.h
eight()); |
470 fTargetUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 470 fKernelOffsetUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili
ty, |
471 kVec2f_GrSLType, "Target"); | 471 kVec2f_GrSLType, "KernelOffset"); |
472 fGainUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 472 fGainUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
473 kFloat_GrSLType, "Gain"); | 473 kFloat_GrSLType, "Gain"); |
474 fBiasUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 474 fBiasUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
475 kFloat_GrSLType, "Bias"); | 475 kFloat_GrSLType, "Bias"); |
476 | 476 |
477 const char* bounds = builder->getUniformCStr(fBoundsUni); | 477 const char* bounds = builder->getUniformCStr(fBoundsUni); |
478 const char* kernelOffset = builder->getUniformCStr(fTargetUni); | 478 const char* kernelOffset = builder->getUniformCStr(fKernelOffsetUni); |
479 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); | 479 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
480 const char* kernel = builder->getUniformCStr(fKernelUni); | 480 const char* kernel = builder->getUniformCStr(fKernelUni); |
481 const char* gain = builder->getUniformCStr(fGainUni); | 481 const char* gain = builder->getUniformCStr(fGainUni); |
482 const char* bias = builder->getUniformCStr(fBiasUni); | 482 const char* bias = builder->getUniformCStr(fBiasUni); |
483 int kWidth = fKernelSize.width(); | 483 int kWidth = fKernelSize.width(); |
484 int kHeight = fKernelSize.height(); | 484 int kHeight = fKernelSize.height(); |
485 | 485 |
486 builder->fsCodeAppend("\t\tvec4 sum = vec4(0, 0, 0, 0);\n"); | 486 builder->fsCodeAppend("\t\tvec4 sum = vec4(0, 0, 0, 0);\n"); |
487 builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords2D.c_str(),
kernelOffset, imgInc); | 487 builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords2D.c_str(),
kernelOffset, imgInc); |
488 builder->fsCodeAppendf("\t\tfor (int y = 0; y < %d; y++) {\n", kHeight); | 488 builder->fsCodeAppendf("\t\tfor (int y = 0; y < %d; y++) {\n", kHeight); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvol
utionEffect>(); | 538 const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvol
utionEffect>(); |
539 GrTexture& texture = *conv.texture(0); | 539 GrTexture& texture = *conv.texture(0); |
540 // the code we generated was for a specific kernel size | 540 // the code we generated was for a specific kernel size |
541 SkASSERT(conv.kernelSize() == fKernelSize); | 541 SkASSERT(conv.kernelSize() == fKernelSize); |
542 SkASSERT(conv.tileMode() == fTileMode); | 542 SkASSERT(conv.tileMode() == fTileMode); |
543 float imageIncrement[2]; | 543 float imageIncrement[2]; |
544 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; | 544 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; |
545 imageIncrement[0] = 1.0f / texture.width(); | 545 imageIncrement[0] = 1.0f / texture.width(); |
546 imageIncrement[1] = ySign / texture.height(); | 546 imageIncrement[1] = ySign / texture.height(); |
547 uman.set2fv(fImageIncrementUni, 1, imageIncrement); | 547 uman.set2fv(fImageIncrementUni, 1, imageIncrement); |
548 uman.set2fv(fTargetUni, 1, conv.kernelOffset()); | 548 uman.set2fv(fKernelOffsetUni, 1, conv.kernelOffset()); |
549 uman.set1fv(fKernelUni, fKernelSize.width() * fKernelSize.height(), conv.ker
nel()); | 549 uman.set1fv(fKernelUni, fKernelSize.width() * fKernelSize.height(), conv.ker
nel()); |
550 uman.set1f(fGainUni, conv.gain()); | 550 uman.set1f(fGainUni, conv.gain()); |
551 uman.set1f(fBiasUni, conv.bias()); | 551 uman.set1f(fBiasUni, conv.bias()); |
552 const SkIRect& bounds = conv.bounds(); | 552 const SkIRect& bounds = conv.bounds(); |
553 float left = (float) bounds.left() / texture.width(); | 553 float left = (float) bounds.left() / texture.width(); |
554 float top = (float) bounds.top() / texture.height(); | 554 float top = (float) bounds.top() / texture.height(); |
555 float right = (float) bounds.right() / texture.width(); | 555 float right = (float) bounds.right() / texture.width(); |
556 float bottom = (float) bounds.bottom() / texture.height(); | 556 float bottom = (float) bounds.bottom() / texture.height(); |
557 if (texture.origin() == kBottomLeft_GrSurfaceOrigin) { | 557 if (texture.origin() == kBottomLeft_GrSurfaceOrigin) { |
558 uman.set4f(fBoundsUni, left, 1.0f - bottom, right, 1.0f - top); | 558 uman.set4f(fBoundsUni, left, 1.0f - bottom, right, 1.0f - top); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 fBias, | 664 fBias, |
665 fKernelOffset, | 665 fKernelOffset, |
666 fTileMode, | 666 fTileMode, |
667 fConvolveAlpha); | 667 fConvolveAlpha); |
668 return true; | 668 return true; |
669 } | 669 } |
670 | 670 |
671 /////////////////////////////////////////////////////////////////////////////// | 671 /////////////////////////////////////////////////////////////////////////////// |
672 | 672 |
673 #endif | 673 #endif |
OLD | NEW |