OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
10 #include "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 wid
thHeight), | 654 wid
thHeight), |
655 0, | 655 0, |
656 &props, | 656 &props, |
657 SkGpuDevice::kUninit_InitConte
nts)); | 657 SkGpuDevice::kUninit_InitConte
nts)); |
658 SkImageFilter::DeviceProxy proxy(device.get()); | 658 SkImageFilter::DeviceProxy proxy(device.get()); |
659 | 659 |
660 (*test)(&proxy, reporter, context); | 660 (*test)(&proxy, reporter, context); |
661 } | 661 } |
662 #endif | 662 #endif |
663 | 663 |
664 DEF_TEST(TestNegativeBlurSigma, reporter) { | 664 DEF_TEST(ImageFilterNegativeBlurSigma, reporter) { |
665 run_raster_test(reporter, 100, test_negative_blur_sigma); | 665 run_raster_test(reporter, 100, test_negative_blur_sigma); |
666 } | 666 } |
667 | 667 |
668 #if SK_SUPPORT_GPU | 668 #if SK_SUPPORT_GPU |
669 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(TestNegativeBlurSigma_Gpu, reporter, ctxIn
fo) { | 669 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterNegativeBlurSigma_Gpu, reporter
, ctxInfo) { |
670 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_negative_blur_sigma); | 670 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_negative_blur_sigma); |
671 } | 671 } |
672 #endif | 672 #endif |
673 | 673 |
674 static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy, | 674 static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy, |
675 skiatest::Reporter* reporter, | 675 skiatest::Reporter* reporter, |
676 GrContext* context) { | 676 GrContext* context) { |
677 // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset w
orks correctly. | 677 // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset w
orks correctly. |
678 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10)
)); | 678 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10)
)); |
679 sk_sp<SkImageFilter> input(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRec
t)); | 679 sk_sp<SkImageFilter> input(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRec
t)); |
(...skipping 20 matching lines...) Expand all Loading... |
700 for (int x = 0; x < resultBM.width(); x++) { | 700 for (int x = 0; x < resultBM.width(); x++) { |
701 bool diff = *resultBM.getAddr32(x, y) != SK_ColorGREEN; | 701 bool diff = *resultBM.getAddr32(x, y) != SK_ColorGREEN; |
702 REPORTER_ASSERT(reporter, !diff); | 702 REPORTER_ASSERT(reporter, !diff); |
703 if (diff) { | 703 if (diff) { |
704 break; | 704 break; |
705 } | 705 } |
706 } | 706 } |
707 } | 707 } |
708 } | 708 } |
709 | 709 |
710 DEF_TEST(TestZeroBlurSigma, reporter) { | 710 DEF_TEST(ImageFilterZeroBlurSigma, reporter) { |
711 run_raster_test(reporter, 100, test_zero_blur_sigma); | 711 run_raster_test(reporter, 100, test_zero_blur_sigma); |
712 } | 712 } |
713 | 713 |
714 #if SK_SUPPORT_GPU | 714 #if SK_SUPPORT_GPU |
715 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(TestZeroBlurSigma_Gpu, reporter, ctxInfo)
{ | 715 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterZeroBlurSigma_Gpu, reporter, ct
xInfo) { |
716 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_zero_blur_sigma); | 716 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_zero_blur_sigma); |
717 } | 717 } |
718 #endif | 718 #endif |
719 | 719 |
720 | 720 |
721 // Tests that, even when an upstream filter has returned null (due to failure or
clipping), a | 721 // Tests that, even when an upstream filter has returned null (due to failure or
clipping), a |
722 // downstream filter that affects transparent black still does so even with a nu
llptr input. | 722 // downstream filter that affects transparent black still does so even with a nu
llptr input. |
723 static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy, | 723 static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy, |
724 skiatest::Reporter* reporter, | 724 skiatest::Reporter* reporter, |
725 GrContext* context) { | 725 GrContext* context) { |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 canvas->drawBitmap(bitmap, 0, 0, &paint); | 1291 canvas->drawBitmap(bitmap, 0, 0, &paint); |
1292 } | 1292 } |
1293 | 1293 |
1294 DEF_TEST(HugeBlurImageFilter, reporter) { | 1294 DEF_TEST(HugeBlurImageFilter, reporter) { |
1295 SkBitmap temp; | 1295 SkBitmap temp; |
1296 temp.allocN32Pixels(100, 100); | 1296 temp.allocN32Pixels(100, 100); |
1297 SkCanvas canvas(temp); | 1297 SkCanvas canvas(temp); |
1298 test_huge_blur(&canvas, reporter); | 1298 test_huge_blur(&canvas, reporter); |
1299 } | 1299 } |
1300 | 1300 |
1301 DEF_TEST(MatrixConvolutionSanityTest, reporter) { | 1301 DEF_TEST(ImageFilterMatrixConvolutionSanityTest, reporter) { |
1302 SkScalar kernel[1] = { 0 }; | 1302 SkScalar kernel[1] = { 0 }; |
1303 SkScalar gain = SK_Scalar1, bias = 0; | 1303 SkScalar gain = SK_Scalar1, bias = 0; |
1304 SkIPoint kernelOffset = SkIPoint::Make(1, 1); | 1304 SkIPoint kernelOffset = SkIPoint::Make(1, 1); |
1305 | 1305 |
1306 // Check that an enormous (non-allocatable) kernel gives a nullptr filter. | 1306 // Check that an enormous (non-allocatable) kernel gives a nullptr filter. |
1307 sk_sp<SkImageFilter> conv(SkMatrixConvolutionImageFilter::Make( | 1307 sk_sp<SkImageFilter> conv(SkMatrixConvolutionImageFilter::Make( |
1308 SkISize::Make(1<<30, 1<<30), | 1308 SkISize::Make(1<<30, 1<<30), |
1309 kernel, | 1309 kernel, |
1310 gain, | 1310 gain, |
1311 bias, | 1311 bias, |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 | 1542 |
1543 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offs
et)); | 1543 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offs
et)); |
1544 REPORTER_ASSERT(reporter, resultImg); | 1544 REPORTER_ASSERT(reporter, resultImg); |
1545 | 1545 |
1546 REPORTER_ASSERT(reporter, offset.fX == 0); | 1546 REPORTER_ASSERT(reporter, offset.fX == 0); |
1547 REPORTER_ASSERT(reporter, offset.fY == 0); | 1547 REPORTER_ASSERT(reporter, offset.fY == 0); |
1548 REPORTER_ASSERT(reporter, resultImg->width() == 20); | 1548 REPORTER_ASSERT(reporter, resultImg->width() == 20); |
1549 REPORTER_ASSERT(reporter, resultImg->height() == 30); | 1549 REPORTER_ASSERT(reporter, resultImg->height() == 30); |
1550 } | 1550 } |
1551 | 1551 |
1552 DEF_TEST(PartialCropRect, reporter) { | 1552 DEF_TEST(ImageFilterPartialCropRect, reporter) { |
1553 run_raster_test(reporter, 100, test_partial_crop_rect); | 1553 run_raster_test(reporter, 100, test_partial_crop_rect); |
1554 } | 1554 } |
1555 | 1555 |
1556 #if SK_SUPPORT_GPU | 1556 #if SK_SUPPORT_GPU |
1557 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(PartialCropRect_Gpu, reporter, ctxInfo) { | 1557 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterPartialCropRect_Gpu, reporter,
ctxInfo) { |
1558 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_partial_crop_rect); | 1558 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_partial_crop_rect); |
1559 } | 1559 } |
1560 #endif | 1560 #endif |
1561 | 1561 |
1562 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { | 1562 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { |
1563 | 1563 |
1564 { | 1564 { |
1565 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 1565 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
1566 sk_sp<SkImageFilter> lighting(SkLightingImageFilter::MakePointLitDiffuse
(location, | 1566 sk_sp<SkImageFilter> lighting(SkLightingImageFilter::MakePointLitDiffuse
(location, |
1567
SK_ColorGREEN, | 1567
SK_ColorGREEN, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 return; | 1681 return; |
1682 } | 1682 } |
1683 | 1683 |
1684 SkPaint paint; | 1684 SkPaint paint; |
1685 paint.setImageFilter(std::move(blur)); | 1685 paint.setImageFilter(std::move(blur)); |
1686 | 1686 |
1687 // This should not crash (http://crbug.com/570479). | 1687 // This should not crash (http://crbug.com/570479). |
1688 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); | 1688 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); |
1689 } | 1689 } |
1690 | 1690 |
1691 DEF_TEST(BlurLargeImage, reporter) { | 1691 DEF_TEST(ImageFilterBlurLargeImage, reporter) { |
1692 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100))); | 1692 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100))); |
1693 test_large_blur_input(reporter, surface->getCanvas()); | 1693 test_large_blur_input(reporter, surface->getCanvas()); |
1694 } | 1694 } |
1695 | 1695 |
1696 #if SK_SUPPORT_GPU | 1696 #if SK_SUPPORT_GPU |
1697 | 1697 |
1698 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(HugeBlurImageFilter_Gpu, reporter, ctxInfo
) { | 1698 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterHugeBlur_Gpu, reporter, ctxInfo
) { |
1699 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1699 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
1700 | 1700 |
1701 sk_sp<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext, | 1701 sk_sp<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext, |
1702 SkBudgeted::kNo, | 1702 SkBudgeted::kNo, |
1703 SkImageInfo::MakeN32Premul(100
, 100), | 1703 SkImageInfo::MakeN32Premul(100
, 100), |
1704 0, | 1704 0, |
1705 &props, | 1705 &props, |
1706 SkGpuDevice::kUninit_InitConte
nts)); | 1706 SkGpuDevice::kUninit_InitConte
nts)); |
1707 SkCanvas canvas(device.get()); | 1707 SkCanvas canvas(device.get()); |
1708 | 1708 |
1709 test_huge_blur(&canvas, reporter); | 1709 test_huge_blur(&canvas, reporter); |
1710 } | 1710 } |
1711 | 1711 |
1712 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, repor
ter, ctxInfo) { | 1712 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, repor
ter, ctxInfo) { |
1713 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1713 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
1714 | 1714 |
1715 sk_sp<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext, | 1715 sk_sp<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext, |
1716 SkBudgeted::kNo, | 1716 SkBudgeted::kNo, |
1717 SkImageInfo::MakeN32Premul(1,
1), | 1717 SkImageInfo::MakeN32Premul(1,
1), |
1718 0, | 1718 0, |
1719 &props, | 1719 &props, |
1720 SkGpuDevice::kUninit_InitConte
nts)); | 1720 SkGpuDevice::kUninit_InitConte
nts)); |
1721 SkCanvas canvas(device.get()); | 1721 SkCanvas canvas(device.get()); |
1722 | 1722 |
1723 test_xfermode_cropped_input(&canvas, reporter); | 1723 test_xfermode_cropped_input(&canvas, reporter); |
1724 } | 1724 } |
1725 | 1725 |
1726 DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(BlurLargeImage_Gpu, reporter, ctxInfo) { | 1726 DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(ImageFilterBlurLargeImage_Gpu, reporter, ctxInfo
) { |
1727 auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kYe
s, | 1727 auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kYe
s, |
1728 SkImageInfo::MakeN32Premul(100, 100
))); | 1728 SkImageInfo::MakeN32Premul(100, 100
))); |
1729 test_large_blur_input(reporter, surface->getCanvas()); | 1729 test_large_blur_input(reporter, surface->getCanvas()); |
1730 } | 1730 } |
1731 #endif | 1731 #endif |
OLD | NEW |