Reland of [2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (patchset #1 id:1 of https://codereview.chromium.org/1821103004/ )
Reason for revert:
guard has now landed in chrome
Original issue's description:
> Revert of Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (patchset #3 id:40001 of https://codereview.chromium.org/1825073002/ )
>
> Reason for revert:
> CreateModeFilter not compiling
>
> Original issue's description:
> > Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.org/1822623002/ )"
> >
> > Fixed legacy withColorFilter to call new(er) make method
> >
> > This reverts commit 1eb81db650d31f50be67b12d60c4f9e7dd08432f.
> >
> > BUG=skia:
> > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1825073002
> >
> > TBR=
> >
> > Committed: https://skia.googlesource.com/skia/+/4c9776b046dd5e9e46e2d1ce35154855c8fcb381
>
> TBR=
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/d6889293dd0942f27f9593f679722c956831f2c4
TBR=
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:
Review URL: https://codereview.chromium.org/1827433002
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 3efb44c..f7f8702 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -391,16 +391,17 @@
* If the paint has an imagefilter, but it can be simplified to just a colorfilter, return that
* colorfilter, else return nullptr.
*/
-static SkColorFilter* image_to_color_filter(const SkPaint& paint) {
+static sk_sp<SkColorFilter> image_to_color_filter(const SkPaint& paint) {
SkImageFilter* imgf = paint.getImageFilter();
if (!imgf) {
return nullptr;
}
- SkColorFilter* imgCF;
- if (!imgf->asAColorFilter(&imgCF)) {
+ SkColorFilter* imgCFPtr;
+ if (!imgf->asAColorFilter(&imgCFPtr)) {
return nullptr;
}
+ sk_sp<SkColorFilter> imgCF(imgCFPtr);
SkColorFilter* paintCF = paint.getColorFilter();
if (nullptr == paintCF) {
@@ -410,8 +411,7 @@
// The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-colorfilter(imgCF)
// and we need to combine them into a single colorfilter.
- SkAutoTUnref<SkColorFilter> autoImgCF(imgCF);
- return SkColorFilter::CreateComposeFilter(imgCF, paintCF);
+ return SkColorFilter::MakeComposeFilter(std::move(imgCF), sk_ref_sp(paintCF));
}
/**
@@ -455,10 +455,10 @@
fTempLayerForImageFilter = false;
fDone = false;
- SkColorFilter* simplifiedCF = image_to_color_filter(fOrigPaint);
+ auto simplifiedCF = image_to_color_filter(fOrigPaint);
if (simplifiedCF) {
SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint);
- paint->setColorFilter(simplifiedCF)->unref();
+ paint->setColorFilter(std::move(simplifiedCF));
paint->setImageFilter(nullptr);
fPaint = paint;
}