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/gm/colorfilterimagefilter.cpp b/gm/colorfilterimagefilter.cpp
index f72108f..497757e 100644
--- a/gm/colorfilterimagefilter.cpp
+++ b/gm/colorfilterimagefilter.cpp
@@ -18,34 +18,34 @@
#define FILTER_HEIGHT SkIntToScalar(30)
#define MARGIN SkIntToScalar(10)
-static SkColorFilter* cf_make_brightness(float brightness) {
+static sk_sp<SkColorFilter> cf_make_brightness(float brightness) {
SkScalar amount255 = SkScalarMul(brightness, SkIntToScalar(255));
SkScalar matrix[20] = {
1, 0, 0, 0, amount255,
0, 1, 0, 0, amount255,
0, 0, 1, 0, amount255,
0, 0, 0, 1, 0 };
- return SkColorMatrixFilter::Create(matrix);
+ return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
}
-static SkColorFilter* cf_make_grayscale() {
+static sk_sp<SkColorFilter> cf_make_grayscale() {
SkScalar matrix[20];
memset(matrix, 0, 20 * sizeof(SkScalar));
matrix[0] = matrix[5] = matrix[10] = 0.2126f;
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
matrix[18] = 1.0f;
- return SkColorMatrixFilter::Create(matrix);
+ return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
}
-static SkColorFilter* cf_make_colorize(SkColor color) {
- return SkColorFilter::CreateModeFilter(color, SkXfermode::kSrc_Mode);
+static sk_sp<SkColorFilter> cf_make_colorize(SkColor color) {
+ return SkColorFilter::MakeModeFilter(color, SkXfermode::kSrc_Mode);
}
-static void sk_gm_get_colorfilters(SkTDArray<SkColorFilter*>* array) {
- *array->append() = cf_make_brightness(0.5f);
- *array->append() = cf_make_grayscale();
- *array->append() = cf_make_colorize(SK_ColorBLUE);
+static void sk_gm_get_colorfilters(SkTArray<sk_sp<SkColorFilter>>* array) {
+ array->push_back(cf_make_brightness(0.5f));
+ array->push_back(cf_make_grayscale());
+ array->push_back(cf_make_colorize(SK_ColorBLUE));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -92,18 +92,15 @@
}
static SkImageFilter* make_brightness(float amount, SkImageFilter* input = nullptr) {
- SkAutoTUnref<SkColorFilter> filter(cf_make_brightness(amount));
- return SkColorFilterImageFilter::Create(filter, input);
+ return SkColorFilterImageFilter::Create(cf_make_brightness(amount).get(), input);
}
static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
- SkAutoTUnref<SkColorFilter> filter(cf_make_grayscale());
- return SkColorFilterImageFilter::Create(filter, input);
+ return SkColorFilterImageFilter::Create(cf_make_grayscale().get(), input);
}
static SkImageFilter* make_mode_blue(SkImageFilter* input = nullptr) {
- SkAutoTUnref<SkColorFilter> filter(cf_make_colorize(SK_ColorBLUE));
- return SkColorFilterImageFilter::Create(filter, input);
+ return SkColorFilterImageFilter::Create(cf_make_colorize(SK_ColorBLUE).get(), input);
}
static void drawClippedRect(SkCanvas* canvas,
@@ -179,8 +176,8 @@
SkAutoCanvasRestore autoCanvasRestore(canvas, false);
SkColorMatrix cm;
cm.setSaturation(0.0f);
- SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(cm));
- SkAutoTUnref<SkImageFilter> imf(SkColorFilterImageFilter::Create(cf));
+ auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
+ SkAutoTUnref<SkImageFilter> imf(SkColorFilterImageFilter::Create(cf.get()));
SkPaint p;
p.setImageFilter(imf);
canvas->saveLayer(NULL, &p);
@@ -195,7 +192,7 @@
};
DEF_SIMPLE_GM(colorfiltershader, canvas, 800, 800) {
- SkTRefArray<SkColorFilter*> filters;
+ SkTArray<sk_sp<SkColorFilter>> filters;
sk_gm_get_colorfilters(&filters);
SkTRefArray<SkShader*> shaders;
@@ -210,7 +207,7 @@
canvas->save();
for (int x = -1; x < filters.count(); ++x) {
- SkColorFilter* filter = x >= 0 ? filters[x] : nullptr;
+ sk_sp<SkColorFilter> filter = x >= 0 ? filters[x] : nullptr;
paint.setShader(shader->makeWithColorFilter(filter));
canvas->drawRect(r, paint);