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

Unified Diff: gm/imagefilters.cpp

Issue 1523053003: add backdrop option to SaveLayerRec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 11 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 | « no previous file | include/core/SkCanvas.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+ }
+}
« no previous file with comments | « no previous file | include/core/SkCanvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698