Index: gm/imagefilters.cpp |
diff --git a/gm/imagefilters.cpp b/gm/imagefilters.cpp |
index 5f1ae849490dd8971a99ab656d7f4b8bca48c255..951a934d8210614daf9ad41262ca8e7cf0dda8bb 100644 |
--- a/gm/imagefilters.cpp |
+++ b/gm/imagefilters.cpp |
@@ -104,3 +104,77 @@ DEF_SIMPLE_GM(fast_slow_blurimagefilter, canvas, 620, 260) { |
canvas->translate(r.width() + 20, 0); |
} |
} |
+ |
+/////////////////////////////////////////////////////////////////////////////////////////////////// |
+#include "Resources.h" |
+#include "SkBlurImageFilter.h" |
+#include "SkMatrixConvolutionImageFilter.h" |
+#include "SkMorphologyImageFilter.h" |
+#include "SkColorMatrixFilter.h" |
+#include "SkColorFilterImageFilter.h" |
+#include "SkRRect.h" |
+ |
+static void draw_set(SkCanvas* canvas, SkImageFilter* filters[], int count) { |
+ const SkRect r = SkRect::MakeXYWH(30, 30, 200, 200); |
+ const SkScalar offset = 250; |
+ SkScalar dx = 0, dy = 0; |
+ |
+ for (int i = 0; i < count; ++i) { |
+ canvas->save(); |
+ SkRRect rr = SkRRect::MakeRectXY(r.makeOffset(dx, dy), 20, 20); |
+ canvas->clipRRect(rr, SkRegion::kIntersect_Op, true); |
+ canvas->saveLayer({ &rr.getBounds(), nullptr, filters[i], 0 }); |
+ canvas->drawColor(0x40FFFFFF); |
+ canvas->restore(); |
+ canvas->restore(); |
+ |
+ if (0 == dx) { |
+ dx = offset; |
+ } else { |
+ dx = 0; |
+ dy = offset; |
+ } |
+ } |
+} |
+ |
+DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) { |
+ SkColorMatrix cm; |
+ cm.setSaturation(10); |
+ SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(cm)); |
+ const SkScalar kernel[] = { 4, 0, 4, 0, -15, 0, 4, 0, 4 }; |
+ SkImageFilter* filters[] = { |
+ SkBlurImageFilter::Create(10, 10), |
+ SkDilateImageFilter::Create(8, 8), |
+ SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 }, |
+ SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, |
+ true), |
+ SkColorFilterImageFilter::Create(cf), |
+ }; |
+ |
+ const struct { |
+ SkScalar fSx, fSy, fTx, fTy; |
+ } xforms[] = { |
+ { 1, 1, 0, 0 }, |
+ { 0.5f, 0.5f, 530, 0 }, |
+ { 0.25f, 0.25f, 530, 275 }, |
+ { 0.125f, 0.125f, 530, 420 }, |
+ }; |
+ |
+ SkPaint paint; |
+ paint.setFilterQuality(kMedium_SkFilterQuality); |
+ SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_512.png")); |
+ |
+ canvas->translate(20, 20); |
+ for (const auto& xform : xforms) { |
+ canvas->save(); |
+ canvas->translate(xform.fTx, xform.fTy); |
+ canvas->scale(xform.fSx, xform.fSy); |
+ canvas->drawImage(image, 0, 0, &paint); |
+ draw_set(canvas, filters, SK_ARRAY_COUNT(filters)); |
+ canvas->restore(); |
+ } |
+ |
+ for (auto& filter : filters) { |
+ filter->unref(); |
+ } |
+} |