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

Unified Diff: gm/imagefilterscropped.cpp

Issue 1860573002: Update SkMorphology ImageFilters to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT 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 | « gm/imagefilterscropexpand.cpp ('k') | gm/imagefiltersgraph.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/imagefilterscropped.cpp
diff --git a/gm/imagefilterscropped.cpp b/gm/imagefilterscropped.cpp
index 1e880fe68a96e67c93ce1d54448a96676833b62c..66e4d870e9eea9263d7d599dde1c4ec1a01af0f2 100644
--- a/gm/imagefilterscropped.cpp
+++ b/gm/imagefilterscropped.cpp
@@ -20,9 +20,9 @@
///////////////////////////////////////////////////////////////////////////////
-static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_paint(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
paint.setColor(SK_ColorBLACK);
canvas->save();
canvas->clipRect(r);
@@ -30,17 +30,17 @@ static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
canvas->restore();
}
-static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_path(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
paint.setColor(SK_ColorMAGENTA);
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
paint.setAntiAlias(true);
canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint);
}
-static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_text(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
paint.setColor(SK_ColorGREEN);
paint.setAntiAlias(true);
sk_tool_utils::set_portable_typeface(&paint);
@@ -49,7 +49,7 @@ static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint);
}
-static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
SkIRect bounds;
@@ -61,7 +61,7 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkCanvas c(bm);
draw_path(&c, r, nullptr);
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
canvas->drawBitmap(bm, 0, 0, &paint);
}
@@ -111,13 +111,16 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) override {
- void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
+ void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = {
draw_bitmap, draw_path, draw_paint, draw_text
};
- auto cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
- SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge);
- SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge);
+ sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
+ SkXfermode::kSrcIn_Mode));
+ SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
+ SkImageFilter::CropRect::kHasAll_CropEdge);
+ SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)),
+ SkImageFilter::CropRect::kHasAll_CropEdge);
sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(SkIntToScalar(-10),
SkIntToScalar(-10),
@@ -125,25 +128,27 @@ protected:
sk_sp<SkImageFilter> cfOffset(SkColorFilterImageFilter::Create(cf.get(), offset.get()));
- SkAutoTUnref<SkImageFilter> erodeX(SkErodeImageFilter::Create(8, 0, nullptr, &cropRect));
- SkAutoTUnref<SkImageFilter> erodeY(SkErodeImageFilter::Create(0, 8, nullptr, &cropRect));
+ sk_sp<SkImageFilter> erodeX(SkErodeImageFilter::Make(8, 0, nullptr, &cropRect));
+ sk_sp<SkImageFilter> erodeY(SkErodeImageFilter::Make(0, 8, nullptr, &cropRect));
- SkImageFilter* filters[] = {
+ sk_sp<SkImageFilter> filters[] = {
nullptr,
- SkColorFilterImageFilter::Create(cf.get(), nullptr, &cropRect),
- SkBlurImageFilter::Make(0.0f, 0.0f, nullptr, &cropRect).release(),
- SkBlurImageFilter::Make(1.0f, 1.0f, nullptr, &cropRect).release(),
- SkBlurImageFilter::Make(8.0f, 0.0f, nullptr, &cropRect).release(),
- SkBlurImageFilter::Make(0.0f, 8.0f, nullptr, &cropRect).release(),
- SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &cropRect).release(),
- SkErodeImageFilter::Create(1, 1, nullptr, &cropRect),
- SkErodeImageFilter::Create(8, 0, erodeY, &cropRect),
- SkErodeImageFilter::Create(0, 8, erodeX, &cropRect),
- SkErodeImageFilter::Create(8, 8, nullptr, &cropRect),
- SkMergeImageFilter::Make(nullptr, std::move(cfOffset),
- SkXfermode::kSrcOver_Mode, &cropRect).release(),
- SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect).release(),
- SkColorFilterImageFilter::Create(cf.get(), nullptr, &bogusRect),
+ sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &cropRect)),
+ SkBlurImageFilter::Make(0.0f, 0.0f, nullptr, &cropRect),
+ SkBlurImageFilter::Make(1.0f, 1.0f, nullptr, &cropRect),
+ SkBlurImageFilter::Make(8.0f, 0.0f, nullptr, &cropRect),
+ SkBlurImageFilter::Make(0.0f, 8.0f, nullptr, &cropRect),
+ SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &cropRect),
+ SkErodeImageFilter::Make(1, 1, nullptr, &cropRect),
+ SkErodeImageFilter::Make(8, 0, std::move(erodeY), &cropRect),
+ SkErodeImageFilter::Make(0, 8, std::move(erodeX), &cropRect),
+ SkErodeImageFilter::Make(8, 8, nullptr, &cropRect),
+ SkMergeImageFilter::Make(nullptr,
+ std::move(cfOffset),
+ SkXfermode::kSrcOver_Mode,
+ &cropRect),
+ SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect),
+ sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &bogusRect)),
};
SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
@@ -163,10 +168,6 @@ protected:
canvas->restore();
canvas->translate(DX, 0);
}
-
- for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
- SkSafeUnref(filters[j]);
- }
}
private:
« no previous file with comments | « gm/imagefilterscropexpand.cpp ('k') | gm/imagefiltersgraph.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698