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

Unified Diff: tests/ImageFilterTest.cpp

Issue 1964043002: Image filters: implement SkImage::makeWithFilter(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More fixes per Rob 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
« include/core/SkImage.h ('K') | « 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..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) {
« include/core/SkImage.h ('K') | « src/image/SkImage.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698