Index: tests/ImageFilterTest.cpp |
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp |
index ed98ef4ab99a4ee69b7b037dbc8c2ec43190fe8b..475b76abfa5e6ff13e7c32a524abb189f20e867e 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; |
+ 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::MakeWH(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, nullptr); |
+ REPORTER_ASSERT(reporter, !result); |
+ |
+ SkIRect emptySubset = SkIRect::MakeEmpty(); |
+ result = sourceImage->makeWithFilter(filter.get(), emptySubset, clipBounds, &outSubset, nullptr); |
+ REPORTER_ASSERT(reporter, !result); |
+ |
+ result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outSubset, &offset); |
+ |
+ REPORTER_ASSERT(reporter, result); |
reed1
2016/05/19 16:33:34
What are the pre and post conditions for the api (
Stephen White
2016/05/19 17:20:06
Done. (Test was there, but buggy.)
|
+ REPORTER_ASSERT(reporter, outSubset.width() == subset.width()); |
+ REPORTER_ASSERT(reporter, outSubset.height() == subset.height()); |
+ REPORTER_ASSERT(reporter, outSubset.width() <= result->width()); |
+ REPORTER_ASSERT(reporter, outSubset.height() <= result->height()); |
+} |
+ |
+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) { |