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

Unified Diff: gm/bleed.cpp

Issue 2182503002: add gm to test bleed with downscale (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/bleed.cpp
diff --git a/gm/bleed.cpp b/gm/bleed.cpp
index 914da993bca171bcb9ba9d7af907f25401d565e3..baef8850d6d396109433f5bc018f1b6e43c11749 100644
--- a/gm/bleed.cpp
+++ b/gm/bleed.cpp
@@ -444,3 +444,68 @@ DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); )
DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); )
DEF_GM( return new BleedGM(kUseAlphaBitmapShader_BleedTest); )
DEF_GM( return new BleedGM(kUseAlphaImageShader_BleedTest); )
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+#include "SkSurface.h"
+
+sk_sp<SkSurface> make_surface(SkCanvas* canvas, const SkImageInfo& info) {
+ auto surface = canvas->makeSurface(info);
+ if (!surface) {
+ surface = SkSurface::MakeRaster(info);
+ }
+ return surface;
+}
+
+// Construct an image and return the inner "src" rect. Build the image such that the interior is
+// blue, with a margin of blue (2px) but then an outer margin of red.
+//
+// Show that kFast_SrcRectConstraint sees even the red margin (due to mipmapping) when the image
+// is scaled down far enough.
+//
+static sk_sp<SkImage> make_image(SkCanvas* canvas, SkRect* srcR) {
+ const int N = 9 + 2 + 7 + 2 + 9;
+ SkImageInfo info = SkImageInfo::MakeN32Premul(N, N);
+ auto surface = make_surface(canvas, info);
+ SkCanvas* c = surface->getCanvas();
+ SkRect r = SkRect::MakeIWH(info.width(), info.height());
+ SkPaint paint;
+
+ paint.setColor(SK_ColorRED);
+ c->drawRect(r, paint);
+ r.inset(4, 4);
+ paint.setColor(SK_ColorBLUE);
+ c->drawRect(r, paint);
+
+ *srcR = r.makeInset(2, 2);
+ return surface->makeImageSnapshot();
+}
+
+DEF_SIMPLE_GM(bleed_downscale, canvas, 360, 240) {
+ SkRect src;
+ sk_sp<SkImage> img = make_image(canvas, &src);
+ SkPaint paint;
+
+ canvas->translate(10, 10);
+
+ const SkCanvas::SrcRectConstraint constraints[] = {
+ SkCanvas::kStrict_SrcRectConstraint, SkCanvas::kFast_SrcRectConstraint
+ };
+ const SkFilterQuality qualities[] = {
+ kNone_SkFilterQuality, kLow_SkFilterQuality, kMedium_SkFilterQuality
+ };
+ for (auto constraint : constraints) {
+ canvas->save();
+ for (auto quality : qualities) {
+ paint.setFilterQuality(quality);
+ auto surf = make_surface(canvas, SkImageInfo::MakeN32Premul(1, 1));
+ surf->getCanvas()->drawImageRect(img, src, SkRect::MakeWH(1, 1), &paint, constraint);
+ // now blow up the 1 pixel result
+ canvas->drawImageRect(surf->makeImageSnapshot(), SkRect::MakeWH(100, 100), nullptr);
+ canvas->translate(120, 0);
+ }
+ canvas->restore();
+ canvas->translate(0, 120);
+ }
+}
+
+
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698