OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 buffer.writeMatrix(fExpectedMatrix); | 72 buffer.writeMatrix(fExpectedMatrix); |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 skiatest::Reporter* fReporter; | 76 skiatest::Reporter* fReporter; |
77 SkMatrix fExpectedMatrix; | 77 SkMatrix fExpectedMatrix; |
78 | 78 |
79 typedef SkImageFilter INHERITED; | 79 typedef SkImageFilter INHERITED; |
80 }; | 80 }; |
81 | 81 |
82 class FailImageFilter : public SkImageFilter { | |
83 public: | |
84 FailImageFilter() : SkImageFilter(0, nullptr) { | |
85 } | |
86 | |
87 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, | |
88 const Context& ctx, | |
89 SkIPoint* offset) const override { | |
90 return nullptr; | |
91 } | |
92 | |
93 SK_TO_STRING_OVERRIDE() | |
94 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) | |
95 | |
96 private: | |
97 typedef SkImageFilter INHERITED; | |
98 }; | |
99 | |
100 SkFlattenable* FailImageFilter::CreateProc(SkReadBuffer& buffer) { | |
101 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); | |
102 return new FailImageFilter(); | |
103 } | |
104 | |
105 #ifndef SK_IGNORE_TO_STRING | |
106 void FailImageFilter::toString(SkString* str) const { | |
107 str->appendf("FailImageFilter: ("); | |
108 str->append(")"); | |
109 } | |
110 #endif | |
111 | |
82 void draw_gradient_circle(SkCanvas* canvas, int width, int height) { | 112 void draw_gradient_circle(SkCanvas* canvas, int width, int height) { |
83 SkScalar x = SkIntToScalar(width / 2); | 113 SkScalar x = SkIntToScalar(width / 2); |
84 SkScalar y = SkIntToScalar(height / 2); | 114 SkScalar y = SkIntToScalar(height / 2); |
85 SkScalar radius = SkMinScalar(x, y) * 0.8f; | 115 SkScalar radius = SkMinScalar(x, y) * 0.8f; |
86 canvas->clear(0x00000000); | 116 canvas->clear(0x00000000); |
87 SkColor colors[2]; | 117 SkColor colors[2]; |
88 colors[0] = SK_ColorWHITE; | 118 colors[0] = SK_ColorWHITE; |
89 colors[1] = SK_ColorBLACK; | 119 colors[1] = SK_ColorBLACK; |
90 sk_sp<SkShader> shader( | 120 sk_sp<SkShader> shader( |
91 SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullpt r, 2, | 121 SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullpt r, 2, |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 DEF_TEST(TestZeroBlurSigma, reporter) { | 658 DEF_TEST(TestZeroBlurSigma, reporter) { |
629 run_raster_test(reporter, 100, test_zero_blur_sigma); | 659 run_raster_test(reporter, 100, test_zero_blur_sigma); |
630 } | 660 } |
631 | 661 |
632 #if SK_SUPPORT_GPU | 662 #if SK_SUPPORT_GPU |
633 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestZeroBlurSigma_Gpu, reporter, context) { | 663 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestZeroBlurSigma_Gpu, reporter, context) { |
634 run_gpu_test(reporter, context, 100, test_zero_blur_sigma); | 664 run_gpu_test(reporter, context, 100, test_zero_blur_sigma); |
635 } | 665 } |
636 #endif | 666 #endif |
637 | 667 |
668 | |
669 // Tests that, even when an upstream filter has returned null (due to failure or clipping), a | |
670 // downstream filter that affects transparent black still does so even with a nu llptr input. | |
671 static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy, | |
672 skiatest::Reporter* reporter, | |
673 GrContext* context) { | |
674 sk_sp<FailImageFilter> failFilter(new FailImageFilter()); | |
675 sk_sp<SkSpecialImage> source(create_empty_special_image(context, proxy, 5)); | |
676 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nul lptr); | |
677 sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXf ermode::kSrc_Mode)); | |
robertphillips
2016/03/30 17:12:28
SkASSERT(green->affectsTransparentBlack());
Stephen White
2016/04/04 21:50:55
Done.
| |
678 sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get( ), | |
679 failFilter .get())); | |
680 SkIPoint offset; | |
681 sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &of fset)); | |
682 REPORTER_ASSERT(reporter, nullptr != result.get()); | |
683 if (result.get()) { | |
684 SkBitmap resultBM; | |
685 TestingSpecialImageAccess::GetROPixels(result.get(), &resultBM); | |
686 SkAutoLockPixels lock(resultBM); | |
687 REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN); | |
688 } | |
689 } | |
690 | |
691 DEF_TEST(ImageFilterFailAffectsTransparentBlack, reporter) { | |
692 run_raster_test(reporter, 100, test_fail_affects_transparent_black); | |
693 } | |
694 | |
695 #if SK_SUPPORT_GPU | |
696 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterFailAffectsTransparentBlack_Gpu, repor ter, context) { | |
697 run_gpu_test(reporter, context, 100, test_fail_affects_transparent_black); | |
698 } | |
699 #endif | |
700 | |
638 DEF_TEST(ImageFilterDrawTiled, reporter) { | 701 DEF_TEST(ImageFilterDrawTiled, reporter) { |
639 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly | 702 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly |
640 // match the same filters drawn with a single full-canvas bitmap draw. | 703 // match the same filters drawn with a single full-canvas bitmap draw. |
641 // Tests pass by not asserting. | 704 // Tests pass by not asserting. |
642 | 705 |
643 FilterList filters; | 706 FilterList filters; |
644 | 707 |
645 SkBitmap untiledResult, tiledResult; | 708 SkBitmap untiledResult, tiledResult; |
646 const int width = 64, height = 64; | 709 const int width = 64, height = 64; |
647 untiledResult.allocN32Pixels(width, height); | 710 untiledResult.allocN32Pixels(width, height); |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1593 | 1656 |
1594 test_xfermode_cropped_input(&canvas, reporter); | 1657 test_xfermode_cropped_input(&canvas, reporter); |
1595 } | 1658 } |
1596 | 1659 |
1597 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { | 1660 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
1598 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, | 1661 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, |
1599 SkImageInfo::MakeN32Premul(100, 100 ))); | 1662 SkImageInfo::MakeN32Premul(100, 100 ))); |
1600 test_large_blur_input(reporter, surface->getCanvas()); | 1663 test_large_blur_input(reporter, surface->getCanvas()); |
1601 } | 1664 } |
1602 #endif | 1665 #endif |
OLD | NEW |