Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1896383003: Begin removing deprecated (and now, unused) ImageFilter code paths (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix comment Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/ImageFilterCacheTest.cpp ('k') | tests/SpecialImageTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 #include "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
11 #include "SkCanvas.h" 10 #include "SkCanvas.h"
12 #include "SkColorFilterImageFilter.h" 11 #include "SkColorFilterImageFilter.h"
13 #include "SkColorMatrixFilter.h" 12 #include "SkColorMatrixFilter.h"
14 #include "SkComposeImageFilter.h" 13 #include "SkComposeImageFilter.h"
15 #include "SkDisplacementMapEffect.h" 14 #include "SkDisplacementMapEffect.h"
16 #include "SkDropShadowImageFilter.h" 15 #include "SkDropShadowImageFilter.h"
17 #include "SkFlattenableSerialization.h" 16 #include "SkFlattenableSerialization.h"
18 #include "SkGradientShader.h" 17 #include "SkGradientShader.h"
19 #include "SkImage.h" 18 #include "SkImage.h"
(...skipping 11 matching lines...) Expand all
31 #include "SkPoint3.h" 30 #include "SkPoint3.h"
32 #include "SkReadBuffer.h" 31 #include "SkReadBuffer.h"
33 #include "SkRect.h" 32 #include "SkRect.h"
34 #include "SkSpecialImage.h" 33 #include "SkSpecialImage.h"
35 #include "SkSpecialSurface.h" 34 #include "SkSpecialSurface.h"
36 #include "SkSurface.h" 35 #include "SkSurface.h"
37 #include "SkTableColorFilter.h" 36 #include "SkTableColorFilter.h"
38 #include "SkTileImageFilter.h" 37 #include "SkTileImageFilter.h"
39 #include "SkXfermodeImageFilter.h" 38 #include "SkXfermodeImageFilter.h"
40 #include "Test.h" 39 #include "Test.h"
41 #include "TestingSpecialImageAccess.h"
42 40
43 #if SK_SUPPORT_GPU 41 #if SK_SUPPORT_GPU
44 #include "GrContext.h" 42 #include "GrContext.h"
45 #include "SkGpuDevice.h"
46 #endif 43 #endif
47 44
48 static const int kBitmapSize = 4; 45 static const int kBitmapSize = 4;
49 46
50 namespace { 47 namespace {
51 48
52 class MatrixTestImageFilter : public SkImageFilter { 49 class MatrixTestImageFilter : public SkImageFilter {
53 public: 50 public:
54 static sk_sp<SkImageFilter> Make(skiatest::Reporter* reporter, 51 static sk_sp<SkImageFilter> Make(skiatest::Reporter* reporter,
55 const SkMatrix& expectedMatrix) { 52 const SkMatrix& expectedMatrix) {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), c ropRect); 360 return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), c ropRect);
364 } 361 }
365 362
366 static sk_sp<SkImageFilter> make_blue(sk_sp<SkImageFilter> input, 363 static sk_sp<SkImageFilter> make_blue(sk_sp<SkImageFilter> input,
367 const SkImageFilter::CropRect* cropRect) { 364 const SkImageFilter::CropRect* cropRect) {
368 sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, 365 sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
369 SkXfermode::kSrcIn _Mode)); 366 SkXfermode::kSrcIn _Mode));
370 return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), c ropRect); 367 return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), c ropRect);
371 } 368 }
372 369
373 static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context, 370 static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context, int widthHeight) {
374 SkImageFilter::Proxy * proxy,
375 int widthHeight) {
376 if (context) { 371 if (context) {
377 GrSurfaceDesc desc; 372 GrSurfaceDesc desc;
378 desc.fConfig = kSkia8888_GrPixelConfig; 373 desc.fConfig = kSkia8888_GrPixelConfig;
379 desc.fFlags = kRenderTarget_GrSurfaceFlag; 374 desc.fFlags = kRenderTarget_GrSurfaceFlag;
380 desc.fWidth = widthHeight; 375 desc.fWidth = widthHeight;
381 desc.fHeight = widthHeight; 376 desc.fHeight = widthHeight;
382 return SkSpecialSurface::MakeRenderTarget(proxy, context, desc); 377 return SkSpecialSurface::MakeRenderTarget(context, desc);
383 } else { 378 } else {
384 const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight, 379 const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight,
385 kOpaque_SkAlphaType); 380 kOpaque_SkAlphaType);
386 return SkSpecialSurface::MakeRaster(proxy, info); 381 return SkSpecialSurface::MakeRaster(info);
387 } 382 }
388 } 383 }
389 384
390 static sk_sp<SkSpecialImage> create_empty_special_image(GrContext* context, 385 static sk_sp<SkSpecialImage> create_empty_special_image(GrContext* context, int widthHeight) {
391 SkImageFilter::Proxy* pr oxy, 386 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, widthHeig ht));
392 int widthHeight) {
393 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, wi dthHeight));
394 387
395 SkASSERT(surf); 388 SkASSERT(surf);
396 389
397 SkCanvas* canvas = surf->getCanvas(); 390 SkCanvas* canvas = surf->getCanvas();
398 SkASSERT(canvas); 391 SkASSERT(canvas);
399 392
400 canvas->clear(0x0); 393 canvas->clear(0x0);
401 394
402 return surf->makeImageSnapshot(); 395 return surf->makeImageSnapshot();
403 } 396 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, 507 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1,
515 std::move(bmSrc))); 508 std::move(bmSrc)));
516 SkCanvas canvas(result); 509 SkCanvas canvas(result);
517 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), 510 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize),
518 SkIntToScalar(kBitmapSize)); 511 SkIntToScalar(kBitmapSize));
519 canvas.drawRect(r, paint); 512 canvas.drawRect(r, paint);
520 } 513 }
521 } 514 }
522 } 515 }
523 516
524 static void test_crop_rects(SkImageFilter::Proxy* proxy, 517 static void test_crop_rects(skiatest::Reporter* reporter,
525 skiatest::Reporter* reporter,
526 GrContext* context) { 518 GrContext* context) {
527 // Check that all filters offset to their absolute crop rect, 519 // Check that all filters offset to their absolute crop rect,
528 // unaffected by the input crop rect. 520 // unaffected by the input crop rect.
529 // Tests pass by not asserting. 521 // Tests pass by not asserting.
530 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) ); 522 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100));
531 SkASSERT(srcImg); 523 SkASSERT(srcImg);
532 524
533 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); 525 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
534 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); 526 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60));
535 sk_sp<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect)); 527 sk_sp<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect));
536 528
537 FilterList filters(input, &cropRect); 529 FilterList filters(input, &cropRect);
538 530
539 for (int i = 0; i < filters.count(); ++i) { 531 for (int i = 0; i < filters.count(); ++i) {
540 SkImageFilter* filter = filters.getFilter(i); 532 SkImageFilter* filter = filters.getFilter(i);
541 SkIPoint offset; 533 SkIPoint offset;
542 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul lptr); 534 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul lptr);
543 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, & offset)); 535 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, & offset));
544 REPORTER_ASSERT_MESSAGE(reporter, resultImg, filters.getName(i)); 536 REPORTER_ASSERT_MESSAGE(reporter, resultImg, filters.getName(i));
545 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, fi lters.getName(i)); 537 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, fi lters.getName(i));
546 } 538 }
547 } 539 }
548 540
549 static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy, 541 static void test_negative_blur_sigma(skiatest::Reporter* reporter,
550 skiatest::Reporter* reporter,
551 GrContext* context) { 542 GrContext* context) {
552 // Check that SkBlurImageFilter will accept a negative sigma, either in 543 // Check that SkBlurImageFilter will accept a negative sigma, either in
553 // the given arguments or after CTM application. 544 // the given arguments or after CTM application.
554 const int width = 32, height = 32; 545 const int width = 32, height = 32;
555 const SkScalar five = SkIntToScalar(5); 546 const SkScalar five = SkIntToScalar(5);
556 547
557 sk_sp<SkImageFilter> positiveFilter(SkBlurImageFilter::Make(five, five, null ptr)); 548 sk_sp<SkImageFilter> positiveFilter(SkBlurImageFilter::Make(five, five, null ptr));
558 sk_sp<SkImageFilter> negativeFilter(SkBlurImageFilter::Make(-five, five, nul lptr)); 549 sk_sp<SkImageFilter> negativeFilter(SkBlurImageFilter::Make(-five, five, nul lptr));
559 550
560 SkBitmap gradient = make_gradient_circle(width, height); 551 SkBitmap gradient = make_gradient_circle(width, height);
561 sk_sp<SkSpecialImage> imgSrc(SkSpecialImage::MakeFromRaster(proxy, 552 sk_sp<SkSpecialImage> imgSrc(SkSpecialImage::MakeFromRaster(SkIRect::MakeWH( width, height),
562 SkIRect::MakeWH( width, height),
563 gradient)); 553 gradient));
564 554
565 SkIPoint offset; 555 SkIPoint offset;
566 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); 556 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr);
567 557
568 sk_sp<SkSpecialImage> positiveResult1(positiveFilter->filterImage(imgSrc.get (), ctx, &offset)); 558 sk_sp<SkSpecialImage> positiveResult1(positiveFilter->filterImage(imgSrc.get (), ctx, &offset));
569 REPORTER_ASSERT(reporter, positiveResult1); 559 REPORTER_ASSERT(reporter, positiveResult1);
570 560
571 sk_sp<SkSpecialImage> negativeResult1(negativeFilter->filterImage(imgSrc.get (), ctx, &offset)); 561 sk_sp<SkSpecialImage> negativeResult1(negativeFilter->filterImage(imgSrc.get (), ctx, &offset));
572 REPORTER_ASSERT(reporter, negativeResult1); 562 REPORTER_ASSERT(reporter, negativeResult1);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 diffs = memcmp(positiveResultBM1.getAddr32(0, y), 606 diffs = memcmp(positiveResultBM1.getAddr32(0, y),
617 positiveResultBM2.getAddr32(0, y), 607 positiveResultBM2.getAddr32(0, y),
618 positiveResultBM1.rowBytes()); 608 positiveResultBM1.rowBytes());
619 REPORTER_ASSERT(reporter, !diffs); 609 REPORTER_ASSERT(reporter, !diffs);
620 if (diffs) { 610 if (diffs) {
621 break; 611 break;
622 } 612 }
623 } 613 }
624 } 614 }
625 615
626 typedef void (*PFTest)(SkImageFilter::Proxy* proxy,
627 skiatest::Reporter* reporter,
628 GrContext* context);
629
630 static void run_raster_test(skiatest::Reporter* reporter,
631 int widthHeight,
632 PFTest test) {
633 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
634
635 const SkImageInfo info = SkImageInfo::MakeN32Premul(widthHeight, widthHeight );
636
637 sk_sp<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
638 SkImageFilter::DeviceProxy proxy(device.get());
639
640 (*test)(&proxy, reporter, nullptr);
641 }
642
643 #if SK_SUPPORT_GPU
644 static void run_gpu_test(skiatest::Reporter* reporter,
645 GrContext* context,
646 int widthHeight,
647 PFTest test) {
648 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
649
650 sk_sp<SkGpuDevice> device(SkGpuDevice::Create(context,
651 SkBudgeted::kNo,
652 SkImageInfo::MakeN32Premul(wid thHeight,
653 wid thHeight),
654 0,
655 &props,
656 SkGpuDevice::kUninit_InitConte nts));
657 SkImageFilter::DeviceProxy proxy(device.get());
658
659 (*test)(&proxy, reporter, context);
660 }
661 #endif
662
663 DEF_TEST(ImageFilterNegativeBlurSigma, reporter) { 616 DEF_TEST(ImageFilterNegativeBlurSigma, reporter) {
664 run_raster_test(reporter, 100, test_negative_blur_sigma); 617 test_negative_blur_sigma(reporter, nullptr);
665 } 618 }
666 619
667 #if SK_SUPPORT_GPU 620 #if SK_SUPPORT_GPU
668 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterNegativeBlurSigma_Gpu, reporter, c txInfo) { 621 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterNegativeBlurSigma_Gpu, reporter, c txInfo) {
669 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_negative_blur_sigma); 622 test_negative_blur_sigma(reporter, ctxInfo.fGrContext);
670 } 623 }
671 #endif 624 #endif
672 625
673 static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy, 626 static void test_zero_blur_sigma(skiatest::Reporter* reporter, GrContext* contex t) {
674 skiatest::Reporter* reporter,
675 GrContext* context) {
676 // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset w orks correctly. 627 // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset w orks correctly.
677 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10) )); 628 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10) ));
678 sk_sp<SkImageFilter> input(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRec t)); 629 sk_sp<SkImageFilter> input(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRec t));
679 sk_sp<SkImageFilter> filter(SkBlurImageFilter::Make(0, 0, std::move(input), &cropRect)); 630 sk_sp<SkImageFilter> filter(SkBlurImageFilter::Make(0, 0, std::move(input), &cropRect));
680 631
681 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, 10 )); 632 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, 10));
682 surf->getCanvas()->clear(SK_ColorGREEN); 633 surf->getCanvas()->clear(SK_ColorGREEN);
683 sk_sp<SkSpecialImage> image(surf->makeImageSnapshot()); 634 sk_sp<SkSpecialImage> image(surf->makeImageSnapshot());
684 635
685 SkIPoint offset; 636 SkIPoint offset;
686 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); 637 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr);
687 638
688 sk_sp<SkSpecialImage> result(filter->filterImage(image.get(), ctx, &offset)) ; 639 sk_sp<SkSpecialImage> result(filter->filterImage(image.get(), ctx, &offset)) ;
689 REPORTER_ASSERT(reporter, offset.fX == 5 && offset.fY == 0); 640 REPORTER_ASSERT(reporter, offset.fX == 5 && offset.fY == 0);
690 REPORTER_ASSERT(reporter, result); 641 REPORTER_ASSERT(reporter, result);
691 REPORTER_ASSERT(reporter, result->width() == 5 && result->height() == 10); 642 REPORTER_ASSERT(reporter, result->width() == 5 && result->height() == 10);
692 643
693 SkBitmap resultBM; 644 SkBitmap resultBM;
694 645
695 REPORTER_ASSERT(reporter, result->getROPixels(&resultBM)); 646 REPORTER_ASSERT(reporter, result->getROPixels(&resultBM));
696 647
697 SkAutoLockPixels lock(resultBM); 648 SkAutoLockPixels lock(resultBM);
698 for (int y = 0; y < resultBM.height(); y++) { 649 for (int y = 0; y < resultBM.height(); y++) {
699 for (int x = 0; x < resultBM.width(); x++) { 650 for (int x = 0; x < resultBM.width(); x++) {
700 bool diff = *resultBM.getAddr32(x, y) != SK_ColorGREEN; 651 bool diff = *resultBM.getAddr32(x, y) != SK_ColorGREEN;
701 REPORTER_ASSERT(reporter, !diff); 652 REPORTER_ASSERT(reporter, !diff);
702 if (diff) { 653 if (diff) {
703 break; 654 break;
704 } 655 }
705 } 656 }
706 } 657 }
707 } 658 }
708 659
709 DEF_TEST(ImageFilterZeroBlurSigma, reporter) { 660 DEF_TEST(ImageFilterZeroBlurSigma, reporter) {
710 run_raster_test(reporter, 100, test_zero_blur_sigma); 661 test_zero_blur_sigma(reporter, nullptr);
711 } 662 }
712 663
713 #if SK_SUPPORT_GPU 664 #if SK_SUPPORT_GPU
714 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterZeroBlurSigma_Gpu, reporter, ctxIn fo) { 665 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterZeroBlurSigma_Gpu, reporter, ctxIn fo) {
715 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_zero_blur_sigma); 666 test_zero_blur_sigma(reporter, ctxInfo.fGrContext);
716 } 667 }
717 #endif 668 #endif
718 669
719 670
720 // Tests that, even when an upstream filter has returned null (due to failure or clipping), a 671 // Tests that, even when an upstream filter has returned null (due to failure or clipping), a
721 // downstream filter that affects transparent black still does so even with a nu llptr input. 672 // downstream filter that affects transparent black still does so even with a nu llptr input.
722 static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy, 673 static void test_fail_affects_transparent_black(skiatest::Reporter* reporter, Gr Context* context) {
723 skiatest::Reporter* reporter,
724 GrContext* context) {
725 sk_sp<FailImageFilter> failFilter(new FailImageFilter()); 674 sk_sp<FailImageFilter> failFilter(new FailImageFilter());
726 sk_sp<SkSpecialImage> source(create_empty_special_image(context, proxy, 5)); 675 sk_sp<SkSpecialImage> source(create_empty_special_image(context, 5));
727 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nul lptr); 676 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nul lptr);
728 sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXf ermode::kSrc_Mode)); 677 sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXf ermode::kSrc_Mode));
729 SkASSERT(green->affectsTransparentBlack()); 678 SkASSERT(green->affectsTransparentBlack());
730 sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(std::move(gr een), 679 sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(std::move(gr een),
731 std::move(fa ilFilter))); 680 std::move(fa ilFilter)));
732 SkIPoint offset; 681 SkIPoint offset;
733 sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &of fset)); 682 sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &of fset));
734 REPORTER_ASSERT(reporter, nullptr != result.get()); 683 REPORTER_ASSERT(reporter, nullptr != result.get());
735 if (result.get()) { 684 if (result.get()) {
736 SkBitmap resultBM; 685 SkBitmap resultBM;
737 REPORTER_ASSERT(reporter, result->getROPixels(&resultBM)); 686 REPORTER_ASSERT(reporter, result->getROPixels(&resultBM));
738 SkAutoLockPixels lock(resultBM); 687 SkAutoLockPixels lock(resultBM);
739 REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN); 688 REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN);
740 } 689 }
741 } 690 }
742 691
743 DEF_TEST(ImageFilterFailAffectsTransparentBlack, reporter) { 692 DEF_TEST(ImageFilterFailAffectsTransparentBlack, reporter) {
744 run_raster_test(reporter, 100, test_fail_affects_transparent_black); 693 test_fail_affects_transparent_black(reporter, nullptr);
745 } 694 }
746 695
747 #if SK_SUPPORT_GPU 696 #if SK_SUPPORT_GPU
748 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterFailAffectsTransparentBlack_Gpu, r eporter, ctxInfo) { 697 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterFailAffectsTransparentBlack_Gpu, r eporter, ctxInfo) {
749 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_fail_affects_transparen t_black); 698 test_fail_affects_transparent_black(reporter, ctxInfo.fGrContext);
750 } 699 }
751 #endif 700 #endif
752 701
753 DEF_TEST(ImageFilterDrawTiled, reporter) { 702 DEF_TEST(ImageFilterDrawTiled, reporter) {
754 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly 703 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly
755 // match the same filters drawn with a single full-canvas bitmap draw. 704 // match the same filters drawn with a single full-canvas bitmap draw.
756 // Tests pass by not asserting. 705 // Tests pass by not asserting.
757 706
758 FilterList filters(nullptr); 707 FilterList filters(nullptr);
759 708
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 { 877 {
929 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, null ptr, 878 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, null ptr,
930 offset, nullp tr)); 879 offset, nullp tr));
931 SkRect bounds = SkRect::MakeWH(100, 100); 880 SkRect bounds = SkRect::MakeWH(100, 100);
932 // Intentionally aliasing here, as that's what the real callers do. 881 // Intentionally aliasing here, as that's what the real callers do.
933 bounds = composite->computeFastBounds(bounds); 882 bounds = composite->computeFastBounds(bounds);
934 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); 883 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100));
935 } 884 }
936 } 885 }
937 886
938 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, 887 static void test_imagefilter_merge_result_size(skiatest::Reporter* reporter, GrC ontext* context) {
939 skiatest::Reporter* reporter,
940 GrContext* context) {
941 SkBitmap greenBM; 888 SkBitmap greenBM;
942 greenBM.allocN32Pixels(20, 20); 889 greenBM.allocN32Pixels(20, 20);
943 greenBM.eraseColor(SK_ColorGREEN); 890 greenBM.eraseColor(SK_ColorGREEN);
944 sk_sp<SkImage> greenImage(SkImage::MakeFromBitmap(greenBM)); 891 sk_sp<SkImage> greenImage(SkImage::MakeFromBitmap(greenBM));
945 sk_sp<SkImageFilter> source(SkImageSource::Make(std::move(greenImage))); 892 sk_sp<SkImageFilter> source(SkImageSource::Make(std::move(greenImage)));
946 sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(source, source)); 893 sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(source, source));
947 894
948 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 1)); 895 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 1));
949 896
950 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr); 897 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr);
951 SkIPoint offset; 898 SkIPoint offset;
952 899
953 sk_sp<SkSpecialImage> resultImg(merge->filterImage(srcImg.get(), ctx, &offse t)); 900 sk_sp<SkSpecialImage> resultImg(merge->filterImage(srcImg.get(), ctx, &offse t));
954 REPORTER_ASSERT(reporter, resultImg); 901 REPORTER_ASSERT(reporter, resultImg);
955 902
956 REPORTER_ASSERT(reporter, resultImg->width() == 20 && resultImg->height() == 20); 903 REPORTER_ASSERT(reporter, resultImg->width() == 20 && resultImg->height() == 20);
957 } 904 }
958 905
959 DEF_TEST(ImageFilterMergeResultSize, reporter) { 906 DEF_TEST(ImageFilterMergeResultSize, reporter) {
960 run_raster_test(reporter, 100, test_imagefilter_merge_result_size); 907 test_imagefilter_merge_result_size(reporter, nullptr);
961 } 908 }
962 909
963 #if SK_SUPPORT_GPU 910 #if SK_SUPPORT_GPU
964 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterMergeResultSize_Gpu, reporter, ctxInfo) { 911 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterMergeResultSize_Gpu, reporter, ctxInfo) {
965 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_imagefilter_merge_resul t_size); 912 test_imagefilter_merge_result_size(reporter, ctxInfo.fGrContext);
966 } 913 }
967 #endif 914 #endif
968 915
969 static void draw_blurred_rect(SkCanvas* canvas) { 916 static void draw_blurred_rect(SkCanvas* canvas) {
970 SkPaint filterPaint; 917 SkPaint filterPaint;
971 filterPaint.setColor(SK_ColorWHITE); 918 filterPaint.setColor(SK_ColorWHITE);
972 filterPaint.setImageFilter(SkBlurImageFilter::Make(SkIntToScalar(8), 0, null ptr)); 919 filterPaint.setImageFilter(SkBlurImageFilter::Make(SkIntToScalar(8), 0, null ptr));
973 canvas->saveLayer(nullptr, &filterPaint); 920 canvas->saveLayer(nullptr, &filterPaint);
974 SkPaint whitePaint; 921 SkPaint whitePaint;
975 whitePaint.setColor(SK_ColorWHITE); 922 whitePaint.setColor(SK_ColorWHITE);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 SkPaint filterPaint; 1032 SkPaint filterPaint;
1086 filterPaint.setImageFilter(std::move(filter)); 1033 filterPaint.setImageFilter(std::move(filter));
1087 SkRect bounds = SkRect::MakeWH(1, 10); 1034 SkRect bounds = SkRect::MakeWH(1, 10);
1088 SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height)); 1035 SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height));
1089 SkPaint rectPaint; 1036 SkPaint rectPaint;
1090 canvas.saveLayer(&bounds, &filterPaint); 1037 canvas.saveLayer(&bounds, &filterPaint);
1091 canvas.drawRect(rect, rectPaint); 1038 canvas.drawRect(rect, rectPaint);
1092 canvas.restore(); 1039 canvas.restore();
1093 } 1040 }
1094 1041
1095 static void test_big_kernel(SkImageFilter::Proxy* proxy, 1042 static void test_big_kernel(skiatest::Reporter* reporter, GrContext* context) {
1096 skiatest::Reporter* reporter,
1097 GrContext* context) {
1098 // Check that a kernel that is too big for the GPU still works 1043 // Check that a kernel that is too big for the GPU still works
1099 SkScalar identityKernel[49] = { 1044 SkScalar identityKernel[49] = {
1100 0, 0, 0, 0, 0, 0, 0, 1045 0, 0, 0, 0, 0, 0, 0,
1101 0, 0, 0, 0, 0, 0, 0, 1046 0, 0, 0, 0, 0, 0, 0,
1102 0, 0, 0, 0, 0, 0, 0, 1047 0, 0, 0, 0, 0, 0, 0,
1103 0, 0, 0, 1, 0, 0, 0, 1048 0, 0, 0, 1, 0, 0, 0,
1104 0, 0, 0, 0, 0, 0, 0, 1049 0, 0, 0, 0, 0, 0, 0,
1105 0, 0, 0, 0, 0, 0, 0, 1050 0, 0, 0, 0, 0, 0, 0,
1106 0, 0, 0, 0, 0, 0, 0 1051 0, 0, 0, 0, 0, 0, 0
1107 }; 1052 };
1108 SkISize kernelSize = SkISize::Make(7, 7); 1053 SkISize kernelSize = SkISize::Make(7, 7);
1109 SkScalar gain = SK_Scalar1, bias = 0; 1054 SkScalar gain = SK_Scalar1, bias = 0;
1110 SkIPoint kernelOffset = SkIPoint::Make(0, 0); 1055 SkIPoint kernelOffset = SkIPoint::Make(0, 0);
1111 1056
1112 sk_sp<SkImageFilter> filter(SkMatrixConvolutionImageFilter::Make( 1057 sk_sp<SkImageFilter> filter(SkMatrixConvolutionImageFilter::Make(
1113 kernelSize, identityKernel, gain, bias, kernelOffset, 1058 kernelSize, identityKernel, gain, bias, kernelOffset,
1114 SkMatrixConvolutionImageFilter::kClamp_T ileMode, 1059 SkMatrixConvolutionImageFilter::kClamp_T ileMode,
1115 true, nullptr)); 1060 true, nullptr));
1116 1061
1117 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) ); 1062 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100));
1118 SkASSERT(srcImg); 1063 SkASSERT(srcImg);
1119 1064
1120 SkIPoint offset; 1065 SkIPoint offset;
1121 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); 1066 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr );
1122 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offs et)); 1067 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offs et));
1123 REPORTER_ASSERT(reporter, resultImg); 1068 REPORTER_ASSERT(reporter, resultImg);
1124 REPORTER_ASSERT(reporter, SkToBool(context) == resultImg->isTextureBacked()) ; 1069 REPORTER_ASSERT(reporter, SkToBool(context) == resultImg->isTextureBacked()) ;
1125 REPORTER_ASSERT(reporter, resultImg->width() == 100 && resultImg->height() = = 100); 1070 REPORTER_ASSERT(reporter, resultImg->width() == 100 && resultImg->height() = = 100);
1126 REPORTER_ASSERT(reporter, offset.fX == 0 && offset.fY == 0); 1071 REPORTER_ASSERT(reporter, offset.fX == 0 && offset.fY == 0);
1127 } 1072 }
1128 1073
1129 DEF_TEST(ImageFilterMatrixConvolutionBigKernel, reporter) { 1074 DEF_TEST(ImageFilterMatrixConvolutionBigKernel, reporter) {
1130 run_raster_test(reporter, 100, test_big_kernel); 1075 test_big_kernel(reporter, nullptr);
1131 } 1076 }
1132 1077
1133 #if SK_SUPPORT_GPU 1078 #if SK_SUPPORT_GPU
1134 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterMatrixConvolutionBigKernel_Gpu, 1079 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterMatrixConvolutionBigKernel_Gpu,
1135 reporter, ctxInfo) { 1080 reporter, ctxInfo) {
1136 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_big_kernel); 1081 test_big_kernel(reporter, ctxInfo.fGrContext);
1137 } 1082 }
1138 #endif 1083 #endif
1139 1084
1140 DEF_TEST(ImageFilterCropRect, reporter) { 1085 DEF_TEST(ImageFilterCropRect, reporter) {
1141 run_raster_test(reporter, 100, test_crop_rects); 1086 test_crop_rects(reporter, nullptr);
1142 } 1087 }
1143 1088
1144 #if SK_SUPPORT_GPU 1089 #if SK_SUPPORT_GPU
1145 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCropRect_Gpu, reporter, ctxInfo) { 1090 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCropRect_Gpu, reporter, ctxInfo) {
1146 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_crop_rects); 1091 test_crop_rects(reporter, ctxInfo.fGrContext);
1147 } 1092 }
1148 #endif 1093 #endif
1149 1094
1150 DEF_TEST(ImageFilterMatrix, reporter) { 1095 DEF_TEST(ImageFilterMatrix, reporter) {
1151 SkBitmap temp; 1096 SkBitmap temp;
1152 temp.allocN32Pixels(100, 100); 1097 temp.allocN32Pixels(100, 100);
1153 SkCanvas canvas(temp); 1098 SkCanvas canvas(temp);
1154 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); 1099 canvas.scale(SkIntToScalar(2), SkIntToScalar(2));
1155 1100
1156 SkMatrix expectedMatrix = canvas.getTotalMatrix(); 1101 SkMatrix expectedMatrix = canvas.getTotalMatrix();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 1170
1226 canvas.clear(0x0); 1171 canvas.clear(0x0);
1227 canvas.drawPicture(crossProcessPicture); 1172 canvas.drawPicture(crossProcessPicture);
1228 pixel = *bitmap.getAddr32(0, 0); 1173 pixel = *bitmap.getAddr32(0, 0);
1229 // If the security precautions are enabled, the result here should not be gr een, since the 1174 // If the security precautions are enabled, the result here should not be gr een, since the
1230 // filter draws nothing. 1175 // filter draws nothing.
1231 REPORTER_ASSERT(reporter, SkPicture::PictureIOSecurityPrecautionsEnabled() 1176 REPORTER_ASSERT(reporter, SkPicture::PictureIOSecurityPrecautionsEnabled()
1232 ? pixel != SK_ColorGREEN : pixel == SK_ColorGREEN); 1177 ? pixel != SK_ColorGREEN : pixel == SK_ColorGREEN);
1233 } 1178 }
1234 1179
1235 static void test_clipped_picture_imagefilter(SkImageFilter::Proxy* proxy, 1180 static void test_clipped_picture_imagefilter(skiatest::Reporter* reporter, GrCon text* context) {
1236 skiatest::Reporter* reporter,
1237 GrContext* context) {
1238 sk_sp<SkPicture> picture; 1181 sk_sp<SkPicture> picture;
1239 1182
1240 { 1183 {
1241 SkRTreeFactory factory; 1184 SkRTreeFactory factory;
1242 SkPictureRecorder recorder; 1185 SkPictureRecorder recorder;
1243 SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0); 1186 SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0);
1244 1187
1245 // Create an SkPicture which simply draws a green 1x1 rectangle. 1188 // Create an SkPicture which simply draws a green 1x1 rectangle.
1246 SkPaint greenPaint; 1189 SkPaint greenPaint;
1247 greenPaint.setColor(SK_ColorGREEN); 1190 greenPaint.setColor(SK_ColorGREEN);
1248 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPain t); 1191 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPain t);
1249 picture = recorder.finishRecordingAsPicture(); 1192 picture = recorder.finishRecordingAsPicture();
1250 } 1193 }
1251 1194
1252 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 2)); 1195 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 2));
1253 1196
1254 sk_sp<SkImageFilter> imageFilter(SkPictureImageFilter::Make(picture)); 1197 sk_sp<SkImageFilter> imageFilter(SkPictureImageFilter::Make(picture));
1255 1198
1256 SkIPoint offset; 1199 SkIPoint offset;
1257 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul lptr); 1200 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul lptr);
1258 1201
1259 sk_sp<SkSpecialImage> resultImage(imageFilter->filterImage(srcImg.get(), ctx , &offset)); 1202 sk_sp<SkSpecialImage> resultImage(imageFilter->filterImage(srcImg.get(), ctx , &offset));
1260 REPORTER_ASSERT(reporter, !resultImage); 1203 REPORTER_ASSERT(reporter, !resultImage);
1261 } 1204 }
1262 1205
1263 DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) { 1206 DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) {
1264 run_raster_test(reporter, 2, test_clipped_picture_imagefilter); 1207 test_clipped_picture_imagefilter(reporter, nullptr);
1265 } 1208 }
1266 1209
1267 #if SK_SUPPORT_GPU 1210 #if SK_SUPPORT_GPU
1268 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterClippedPictureImageFilter_Gpu, rep orter, ctxInfo) { 1211 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterClippedPictureImageFilter_Gpu, rep orter, ctxInfo) {
1269 run_gpu_test(reporter, ctxInfo.fGrContext, 2, test_clipped_picture_imagefilt er); 1212 test_clipped_picture_imagefilter(reporter, ctxInfo.fGrContext);
1270 } 1213 }
1271 #endif 1214 #endif
1272 1215
1273 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { 1216 DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
1274 // Even when there's an empty saveLayer()/restore(), ensure that an image 1217 // Even when there's an empty saveLayer()/restore(), ensure that an image
1275 // filter or color filter which affects transparent black still draws. 1218 // filter or color filter which affects transparent black still draws.
1276 1219
1277 SkBitmap bitmap; 1220 SkBitmap bitmap;
1278 bitmap.allocN32Pixels(10, 10); 1221 bitmap.allocN32Pixels(10, 10);
1279 SkCanvas canvas(bitmap); 1222 SkCanvas canvas(bitmap);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 1436 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
1494 } 1437 }
1495 1438
1496 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { 1439 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) {
1497 SkBitmap temp; 1440 SkBitmap temp;
1498 temp.allocN32Pixels(100, 100); 1441 temp.allocN32Pixels(100, 100);
1499 SkCanvas canvas(temp); 1442 SkCanvas canvas(temp);
1500 test_xfermode_cropped_input(&canvas, reporter); 1443 test_xfermode_cropped_input(&canvas, reporter);
1501 } 1444 }
1502 1445
1503 static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy, 1446 static void test_composed_imagefilter_offset(skiatest::Reporter* reporter, GrCon text* context) {
1504 skiatest::Reporter* reporter, 1447 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100));
1505 GrContext* context) {
1506 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) );
1507 1448
1508 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); 1449 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20));
1509 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(0, 0, nullptr, & cropRect)); 1450 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(0, 0, nullptr, & cropRect));
1510 sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Make(SK_Scalar1, SK_Scala r1, 1451 sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Make(SK_Scalar1, SK_Scala r1,
1511 nullptr, &cropRect)) ; 1452 nullptr, &cropRect)) ;
1512 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blu rFilter), 1453 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blu rFilter),
1513 std::move(off setFilter))); 1454 std::move(off setFilter)));
1514 SkIPoint offset; 1455 SkIPoint offset;
1515 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); 1456 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr );
1516 1457
1517 sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ct x, &offset)); 1458 sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ct x, &offset));
1518 REPORTER_ASSERT(reporter, resultImg); 1459 REPORTER_ASSERT(reporter, resultImg);
1519 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); 1460 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0);
1520 } 1461 }
1521 1462
1522 DEF_TEST(ComposedImageFilterOffset, reporter) { 1463 DEF_TEST(ComposedImageFilterOffset, reporter) {
1523 run_raster_test(reporter, 100, test_composed_imagefilter_offset); 1464 test_composed_imagefilter_offset(reporter, nullptr);
1524 } 1465 }
1525 1466
1526 #if SK_SUPPORT_GPU 1467 #if SK_SUPPORT_GPU
1527 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ComposedImageFilterOffset_Gpu, reporter, ctxI nfo) { 1468 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ComposedImageFilterOffset_Gpu, reporter, ctxI nfo) {
1528 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_composed_imagefilter_of fset); 1469 test_composed_imagefilter_offset(reporter, ctxInfo.fGrContext);
1529 } 1470 }
1530 #endif 1471 #endif
1531 1472
1532 static void test_composed_imagefilter_bounds(SkImageFilter::Proxy* proxy, 1473 static void test_composed_imagefilter_bounds(skiatest::Reporter* reporter, GrCon text* context) {
1533 skiatest::Reporter* reporter,
1534 GrContext* context) {
1535 // The bounds passed to the inner filter must be filtered by the outer 1474 // The bounds passed to the inner filter must be filtered by the outer
1536 // filter, so that the inner filter produces the pixels that the outer 1475 // filter, so that the inner filter produces the pixels that the outer
1537 // filter requires as input. This matters if the outer filter moves pixels. 1476 // filter requires as input. This matters if the outer filter moves pixels.
1538 // Here, accounting for the outer offset is necessary so that the green 1477 // Here, accounting for the outer offset is necessary so that the green
1539 // pixels of the picture are not clipped. 1478 // pixels of the picture are not clipped.
1540 1479
1541 SkPictureRecorder recorder; 1480 SkPictureRecorder recorder;
1542 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(200, 100) ); 1481 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(200, 100) );
1543 recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); 1482 recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100));
1544 recordingCanvas->clear(SK_ColorGREEN); 1483 recordingCanvas->clear(SK_ColorGREEN);
1545 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); 1484 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
1546 sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture)); 1485 sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture));
1547 SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100)); 1486 SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100));
1548 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(-100, 0, nullptr , &cropRect)); 1487 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(-100, 0, nullptr , &cropRect));
1549 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(off setFilter), 1488 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(off setFilter),
1550 std::move(pic tureFilter))); 1489 std::move(pic tureFilter)));
1551 1490
1552 sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, proxy, 100)); 1491 sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, 100));
1553 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); 1492 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr );
1554 SkIPoint offset; 1493 SkIPoint offset;
1555 sk_sp<SkSpecialImage> result(composedFilter->filterImage(sourceImage.get(), ctx, &offset)); 1494 sk_sp<SkSpecialImage> result(composedFilter->filterImage(sourceImage.get(), ctx, &offset));
1556 REPORTER_ASSERT(reporter, offset.isZero()); 1495 REPORTER_ASSERT(reporter, offset.isZero());
1557 REPORTER_ASSERT(reporter, result); 1496 REPORTER_ASSERT(reporter, result);
1558 REPORTER_ASSERT(reporter, result->subset().size() == SkISize::Make(100, 100) ); 1497 REPORTER_ASSERT(reporter, result->subset().size() == SkISize::Make(100, 100) );
1559 1498
1560 SkBitmap resultBM; 1499 SkBitmap resultBM;
1561 REPORTER_ASSERT(reporter, result->getROPixels(&resultBM)); 1500 REPORTER_ASSERT(reporter, result->getROPixels(&resultBM));
1562 SkAutoLockPixels lock(resultBM); 1501 SkAutoLockPixels lock(resultBM);
1563 REPORTER_ASSERT(reporter, resultBM.getColor(50, 50) == SK_ColorGREEN); 1502 REPORTER_ASSERT(reporter, resultBM.getColor(50, 50) == SK_ColorGREEN);
1564 } 1503 }
1565 1504
1566 DEF_TEST(ComposedImageFilterBounds, reporter) { 1505 DEF_TEST(ComposedImageFilterBounds, reporter) {
1567 run_raster_test(reporter, 100, test_composed_imagefilter_bounds); 1506 test_composed_imagefilter_bounds(reporter, nullptr);
1568 } 1507 }
1569 1508
1570 #if SK_SUPPORT_GPU 1509 #if SK_SUPPORT_GPU
1571 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ComposedImageFilterBounds_Gpu, reporter, c txInfo) { 1510 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ComposedImageFilterBounds_Gpu, reporter, c txInfo) {
1572 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_composed_imagefilter_bo unds); 1511 test_composed_imagefilter_bounds(reporter, ctxInfo.fGrContext);
1573 } 1512 }
1574 #endif 1513 #endif
1575 1514
1576 static void test_partial_crop_rect(SkImageFilter::Proxy* proxy, 1515 static void test_partial_crop_rect(skiatest::Reporter* reporter, GrContext* cont ext) {
1577 skiatest::Reporter* reporter, 1516 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100));
1578 GrContext* context) {
1579 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) );
1580 1517
1581 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), 1518 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30),
1582 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge); 1519 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge);
1583 sk_sp<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); 1520 sk_sp<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
1584 SkIPoint offset; 1521 SkIPoint offset;
1585 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); 1522 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr );
1586 1523
1587 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offs et)); 1524 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offs et));
1588 REPORTER_ASSERT(reporter, resultImg); 1525 REPORTER_ASSERT(reporter, resultImg);
1589 1526
1590 REPORTER_ASSERT(reporter, offset.fX == 0); 1527 REPORTER_ASSERT(reporter, offset.fX == 0);
1591 REPORTER_ASSERT(reporter, offset.fY == 0); 1528 REPORTER_ASSERT(reporter, offset.fY == 0);
1592 REPORTER_ASSERT(reporter, resultImg->width() == 20); 1529 REPORTER_ASSERT(reporter, resultImg->width() == 20);
1593 REPORTER_ASSERT(reporter, resultImg->height() == 30); 1530 REPORTER_ASSERT(reporter, resultImg->height() == 30);
1594 } 1531 }
1595 1532
1596 DEF_TEST(ImageFilterPartialCropRect, reporter) { 1533 DEF_TEST(ImageFilterPartialCropRect, reporter) {
1597 run_raster_test(reporter, 100, test_partial_crop_rect); 1534 test_partial_crop_rect(reporter, nullptr);
1598 } 1535 }
1599 1536
1600 #if SK_SUPPORT_GPU 1537 #if SK_SUPPORT_GPU
1601 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterPartialCropRect_Gpu, reporter, ctx Info) { 1538 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterPartialCropRect_Gpu, reporter, ctx Info) {
1602 run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_partial_crop_rect); 1539 test_partial_crop_rect(reporter, ctxInfo.fGrContext);
1603 } 1540 }
1604 #endif 1541 #endif
1605 1542
1606 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { 1543 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
1607 1544
1608 { 1545 {
1609 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); 1546 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
1610 sk_sp<SkImageFilter> lighting(SkLightingImageFilter::MakePointLitDiffuse (location, 1547 sk_sp<SkImageFilter> lighting(SkLightingImageFilter::MakePointLitDiffuse (location,
1611 SK_ColorGREEN, 1548 SK_ColorGREEN,
1612 0, 0, nullptr)); 1549 0, 0, nullptr));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 } 1670 }
1734 1671
1735 DEF_TEST(ImageFilterBlurLargeImage, reporter) { 1672 DEF_TEST(ImageFilterBlurLargeImage, reporter) {
1736 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100))); 1673 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100)));
1737 test_large_blur_input(reporter, surface->getCanvas()); 1674 test_large_blur_input(reporter, surface->getCanvas());
1738 } 1675 }
1739 1676
1740 #if SK_SUPPORT_GPU 1677 #if SK_SUPPORT_GPU
1741 1678
1742 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterHugeBlur_Gpu, reporter, ctxInfo) { 1679 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterHugeBlur_Gpu, reporter, ctxInfo) {
1743 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
1744 1680
1745 sk_sp<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext, 1681 sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.fGrContext,
1746 SkBudgeted::kNo, 1682 SkBudgeted::kNo,
1747 SkImageInfo::MakeN32Premul(100 , 100), 1683 SkImageInfo::MakeN32Premul (100, 100)));
1748 0,
1749 &props,
1750 SkGpuDevice::kUninit_InitConte nts));
1751 SkCanvas canvas(device.get());
1752 1684
1753 test_huge_blur(&canvas, reporter); 1685
1686 SkCanvas* canvas = surf->getCanvas();
1687
1688 test_huge_blur(canvas, reporter);
1754 } 1689 }
1755 1690
1756 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, repor ter, ctxInfo) { 1691 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, repor ter, ctxInfo) {
1757 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
1758 1692
1759 sk_sp<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext, 1693 sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.fGrContext,
1760 SkBudgeted::kNo, 1694 SkBudgeted::kNo,
1761 SkImageInfo::MakeN32Premul(1, 1), 1695 SkImageInfo::MakeN32Premul (1, 1)));
1762 0,
1763 &props,
1764 SkGpuDevice::kUninit_InitConte nts));
1765 SkCanvas canvas(device.get());
1766 1696
1767 test_xfermode_cropped_input(&canvas, reporter); 1697
1698 SkCanvas* canvas = surf->getCanvas();
1699
1700 test_xfermode_cropped_input(canvas, reporter);
1768 } 1701 }
1769 1702
1770 DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(ImageFilterBlurLargeImage_Gpu, reporter, ctxInfo ) { 1703 DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(ImageFilterBlurLargeImage_Gpu, reporter, ctxInfo ) {
1771 auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kYe s, 1704 auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kYe s,
1772 SkImageInfo::MakeN32Premul(100, 100 ))); 1705 SkImageInfo::MakeN32Premul(100, 100 )));
1773 test_large_blur_input(reporter, surface->getCanvas()); 1706 test_large_blur_input(reporter, surface->getCanvas());
1774 } 1707 }
1775 #endif 1708 #endif
OLDNEW
« no previous file with comments | « tests/ImageFilterCacheTest.cpp ('k') | tests/SpecialImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698