| 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 323 |
| 324 #if SK_SUPPORT_GPU | 324 #if SK_SUPPORT_GPU |
| 325 | 325 |
| 326 /////////////////////////////////////////////////////////////////////////////// | 326 /////////////////////////////////////////////////////////////////////////////// |
| 327 | 327 |
| 328 class GrGLMatrixConvolutionEffect; | 328 class GrGLMatrixConvolutionEffect; |
| 329 | 329 |
| 330 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { | 330 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { |
| 331 public: | 331 public: |
| 332 typedef SkMatrixConvolutionImageFilter::TileMode TileMode; | 332 typedef SkMatrixConvolutionImageFilter::TileMode TileMode; |
| 333 static GrEffectRef* Create(GrTexture* texture, | 333 static GrEffect* Create(GrTexture* texture, |
| 334 const SkIRect& bounds, | 334 const SkIRect& bounds, |
| 335 const SkISize& kernelSize, | 335 const SkISize& kernelSize, |
| 336 const SkScalar* kernel, | 336 const SkScalar* kernel, |
| 337 SkScalar gain, | 337 SkScalar gain, |
| 338 SkScalar bias, | 338 SkScalar bias, |
| 339 const SkIPoint& kernelOffset, | 339 const SkIPoint& kernelOffset, |
| 340 TileMode tileMode, | 340 TileMode tileMode, |
| 341 bool convolveAlpha) { | 341 bool convolveAlpha) { |
| 342 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, | 342 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, |
| 343 bounds, | 343 bounds, |
| 344 kernelSize, | 344 kernelSize, |
| 345 kernel, | 345 kernel, |
| 346 gain, | 346 gain, |
| 347 bias, | 347 bias, |
| 348 kernelOffset, | 348 kernelOffset, |
| 349 tileMode, | 349 tileMode, |
| 350 convolveAlpha)); | 350 convolveAlpha)); |
| 351 } | 351 } |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 fTileMode == s.tileMode() && | 618 fTileMode == s.tileMode() && |
| 619 fConvolveAlpha == s.convolveAlpha(); | 619 fConvolveAlpha == s.convolveAlpha(); |
| 620 } | 620 } |
| 621 | 621 |
| 622 GR_DEFINE_EFFECT_TEST(GrMatrixConvolutionEffect); | 622 GR_DEFINE_EFFECT_TEST(GrMatrixConvolutionEffect); |
| 623 | 623 |
| 624 // A little bit less than the minimum # uniforms required by DX9SM2 (32). | 624 // A little bit less than the minimum # uniforms required by DX9SM2 (32). |
| 625 // Allows for a 5x5 kernel (or 25x1, for that matter). | 625 // Allows for a 5x5 kernel (or 25x1, for that matter). |
| 626 #define MAX_KERNEL_SIZE 25 | 626 #define MAX_KERNEL_SIZE 25 |
| 627 | 627 |
| 628 GrEffectRef* GrMatrixConvolutionEffect::TestCreate(SkRandom* random, | 628 GrEffect* GrMatrixConvolutionEffect::TestCreate(SkRandom* random, |
| 629 GrContext* context, | 629 GrContext* context, |
| 630 const GrDrawTargetCaps&, | 630 const GrDrawTargetCaps&, |
| 631 GrTexture* textures[]) { | 631 GrTexture* textures[]) { |
| 632 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 632 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
| 633 GrEffectUnitTest::kAlphaTextureIdx; | 633 GrEffectUnitTest::kAlphaTextureIdx; |
| 634 int width = random->nextRangeU(1, MAX_KERNEL_SIZE); | 634 int width = random->nextRangeU(1, MAX_KERNEL_SIZE); |
| 635 int height = random->nextRangeU(1, MAX_KERNEL_SIZE / width); | 635 int height = random->nextRangeU(1, MAX_KERNEL_SIZE / width); |
| 636 SkISize kernelSize = SkISize::Make(width, height); | 636 SkISize kernelSize = SkISize::Make(width, height); |
| 637 SkAutoTDeleteArray<SkScalar> kernel(new SkScalar[width * height]); | 637 SkAutoTDeleteArray<SkScalar> kernel(new SkScalar[width * height]); |
| 638 for (int i = 0; i < width * height; i++) { | 638 for (int i = 0; i < width * height; i++) { |
| 639 kernel.get()[i] = random->nextSScalar1(); | 639 kernel.get()[i] = random->nextSScalar1(); |
| 640 } | 640 } |
| 641 SkScalar gain = random->nextSScalar1(); | 641 SkScalar gain = random->nextSScalar1(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 652 bounds, | 652 bounds, |
| 653 kernelSize, | 653 kernelSize, |
| 654 kernel.get(), | 654 kernel.get(), |
| 655 gain, | 655 gain, |
| 656 bias, | 656 bias, |
| 657 kernelOffset, | 657 kernelOffset, |
| 658 tileMode, | 658 tileMode, |
| 659 convolveAlpha); | 659 convolveAlpha); |
| 660 } | 660 } |
| 661 | 661 |
| 662 bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffectRef** effect, | 662 bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffect** effect, |
| 663 GrTexture* texture, | 663 GrTexture* texture, |
| 664 const SkMatrix&, | 664 const SkMatrix&, |
| 665 const SkIRect& bounds | 665 const SkIRect& bounds |
| 666 ) const { | 666 ) const { |
| 667 if (!effect) { | 667 if (!effect) { |
| 668 return fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE; | 668 return fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE; |
| 669 } | 669 } |
| 670 SkASSERT(fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE); | 670 SkASSERT(fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE); |
| 671 *effect = GrMatrixConvolutionEffect::Create(texture, | 671 *effect = GrMatrixConvolutionEffect::Create(texture, |
| 672 bounds, | 672 bounds, |
| 673 fKernelSize, | 673 fKernelSize, |
| 674 fKernel, | 674 fKernel, |
| 675 fGain, | 675 fGain, |
| 676 fBias, | 676 fBias, |
| 677 fKernelOffset, | 677 fKernelOffset, |
| 678 fTileMode, | 678 fTileMode, |
| 679 fConvolveAlpha); | 679 fConvolveAlpha); |
| 680 return true; | 680 return true; |
| 681 } | 681 } |
| 682 | 682 |
| 683 /////////////////////////////////////////////////////////////////////////////// | 683 /////////////////////////////////////////////////////////////////////////////// |
| 684 | 684 |
| 685 #endif | 685 #endif |
| OLD | NEW |