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

Unified Diff: gm/imagemagnifier.cpp

Issue 1882943002: Switch SkMagnifierImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 4 years, 8 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/effects/SkMagnifierImageFilter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/imagemagnifier.cpp
diff --git a/gm/imagemagnifier.cpp b/gm/imagemagnifier.cpp
index 5697aa2480e06ced45393e79a63f3f52016d6dd3..a012a9e39693095a3ea6e1b6606cfbdb1d0e2a1c 100644
--- a/gm/imagemagnifier.cpp
+++ b/gm/imagemagnifier.cpp
@@ -6,8 +6,10 @@
*/
#include "gm.h"
+#include "SkImageSource.h"
#include "SkMagnifierImageFilter.h"
#include "SkRandom.h"
+#include "SkSurface.h"
#define WIDTH 500
#define HEIGHT 500
@@ -36,3 +38,51 @@ DEF_SIMPLE_GM_BG(imagemagnifier, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
}
canvas->restore();
}
+
+////////////////////////////////////////////////////////////////////////////////
+#define WIDTH_HEIGHT 256
+
+static sk_sp<SkImage> make_img() {
+ const SkImageInfo info = SkImageInfo::MakeN32Premul(WIDTH_HEIGHT, WIDTH_HEIGHT);
+
+ sk_sp<SkSurface> surf(SkSurface::MakeRaster(info));
+
+ SkCanvas* canvas = surf->getCanvas();
+
+ canvas->clear(0x0);
+
+ SkPaint paint;
+ paint.setColor(SK_ColorBLUE);
+
+ for (float pos = 0; pos < WIDTH_HEIGHT; pos += 16) {
+ canvas->drawLine(0, pos, SkIntToScalar(WIDTH_HEIGHT), pos, paint);
+ canvas->drawLine(pos, 0, pos, SkIntToScalar(WIDTH_HEIGHT), paint);
+ }
+
+ return surf->makeImageSnapshot();
+}
+
+DEF_SIMPLE_GM_BG(imagemagnifier_cropped, canvas, WIDTH_HEIGHT, WIDTH_HEIGHT, SK_ColorBLACK) {
+
+ sk_sp<SkImage> image(make_img());
+
+ sk_sp<SkImageFilter> imageSource(SkImageSource::Make(std::move(image)));
+
+ SkRect srcRect = SkRect::MakeWH(SkIntToScalar(WIDTH_HEIGHT-32),
+ SkIntToScalar(WIDTH_HEIGHT-32));
+ srcRect.inset(64.0f, 64.0f);
+
+ static const SkScalar kInset = 64.0f;
+
+ // Crop out a 16 pixel ring around the result
+ const SkRect rect = SkRect::MakeXYWH(16, 16, WIDTH_HEIGHT-32, WIDTH_HEIGHT-32);
+ SkImageFilter::CropRect cropRect(rect);
+
+ SkPaint filterPaint;
+ filterPaint.setImageFilter(SkMagnifierImageFilter::Make(srcRect, kInset,
+ std::move(imageSource),
+ &cropRect));
+
+ canvas->saveLayer(nullptr, &filterPaint);
+ canvas->restore();
+}
« no previous file with comments | « no previous file | include/effects/SkMagnifierImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698