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

Unified Diff: gm/imagesource.cpp

Issue 1842243002: Update SkImageSource to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 4 years, 9 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 | « gm/imagefilterstransformed.cpp ('k') | gm/imagesource2.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/imagesource.cpp
diff --git a/gm/imagesource.cpp b/gm/imagesource.cpp
index 973dc0c6eaa81b339df1b8ff2ce5caa7ab1963e0..ed7aba1c989f926a226a38ce78c060836895e739 100644
--- a/gm/imagesource.cpp
+++ b/gm/imagesource.cpp
@@ -12,6 +12,17 @@
// This GM exercises the SkImageSource ImageFilter class.
+static void fill_rect_filtered(SkCanvas* canvas,
+ const SkRect& clipRect,
+ sk_sp<SkImageFilter> filter) {
+ SkPaint paint;
+ paint.setImageFilter(std::move(filter));
+ canvas->save();
+ canvas->clipRect(clipRect);
+ canvas->drawPaint(paint);
+ canvas->restore();
+}
+
class ImageSourceGM : public skiagm::GM {
public:
ImageSourceGM() { }
@@ -28,44 +39,39 @@ protected:
fImage = SkImage::MakeFromBitmap(bm);
}
- static void FillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkImageFilter* filter) {
- SkPaint paint;
- paint.setImageFilter(filter);
- canvas->save();
- canvas->clipRect(clipRect);
- canvas->drawPaint(paint);
- canvas->restore();
- }
-
void onDraw(SkCanvas* canvas) override {
canvas->clear(SK_ColorBLACK);
- {
- SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
- SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60);
- SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100);
- SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
- SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(fImage.get()));
- SkAutoTUnref<SkImageFilter> imageSourceSrcRect(
- SkImageSource::Create(fImage.get(), srcRect, srcRect, kHigh_SkFilterQuality));
- SkAutoTUnref<SkImageFilter> imageSourceSrcRectDstRect(
- SkImageSource::Create(fImage.get(), srcRect, dstRect, kHigh_SkFilterQuality));
- SkAutoTUnref<SkImageFilter> imageSourceDstRectOnly(
- SkImageSource::Create(fImage.get(), bounds, dstRect, kHigh_SkFilterQuality));
+ const SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
+ const SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60);
+ const SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100);
+ const SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
+
+ {
// Draw an unscaled bitmap.
- FillRectFiltered(canvas, clipRect, imageSource);
+ sk_sp<SkImageFilter> imageSource(SkImageSource::Make(fImage));
+ fill_rect_filtered(canvas, clipRect, std::move(imageSource));
canvas->translate(SkIntToScalar(100), 0);
-
+ }
+ {
// Draw an unscaled subset of the source bitmap (srcRect -> srcRect).
- FillRectFiltered(canvas, clipRect, imageSourceSrcRect);
+ sk_sp<SkImageFilter> imageSourceSrcRect(
+ SkImageSource::Make(fImage, srcRect, srcRect, kHigh_SkFilterQuality));
+ fill_rect_filtered(canvas, clipRect, std::move(imageSourceSrcRect));
canvas->translate(SkIntToScalar(100), 0);
-
+ }
+ {
// Draw a subset of the bitmap scaled to a destination rect (srcRect -> dstRect).
- FillRectFiltered(canvas, clipRect, imageSourceSrcRectDstRect);
+ sk_sp<SkImageFilter> imageSourceSrcRectDstRect(
+ SkImageSource::Make(fImage, srcRect, dstRect, kHigh_SkFilterQuality));
+ fill_rect_filtered(canvas, clipRect, std::move(imageSourceSrcRectDstRect));
canvas->translate(SkIntToScalar(100), 0);
-
+ }
+ {
// Draw the entire bitmap scaled to a destination rect (bounds -> dstRect).
- FillRectFiltered(canvas, clipRect, imageSourceDstRectOnly);
+ sk_sp<SkImageFilter> imageSourceDstRectOnly(
+ SkImageSource::Make(fImage, bounds, dstRect, kHigh_SkFilterQuality));
+ fill_rect_filtered(canvas, clipRect, std::move(imageSourceDstRectOnly));
canvas->translate(SkIntToScalar(100), 0);
}
}
« no previous file with comments | « gm/imagefilterstransformed.cpp ('k') | gm/imagesource2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698