Index: tests/ImageFilterTest.cpp |
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp |
index ed98ef4ab99a4ee69b7b037dbc8c2ec43190fe8b..d71c7b93064ea9df453880a99d88b8975a6f6e13 100644 |
--- a/tests/ImageFilterTest.cpp |
+++ b/tests/ImageFilterTest.cpp |
@@ -377,6 +377,18 @@ static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context, |
} |
} |
+static sk_sp<SkSurface> create_surface(GrContext* context, int width, int height) { |
+ const SkImageInfo info = SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType); |
+#if SK_SUPPORT_GPU |
+ if (context) { |
+ return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); |
+ } else |
+#endif |
+ { |
+ return SkSurface::MakeRaster(info); |
+ } |
+} |
+ |
static sk_sp<SkSpecialImage> create_empty_special_image(GrContext* context, int widthHeight) { |
sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, widthHeight)); |
@@ -1669,6 +1681,57 @@ DEF_TEST(ImageFilterBlurLargeImage, reporter) { |
test_large_blur_input(reporter, surface->getCanvas()); |
} |
+static void test_make_with_filter(skiatest::Reporter* reporter, GrContext* context) { |
+ sk_sp<SkSurface> surface(create_surface(context, 100, 100)); |
+ surface->getCanvas()->clear(SK_ColorRED); |
+ SkPaint greenPaint; |
robertphillips
2016/05/19 21:14:44
bluePaint? SK_ColorGreen ?
Stephen White
2016/05/19 21:27:43
LOL
What... is your favourite colour?
https://ww
|
+ greenPaint.setColor(SK_ColorBLUE); |
+ SkIRect subset = SkIRect::MakeXYWH(25, 20, 50, 50); |
+ surface->getCanvas()->drawRect(SkRect::Make(subset), greenPaint); |
+ sk_sp<SkImage> sourceImage = surface->makeImageSnapshot(); |
+ |
+ sk_sp<SkImageFilter> filter = make_grayscale(nullptr, nullptr); |
+ SkIRect clipBounds = SkIRect::MakeXYWH(30, 35, 100, 100); |
+ SkIRect outSubset; |
+ SkIPoint offset; |
+ sk_sp<SkImage> result; |
+ |
+ result = sourceImage->makeWithFilter(nullptr, subset, clipBounds, &outSubset, &offset); |
+ REPORTER_ASSERT(reporter, !result); |
+ |
+ result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, nullptr, &offset); |
+ REPORTER_ASSERT(reporter, !result); |
+ |
+ result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outSubset, nullptr); |
+ REPORTER_ASSERT(reporter, !result); |
+ |
+ SkIRect bigSubset = SkIRect::MakeXYWH(-10000, -10000, 20000, 20000); |
+ result = sourceImage->makeWithFilter(filter.get(), bigSubset, clipBounds, &outSubset, &offset); |
+ REPORTER_ASSERT(reporter, !result); |
+ |
+ SkIRect empty = SkIRect::MakeEmpty(); |
robertphillips
2016/05/19 21:14:44
Do you intend the offset out pointer to be null he
Stephen White
2016/05/19 21:27:43
Nope. Thanks.
|
+ result = sourceImage->makeWithFilter(filter.get(), empty, clipBounds, &outSubset, nullptr); |
+ REPORTER_ASSERT(reporter, !result); |
+ |
+ result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outSubset, &offset); |
+ |
+ REPORTER_ASSERT(reporter, result); |
+ REPORTER_ASSERT(reporter, result->bounds().contains(outSubset)); |
robertphillips
2016/05/19 21:14:44
destRect ?
Stephen White
2016/05/19 21:27:43
Done.
|
+ SkIRect dest_rect = SkIRect::MakeXYWH(offset.x(), offset.y(), |
reed1
2016/05/19 20:12:10
nit: can just use outSubset.makeOffset(offset.x(),
Stephen White
2016/05/19 21:27:43
Can't do that; we wan to use only the outSubset si
|
+ outSubset.width(), outSubset.height()); |
+ REPORTER_ASSERT(reporter, clipBounds.contains(dest_rect)); |
robertphillips
2016/05/19 21:14:44
Do you not want to test the case where clipBounds
Stephen White
2016/05/19 21:27:43
Good point. Done.
|
+} |
+ |
+DEF_TEST(ImageFilterMakeWithFilter, reporter) { |
+ test_make_with_filter(reporter, nullptr); |
+} |
+ |
+#if SK_SUPPORT_GPU |
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterMakeWithFilter_Gpu, reporter, ctxInfo) { |
+ test_make_with_filter(reporter, ctxInfo.grContext()); |
+} |
+#endif |
+ |
#if SK_SUPPORT_GPU |
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterHugeBlur_Gpu, reporter, ctxInfo) { |