| 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 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 #define MAX_KERNEL_SIZE 25 | 532 #define MAX_KERNEL_SIZE 25 |
| 533 | 533 |
| 534 GrEffectRef* GrMatrixConvolutionEffect::TestCreate(SkMWCRandom* random, | 534 GrEffectRef* GrMatrixConvolutionEffect::TestCreate(SkMWCRandom* random, |
| 535 GrContext* context, | 535 GrContext* context, |
| 536 GrTexture* textures[]) { | 536 GrTexture* textures[]) { |
| 537 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 537 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
| 538 GrEffectUnitTest::kAlphaTextureIdx; | 538 GrEffectUnitTest::kAlphaTextureIdx; |
| 539 int width = random->nextRangeU(1, MAX_KERNEL_SIZE); | 539 int width = random->nextRangeU(1, MAX_KERNEL_SIZE); |
| 540 int height = random->nextRangeU(1, MAX_KERNEL_SIZE / width); | 540 int height = random->nextRangeU(1, MAX_KERNEL_SIZE / width); |
| 541 SkISize kernelSize = SkISize::Make(width, height); | 541 SkISize kernelSize = SkISize::Make(width, height); |
| 542 SkScalar* kernel = new SkScalar[width * height]; | 542 SkAutoTDeleteArray<SkScalar> kernel(new SkScalar[width * height]); |
| 543 for (int i = 0; i < width * height; i++) { | 543 for (int i = 0; i < width * height; i++) { |
| 544 kernel[i] = random->nextSScalar1(); | 544 kernel.get()[i] = random->nextSScalar1(); |
| 545 } | 545 } |
| 546 SkScalar gain = random->nextSScalar1(); | 546 SkScalar gain = random->nextSScalar1(); |
| 547 SkScalar bias = random->nextSScalar1(); | 547 SkScalar bias = random->nextSScalar1(); |
| 548 SkIPoint target = SkIPoint::Make(random->nextRangeU(0, kernelSize.width()), | 548 SkIPoint target = SkIPoint::Make(random->nextRangeU(0, kernelSize.width()), |
| 549 random->nextRangeU(0, kernelSize.height()))
; | 549 random->nextRangeU(0, kernelSize.height()))
; |
| 550 TileMode tileMode = static_cast<TileMode>(random->nextRangeU(0, 2)); | 550 TileMode tileMode = static_cast<TileMode>(random->nextRangeU(0, 2)); |
| 551 bool convolveAlpha = random->nextBool(); | 551 bool convolveAlpha = random->nextBool(); |
| 552 return GrMatrixConvolutionEffect::Create(textures[texIdx], | 552 return GrMatrixConvolutionEffect::Create(textures[texIdx], |
| 553 kernelSize, | 553 kernelSize, |
| 554 kernel, | 554 kernel.get(), |
| 555 gain, | 555 gain, |
| 556 bias, | 556 bias, |
| 557 target, | 557 target, |
| 558 tileMode, | 558 tileMode, |
| 559 convolveAlpha); | 559 convolveAlpha); |
| 560 | |
| 561 } | 560 } |
| 562 | 561 |
| 563 bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffectRef** effect, | 562 bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffectRef** effect, |
| 564 GrTexture* texture) const { | 563 GrTexture* texture) const { |
| 565 bool ok = fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE; | 564 bool ok = fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE; |
| 566 if (ok && effect) { | 565 if (ok && effect) { |
| 567 *effect = GrMatrixConvolutionEffect::Create(texture, | 566 *effect = GrMatrixConvolutionEffect::Create(texture, |
| 568 fKernelSize, | 567 fKernelSize, |
| 569 fKernel, | 568 fKernel, |
| 570 fGain, | 569 fGain, |
| 571 fBias, | 570 fBias, |
| 572 fTarget, | 571 fTarget, |
| 573 fTileMode, | 572 fTileMode, |
| 574 fConvolveAlpha); | 573 fConvolveAlpha); |
| 575 } | 574 } |
| 576 return ok; | 575 return ok; |
| 577 } | 576 } |
| 578 | 577 |
| 579 /////////////////////////////////////////////////////////////////////////////// | 578 /////////////////////////////////////////////////////////////////////////////// |
| 580 | 579 |
| 581 #endif | 580 #endif |
| OLD | NEW |