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

Unified Diff: tests/ImageFilterTest.cpp

Issue 1964043002: Image filters: implement SkImage::makeWithFilter(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixes per Rob's comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkImage.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageFilterTest.cpp
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index ed98ef4ab99a4ee69b7b037dbc8c2ec43190fe8b..12b1caa16dbecb7cfdb9959301fe9f5eb7461dd3 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,64 @@ 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 bluePaint;
+ bluePaint.setColor(SK_ColorBLUE);
+ SkIRect subset = SkIRect::MakeXYWH(25, 20, 50, 50);
+ surface->getCanvas()->drawRect(SkRect::Make(subset), bluePaint);
+ 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();
+ result = sourceImage->makeWithFilter(filter.get(), empty, clipBounds, &outSubset, &offset);
+ REPORTER_ASSERT(reporter, !result);
+
+ result = sourceImage->makeWithFilter(filter.get(), subset, empty, &outSubset, &offset);
+ REPORTER_ASSERT(reporter, !result);
+
+ SkIRect leftField = SkIRect::MakeXYWH(-1000, 0, 100, 100);
+ result = sourceImage->makeWithFilter(filter.get(), subset, leftField, &outSubset, &offset);
+ REPORTER_ASSERT(reporter, !result);
+
+ result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outSubset, &offset);
+
+ REPORTER_ASSERT(reporter, result);
+ REPORTER_ASSERT(reporter, result->bounds().contains(outSubset));
+ SkIRect destRect = SkIRect::MakeXYWH(offset.x(), offset.y(),
+ outSubset.width(), outSubset.height());
+ REPORTER_ASSERT(reporter, clipBounds.contains(destRect));
+}
+
+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) {
« no previous file with comments | « src/image/SkImage.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698