Chromium Code Reviews| Index: tests/ImageFilterTest.cpp |
| diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp |
| index 89f5061f537939b27ac22164baabdac1bb04a686..f9a513e6e1054fad945eb3df29592f106f2510b2 100644 |
| --- a/tests/ImageFilterTest.cpp |
| +++ b/tests/ImageFilterTest.cpp |
| @@ -79,6 +79,36 @@ private: |
| typedef SkImageFilter INHERITED; |
| }; |
| +class FailImageFilter : public SkImageFilter { |
| +public: |
| + FailImageFilter() : SkImageFilter(0, nullptr) { |
| + } |
| + |
| + sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, |
| + const Context& ctx, |
| + SkIPoint* offset) const override { |
| + return nullptr; |
| + } |
| + |
| + SK_TO_STRING_OVERRIDE() |
| + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) |
| + |
| +private: |
| + typedef SkImageFilter INHERITED; |
| +}; |
| + |
| +SkFlattenable* FailImageFilter::CreateProc(SkReadBuffer& buffer) { |
| + SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); |
| + return new FailImageFilter(); |
| +} |
| + |
| +#ifndef SK_IGNORE_TO_STRING |
| +void FailImageFilter::toString(SkString* str) const { |
| + str->appendf("FailImageFilter: ("); |
| + str->append(")"); |
| +} |
| +#endif |
| + |
| void draw_gradient_circle(SkCanvas* canvas, int width, int height) { |
| SkScalar x = SkIntToScalar(width / 2); |
| SkScalar y = SkIntToScalar(height / 2); |
| @@ -635,6 +665,39 @@ DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestZeroBlurSigma_Gpu, reporter, context) { |
| } |
| #endif |
| + |
| +// Tests that, even when an upstream filter has returned null (due to failure or clipping), a |
| +// downstream filter that affects transparent black still does so even with a nullptr input. |
| +static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy, |
| + skiatest::Reporter* reporter, |
| + GrContext* context) { |
| + sk_sp<FailImageFilter> failFilter(new FailImageFilter()); |
| + sk_sp<SkSpecialImage> source(create_empty_special_image(context, proxy, 5)); |
| + SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nullptr); |
| + sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode)); |
|
robertphillips
2016/03/30 17:12:28
SkASSERT(green->affectsTransparentBlack());
Stephen White
2016/04/04 21:50:55
Done.
|
| + sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get(), |
| + failFilter.get())); |
| + SkIPoint offset; |
| + sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &offset)); |
| + REPORTER_ASSERT(reporter, nullptr != result.get()); |
| + if (result.get()) { |
| + SkBitmap resultBM; |
| + TestingSpecialImageAccess::GetROPixels(result.get(), &resultBM); |
| + SkAutoLockPixels lock(resultBM); |
| + REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN); |
| + } |
| +} |
| + |
| +DEF_TEST(ImageFilterFailAffectsTransparentBlack, reporter) { |
| + run_raster_test(reporter, 100, test_fail_affects_transparent_black); |
| +} |
| + |
| +#if SK_SUPPORT_GPU |
| +DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterFailAffectsTransparentBlack_Gpu, reporter, context) { |
| + run_gpu_test(reporter, context, 100, test_fail_affects_transparent_black); |
| +} |
| +#endif |
| + |
| DEF_TEST(ImageFilterDrawTiled, reporter) { |
| // Check that all filters when drawn tiled (with subsequent clip rects) exactly |
| // match the same filters drawn with a single full-canvas bitmap draw. |