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

Side by Side 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, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 typedef GM INHERITED; 437 typedef GM INHERITED;
438 }; 438 };
439 439
440 440
441 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); ) 441 DEF_GM( return new BleedGM(kUseBitmap_BleedTest); )
442 DEF_GM( return new BleedGM(kUseImage_BleedTest); ) 442 DEF_GM( return new BleedGM(kUseImage_BleedTest); )
443 DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); ) 443 DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); )
444 DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); ) 444 DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); )
445 DEF_GM( return new BleedGM(kUseAlphaBitmapShader_BleedTest); ) 445 DEF_GM( return new BleedGM(kUseAlphaBitmapShader_BleedTest); )
446 DEF_GM( return new BleedGM(kUseAlphaImageShader_BleedTest); ) 446 DEF_GM( return new BleedGM(kUseAlphaImageShader_BleedTest); )
447
448 //////////////////////////////////////////////////////////////////////////////// ///////////////////
449 #include "SkSurface.h"
450
451 sk_sp<SkSurface> make_surface(SkCanvas* canvas, const SkImageInfo& info) {
452 auto surface = canvas->makeSurface(info);
453 if (!surface) {
454 surface = SkSurface::MakeRaster(info);
455 }
456 return surface;
457 }
458
459 // Construct an image and return the inner "src" rect. Build the image such that the interior is
460 // blue, with a margin of blue (2px) but then an outer margin of red.
461 //
462 // Show that kFast_SrcRectConstraint sees even the red margin (due to mipmapping ) when the image
463 // is scaled down far enough.
464 //
465 static sk_sp<SkImage> make_image(SkCanvas* canvas, SkRect* srcR) {
466 const int N = 9 + 2 + 7 + 2 + 9;
467 SkImageInfo info = SkImageInfo::MakeN32Premul(N, N);
468 auto surface = make_surface(canvas, info);
469 SkCanvas* c = surface->getCanvas();
470 SkRect r = SkRect::MakeIWH(info.width(), info.height());
471 SkPaint paint;
472
473 paint.setColor(SK_ColorRED);
474 c->drawRect(r, paint);
475 r.inset(4, 4);
476 paint.setColor(SK_ColorBLUE);
477 c->drawRect(r, paint);
478
479 *srcR = r.makeInset(2, 2);
480 return surface->makeImageSnapshot();
481 }
482
483 DEF_SIMPLE_GM(bleed_downscale, canvas, 360, 240) {
484 SkRect src;
485 sk_sp<SkImage> img = make_image(canvas, &src);
486 SkPaint paint;
487
488 canvas->translate(10, 10);
489
490 const SkCanvas::SrcRectConstraint constraints[] = {
491 SkCanvas::kStrict_SrcRectConstraint, SkCanvas::kFast_SrcRectConstraint
492 };
493 const SkFilterQuality qualities[] = {
494 kNone_SkFilterQuality, kLow_SkFilterQuality, kMedium_SkFilterQuality
495 };
496 for (auto constraint : constraints) {
497 canvas->save();
498 for (auto quality : qualities) {
499 paint.setFilterQuality(quality);
500 auto surf = make_surface(canvas, SkImageInfo::MakeN32Premul(1, 1));
501 surf->getCanvas()->drawImageRect(img, src, SkRect::MakeWH(1, 1), &pa int, constraint);
502 // now blow up the 1 pixel result
503 canvas->drawImageRect(surf->makeImageSnapshot(), SkRect::MakeWH(100, 100), nullptr);
504 canvas->translate(120, 0);
505 }
506 canvas->restore();
507 canvas->translate(0, 120);
508 }
509 }
510
511
OLDNEW
« 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