diff --git a/bench/ColorFilterBench.cpp b/bench/ColorFilterBench.cpp index c4ba1e5dcb..30bd3161a0 100644 --- a/bench/ColorFilterBench.cpp +++ b/bench/ColorFilterBench.cpp @@ -9,14 +9,39 @@ #include "SkCanvas.h" #include "SkColorFilterImageFilter.h" #include "SkColorMatrixFilter.h" -#include "SkLumaColorFilter.h" -#include "SkTableColorFilter.h" #define FILTER_WIDTH_SMALL SkIntToScalar(32) #define FILTER_HEIGHT_SMALL SkIntToScalar(32) #define FILTER_WIDTH_LARGE SkIntToScalar(256) #define FILTER_HEIGHT_LARGE SkIntToScalar(256) +static sk_sp make_brightness(float amount, sk_sp input) { + SkScalar amount255 = SkScalarMul(amount, 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 }; + sk_sp filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); + return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); +} + +static sk_sp make_grayscale(sk_sp input) { + 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; + sk_sp filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); + return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); +} + +static sk_sp make_mode_blue(sk_sp input) { + sk_sp filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, + SkXfermode::kSrcIn_Mode)); + return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); +} + class ColorFilterBaseBench : public Benchmark { public: @@ -24,34 +49,8 @@ public: protected: SkRect getFilterRect() const { - return isSmall() ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) : - SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE); - } - - static SkImageFilter* make_brightness(float amount, SkImageFilter* input = nullptr) { - SkScalar amount255 = SkScalarMul(amount, 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 }; - auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); - return SkColorFilterImageFilter::Create(filter.get(), input); - } - - static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) { - 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; - auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); - return SkColorFilterImageFilter::Create(filter.get(), input); - } - - static SkImageFilter* make_mode_blue(SkImageFilter* input = nullptr) { - auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); - return SkColorFilterImageFilter::Create(filter.get(), input); + return this->isSmall() ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) : + SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE); } inline bool isSmall() const { return fIsSmall; } @@ -65,24 +64,22 @@ private: class ColorFilterDimBrightBench : public ColorFilterBaseBench { public: - ColorFilterDimBrightBench(bool small) : INHERITED(small) { - } + ColorFilterDimBrightBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { - return isSmall() ? "colorfilter_dim_bright_small" : "colorfilter_dim_bright_large"; + return this->isSmall() ? "colorfilter_dim_bright_small" : "colorfilter_dim_bright_large"; } void onDraw(int loops, SkCanvas* canvas) override { - SkRect r = getFilterRect(); + SkRect r = this->getFilterRect(); SkPaint paint; paint.setColor(SK_ColorRED); for (int i = 0; i < loops; i++) { for (float brightness = -1.0f; brightness <= 1.0f; brightness += 0.4f) { - SkAutoTUnref dim(make_brightness(-brightness)); - SkAutoTUnref bright(make_brightness(brightness, dim)); - paint.setImageFilter(bright); + sk_sp dim(make_brightness(-brightness, nullptr)); + paint.setImageFilter(make_brightness(brightness, std::move(dim))); canvas->drawRect(r, paint); } } @@ -95,22 +92,20 @@ private: class ColorFilterBrightGrayBench : public ColorFilterBaseBench { public: - ColorFilterBrightGrayBench(bool small) : INHERITED(small) { - } + ColorFilterBrightGrayBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { - return isSmall() ? "colorfilter_bright_gray_small" : "colorfilter_bright_gray_large"; + return this->isSmall() ? "colorfilter_bright_gray_small" : "colorfilter_bright_gray_large"; } void onDraw(int loops, SkCanvas* canvas) override { - SkRect r = getFilterRect(); + SkRect r = this->getFilterRect(); SkPaint paint; paint.setColor(SK_ColorRED); for (int i = 0; i < loops; i++) { - SkAutoTUnref brightness(make_brightness(0.9f)); - SkAutoTUnref grayscale(make_grayscale(brightness)); - paint.setImageFilter(grayscale); + sk_sp brightness(make_brightness(0.9f, nullptr)); + paint.setImageFilter(make_grayscale(std::move(brightness))); canvas->drawRect(r, paint); } } @@ -122,22 +117,20 @@ private: class ColorFilterGrayBrightBench : public ColorFilterBaseBench { public: - ColorFilterGrayBrightBench(bool small) : INHERITED(small) { - } + ColorFilterGrayBrightBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { - return isSmall() ? "colorfilter_gray_bright_small" : "colorfilter_gray_bright_large"; + return this->isSmall() ? "colorfilter_gray_bright_small" : "colorfilter_gray_bright_large"; } void onDraw(int loops, SkCanvas* canvas) override { - SkRect r = getFilterRect(); + SkRect r = this->getFilterRect(); SkPaint paint; paint.setColor(SK_ColorRED); for (int i = 0; i < loops; i++) { - SkAutoTUnref grayscale(make_grayscale()); - SkAutoTUnref brightness(make_brightness(0.9f, grayscale)); - paint.setImageFilter(brightness); + sk_sp grayscale(make_grayscale(nullptr)); + paint.setImageFilter(make_brightness(0.9f, std::move(grayscale))); canvas->drawRect(r, paint); } } @@ -149,22 +142,20 @@ private: class ColorFilterBlueBrightBench : public ColorFilterBaseBench { public: - ColorFilterBlueBrightBench(bool small) : INHERITED(small) { - } + ColorFilterBlueBrightBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { - return isSmall() ? "colorfilter_blue_bright_small" : "colorfilter_blue_bright_large"; + return this->isSmall() ? "colorfilter_blue_bright_small" : "colorfilter_blue_bright_large"; } void onDraw(int loops, SkCanvas* canvas) override { - SkRect r = getFilterRect(); + SkRect r = this->getFilterRect(); SkPaint paint; paint.setColor(SK_ColorRED); for (int i = 0; i < loops; i++) { - SkAutoTUnref blue(make_mode_blue()); - SkAutoTUnref brightness(make_brightness(1.0f, blue)); - paint.setImageFilter(brightness); + sk_sp blue(make_mode_blue(nullptr)); + paint.setImageFilter(make_brightness(1.0f, std::move(blue))); canvas->drawRect(r, paint); } } @@ -176,22 +167,20 @@ private: class ColorFilterBrightBlueBench : public ColorFilterBaseBench { public: - ColorFilterBrightBlueBench(bool small) : INHERITED(small) { - } + ColorFilterBrightBlueBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { - return isSmall() ? "colorfilter_bright_blue_small" : "colorfilter_bright_blue_large"; + return this->isSmall() ? "colorfilter_bright_blue_small" : "colorfilter_bright_blue_large"; } void onDraw(int loops, SkCanvas* canvas) override { - SkRect r = getFilterRect(); + SkRect r = this->getFilterRect(); SkPaint paint; paint.setColor(SK_ColorRED); for (int i = 0; i < loops; i++) { - SkAutoTUnref brightness(make_brightness(1.0f)); - SkAutoTUnref blue(make_mode_blue(brightness)); - paint.setImageFilter(blue); + sk_sp brightness(make_brightness(1.0f, nullptr)); + paint.setImageFilter(make_mode_blue(std::move(brightness))); canvas->drawRect(r, paint); } } @@ -203,21 +192,19 @@ private: class ColorFilterBrightBench : public ColorFilterBaseBench { public: - ColorFilterBrightBench(bool small) : INHERITED(small) { - } + ColorFilterBrightBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { - return isSmall() ? "colorfilter_bright_small" : "colorfilter_bright_large"; + return this->isSmall() ? "colorfilter_bright_small" : "colorfilter_bright_large"; } void onDraw(int loops, SkCanvas* canvas) override { - SkRect r = getFilterRect(); + SkRect r = this->getFilterRect(); SkPaint paint; paint.setColor(SK_ColorRED); for (int i = 0; i < loops; i++) { - SkAutoTUnref brightness(make_brightness(1.0f)); - paint.setImageFilter(brightness); + paint.setImageFilter(make_brightness(1.0f, nullptr)); canvas->drawRect(r, paint); } } @@ -229,21 +216,19 @@ private: class ColorFilterBlueBench : public ColorFilterBaseBench { public: - ColorFilterBlueBench(bool small) : INHERITED(small) { - } + ColorFilterBlueBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { - return isSmall() ? "colorfilter_blue_small" : "colorfilter_blue_large"; + return this->isSmall() ? "colorfilter_blue_small" : "colorfilter_blue_large"; } void onDraw(int loops, SkCanvas* canvas) override { - SkRect r = getFilterRect(); + SkRect r = this->getFilterRect(); SkPaint paint; paint.setColor(SK_ColorRED); for (int i = 0; i < loops; i++) { - SkAutoTUnref blue(make_mode_blue()); - paint.setImageFilter(blue); + paint.setImageFilter(make_mode_blue(nullptr)); canvas->drawRect(r, paint); } } @@ -255,20 +240,19 @@ private: class ColorFilterGrayBench : public ColorFilterBaseBench { public: - ColorFilterGrayBench(bool small) : INHERITED(small) {} + ColorFilterGrayBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { - return isSmall() ? "colorfilter_gray_small" : "colorfilter_gray_large"; + return this->isSmall() ? "colorfilter_gray_small" : "colorfilter_gray_large"; } void onDraw(int loops, SkCanvas* canvas) override { - SkRect r = getFilterRect(); + SkRect r = this->getFilterRect(); SkPaint paint; paint.setColor(SK_ColorRED); for (int i = 0; i < loops; i++) { - SkAutoTUnref grayscale(make_grayscale()); - paint.setImageFilter(grayscale); + paint.setImageFilter(make_grayscale(nullptr)); canvas->drawRect(r, paint); } } diff --git a/bench/ImageFilterCollapse.cpp b/bench/ImageFilterCollapse.cpp index cafcd38c6e..d85d1de330 100644 --- a/bench/ImageFilterCollapse.cpp +++ b/bench/ImageFilterCollapse.cpp @@ -22,20 +22,15 @@ class BaseImageFilterCollapseBench : public Benchmark { public: - BaseImageFilterCollapseBench(): fImageFilter(nullptr) {} - ~BaseImageFilterCollapseBench() { - SkSafeUnref(fImageFilter); - } + BaseImageFilterCollapseBench() {} protected: void doPreDraw(sk_sp colorFilters[], int nFilters) { + SkASSERT(!fImageFilter); + // Create a chain of ImageFilters from colorFilters - fImageFilter = nullptr; for(int i = nFilters; i --> 0;) { - SkAutoTUnref filter( - SkColorFilterImageFilter::Create(colorFilters[i].get(), fImageFilter, nullptr) - ); - SkRefCnt_SafeAssign(fImageFilter, filter.get()); + fImageFilter = SkColorFilterImageFilter::Make(colorFilters[i], fImageFilter); } } @@ -50,7 +45,7 @@ protected: } private: - SkImageFilter* fImageFilter; + sk_sp fImageFilter; SkBitmap fBitmap; void makeBitmap() { @@ -95,7 +90,7 @@ protected: SkTableColorFilter::Make(table3), }; - doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); + this->doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); } private: @@ -134,7 +129,7 @@ protected: make_brightness(-0.1f), }; - doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); + this->doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); } }; diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp index 5132d71ae0..ebb3c6715c 100644 --- a/gm/coloremoji.cpp +++ b/gm/coloremoji.cpp @@ -35,7 +35,7 @@ static sk_sp make_grayscale(sk_sp input) { matrix[2] = matrix[7] = matrix[12] = 0.0722f; matrix[18] = 1.0f; sk_sp filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); - return sk_sp(SkColorFilterImageFilter::Create(filter.get(), input.get())); + return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); } static sk_sp make_blur(float amount, sk_sp input) { diff --git a/gm/colorfilterimagefilter.cpp b/gm/colorfilterimagefilter.cpp index 38ff0ddb22..6031ba7670 100644 --- a/gm/colorfilterimagefilter.cpp +++ b/gm/colorfilterimagefilter.cpp @@ -92,30 +92,27 @@ static sk_sp make_blur(float amount, sk_sp input) } static sk_sp make_brightness(float amount, sk_sp input) { - return sk_sp(SkColorFilterImageFilter::Create(cf_make_brightness(amount).get(), - input.get())); + return SkColorFilterImageFilter::Make(cf_make_brightness(amount), std::move(input)); } static sk_sp make_grayscale(sk_sp input) { - return sk_sp(SkColorFilterImageFilter::Create(cf_make_grayscale().get(), - input.get())); + return SkColorFilterImageFilter::Make(cf_make_grayscale(), std::move(input)); } static sk_sp make_mode_blue(sk_sp input) { - return sk_sp(SkColorFilterImageFilter::Create(cf_make_colorize(SK_ColorBLUE).get(), - input.get())); + return SkColorFilterImageFilter::Make(cf_make_colorize(SK_ColorBLUE), std::move(input)); } static void draw_clipped_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& paint, float outset = 0.0f) { - canvas->save(); - SkRect clip(r); - clip.outset(outset, outset); - canvas->clipRect(clip); - canvas->drawRect(r, paint); - canvas->restore(); + canvas->save(); + SkRect clip(r); + clip.outset(outset, outset); + canvas->clipRect(clip); + canvas->drawRect(r, paint); + canvas->restore(); } DEF_SIMPLE_GM(colorfilterimagefilter, canvas, 400, 100){ @@ -179,10 +176,9 @@ DEF_SIMPLE_GM(colorfilterimagefilter_layer, canvas, 32, 32) { SkAutoCanvasRestore autoCanvasRestore(canvas, false); SkColorMatrix cm; cm.setSaturation(0.0f); - auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); - sk_sp imf(SkColorFilterImageFilter::Create(cf.get())); + sk_sp cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); SkPaint p; - p.setImageFilter(std::move(imf)); + p.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), nullptr)); canvas->saveLayer(NULL, &p); canvas->clear(SK_ColorRED); } diff --git a/gm/dropshadowimagefilter.cpp b/gm/dropshadowimagefilter.cpp index 567ef803b5..11fa9a86fa 100644 --- a/gm/dropshadowimagefilter.cpp +++ b/gm/dropshadowimagefilter.cpp @@ -93,8 +93,9 @@ protected: draw_bitmap, draw_path, draw_paint, draw_text }; - auto cf(SkColorFilter::MakeModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_Mode)); - SkAutoTUnref cfif(SkColorFilterImageFilter::Create(cf.get())); + sk_sp cf(SkColorFilter::MakeModeFilter(SK_ColorMAGENTA, + SkXfermode::kSrcIn_Mode)); + sk_sp cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr)); 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)), @@ -109,7 +110,7 @@ protected: SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode), SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, - SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, cfif, nullptr), + SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, cfif.get(), nullptr), SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr, &cropRect), SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, diff --git a/gm/fadefilter.cpp b/gm/fadefilter.cpp index 386e32b098..c9c362b050 100644 --- a/gm/fadefilter.cpp +++ b/gm/fadefilter.cpp @@ -15,9 +15,8 @@ DEF_SIMPLE_GM(fadefilter, canvas, 256, 256) { 0, 1, 0, 0, 128.0f, 0, 0, 1, 0, 128.0f, 0, 0, 0, 1, 0 }; - auto colorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); - SkAutoTUnref filter(SkColorFilterImageFilter::Create(colorFilter.get())); + sk_sp colorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); SkPaint layerPaint; - layerPaint.setImageFilter(filter); + layerPaint.setImageFilter(SkColorFilterImageFilter::Make(std::move(colorFilter), nullptr)); canvas->drawRect(SkRect::MakeLTRB(64, 64, 192, 192), layerPaint); } diff --git a/gm/imagefilters.cpp b/gm/imagefilters.cpp index f1f1b80ac9..18e353a099 100644 --- a/gm/imagefilters.cpp +++ b/gm/imagefilters.cpp @@ -147,7 +147,7 @@ DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) { SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 }, SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, true), - SkColorFilterImageFilter::Create(cf.get()), + SkColorFilterImageFilter::Make(std::move(cf), nullptr).release(), }; const struct { diff --git a/gm/imagefiltersbase.cpp b/gm/imagefiltersbase.cpp index e2e92356e0..ebbd8956a5 100644 --- a/gm/imagefiltersbase.cpp +++ b/gm/imagefiltersbase.cpp @@ -106,9 +106,9 @@ void IdentityImageFilter::toString(SkString* str) const { /////////////////////////////////////////////////////////////////////////////// -static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { +static void draw_paint(SkCanvas* canvas, const SkRect& r, sk_sp imf) { SkPaint paint; - paint.setImageFilter(imf); + paint.setImageFilter(std::move(imf)); paint.setColor(SK_ColorGREEN); canvas->save(); canvas->clipRect(r); @@ -116,7 +116,7 @@ static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { canvas->restore(); } -static void draw_line(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { +static void draw_line(SkCanvas* canvas, const SkRect& r, sk_sp imf) { SkPaint paint; paint.setColor(SK_ColorBLUE); paint.setImageFilter(imf); @@ -124,7 +124,7 @@ static void draw_line(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, paint); } -static void draw_rect(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { +static void draw_rect(SkCanvas* canvas, const SkRect& r, sk_sp imf) { SkPaint paint; paint.setColor(SK_ColorYELLOW); paint.setImageFilter(imf); @@ -133,7 +133,7 @@ static void draw_rect(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { canvas->drawRect(rr, paint); } -static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { +static void draw_path(SkCanvas* canvas, const SkRect& r, sk_sp imf) { SkPaint paint; paint.setColor(SK_ColorMAGENTA); paint.setImageFilter(imf); @@ -141,7 +141,7 @@ static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { 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 imf) { SkPaint paint; paint.setImageFilter(imf); paint.setColor(SK_ColorCYAN); @@ -152,9 +152,9 @@ 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 imf) { SkPaint paint; - paint.setImageFilter(imf); + paint.setImageFilter(std::move(imf)); SkIRect bounds; r.roundOut(&bounds); @@ -189,21 +189,22 @@ protected: } void onDraw(SkCanvas* canvas) override { - void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { + void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp) = { draw_paint, draw_line, draw_rect, draw_path, draw_text, draw_bitmap, }; auto cf = SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode); - SkImageFilter* filters[] = { + sk_sp filters[] = { nullptr, - IdentityImageFilter::Make(nullptr).release(), - FailImageFilter::Make().release(), - SkColorFilterImageFilter::Create(cf.get()), - SkBlurImageFilter::Make(12.0f, 0.0f, nullptr).release(), - SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE, - SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode), + IdentityImageFilter::Make(nullptr), + FailImageFilter::Make(), + SkColorFilterImageFilter::Make(std::move(cf), nullptr), + SkBlurImageFilter::Make(12.0f, 0.0f, nullptr), + sk_sp(SkDropShadowImageFilter::Create( + 10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE, + SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)), }; SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); @@ -223,10 +224,6 @@ protected: canvas->restore(); canvas->translate(DX, 0); } - - for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) { - SkSafeUnref(filters[j]); - } } private: diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp index 8f36ba9041..907277fc6a 100644 --- a/gm/imagefilterscropexpand.cpp +++ b/gm/imagefilterscropexpand.cpp @@ -75,10 +75,9 @@ protected: SkIntToScalar(outset)); SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasAll_CropEdge); - Draw(canvas, checkerboard, rect, - sk_sp(SkColorFilterImageFilter::Create(cfAlphaTrans.get(), - noopCropped.get(), - &bigRect))); + Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Make(cfAlphaTrans, + noopCropped, + &bigRect)); Draw(canvas, checkerboard, rect, SkBlurImageFilter::Make(0.3f, 0.3f, noopCropped, diff --git a/gm/imagefilterscropped.cpp b/gm/imagefilterscropped.cpp index 66e4d870e9..0c04e52b48 100644 --- a/gm/imagefilterscropped.cpp +++ b/gm/imagefilterscropped.cpp @@ -106,11 +106,11 @@ protected: canvas->drawRect(r, paint); } - virtual void onOnceBeforeDraw() override{ + void onOnceBeforeDraw() override{ make_checkerboard(); } - virtual void onDraw(SkCanvas* canvas) override { + void onDraw(SkCanvas* canvas) override { void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp) = { draw_bitmap, draw_path, draw_paint, draw_text }; @@ -126,14 +126,14 @@ protected: SkIntToScalar(-10), nullptr)); - sk_sp cfOffset(SkColorFilterImageFilter::Create(cf.get(), offset.get())); + sk_sp cfOffset(SkColorFilterImageFilter::Make(cf, std::move(offset))); sk_sp erodeX(SkErodeImageFilter::Make(8, 0, nullptr, &cropRect)); sk_sp erodeY(SkErodeImageFilter::Make(0, 8, nullptr, &cropRect)); sk_sp filters[] = { nullptr, - sk_sp(SkColorFilterImageFilter::Create(cf.get(), nullptr, &cropRect)), + SkColorFilterImageFilter::Make(cf, 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), @@ -148,7 +148,7 @@ protected: SkXfermode::kSrcOver_Mode, &cropRect), SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect), - sk_sp(SkColorFilterImageFilter::Create(cf.get(), nullptr, &bogusRect)), + SkColorFilterImageFilter::Make(cf, nullptr, &bogusRect), }; SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp index eb5519a761..319884b026 100644 --- a/gm/imagefiltersgraph.cpp +++ b/gm/imagefiltersgraph.cpp @@ -137,7 +137,8 @@ protected: SkXfermode::kSrcIn_Mode)); sk_sp blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource))); sk_sp erode(SkErodeImageFilter::Make(4, 4, blur)); - sk_sp color(SkColorFilterImageFilter::Create(cf.get(), erode.get())); + sk_sp color(SkColorFilterImageFilter::Make(std::move(cf), + std::move(erode))); sk_sp merge(SkMergeImageFilter::Make(blur, color)); SkPaint paint; @@ -154,8 +155,8 @@ protected: 0, 0, 0, 0.5f, 0 }; sk_sp matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); - sk_sp colorMorph(SkColorFilterImageFilter::Create(matrixFilter.get(), - morph.get())); + sk_sp colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter), + std::move(morph))); SkPaint paint; paint.setImageFilter(SkXfermodeImageFilter::Make( SkXfermode::Make(SkXfermode::kSrcOver_Mode), @@ -170,7 +171,8 @@ protected: 0, 0, SK_Scalar1, 0, 0, 0, 0, 0, 0.5f, 0 }; sk_sp matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); - sk_sp matrixFilter(SkColorFilterImageFilter::Create(matrixCF.get())); + sk_sp matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF), + nullptr)); sk_sp offsetFilter(SimpleOffsetFilter::Make(10.0f, 10.f, matrixFilter)); SkPaint paint; @@ -228,18 +230,20 @@ protected: } { // Test that crop offsets are absolute, not relative to the parent's crop rect. - auto cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); - auto cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode)); + sk_sp cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, + SkXfermode::kSrcIn_Mode)); + sk_sp cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, + SkXfermode::kSrcIn_Mode)); SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(80), SkIntToScalar(80))); SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(60), SkIntToScalar(60))); - sk_sp color1(SkColorFilterImageFilter::Create(cf1.get(), - nullptr, - &outerRect)); - sk_sp color2(SkColorFilterImageFilter::Create(cf2.get(), - color1.get(), - &innerRect)); + sk_sp color1(SkColorFilterImageFilter::Make(std::move(cf1), + nullptr, + &outerRect)); + sk_sp color2(SkColorFilterImageFilter::Make(std::move(cf2), + std::move(color1), + &innerRect)); SkPaint paint; paint.setImageFilter(std::move(color2)); diff --git a/gm/recordopts.cpp b/gm/recordopts.cpp index d920a1785b..25a88f73e5 100644 --- a/gm/recordopts.cpp +++ b/gm/recordopts.cpp @@ -39,10 +39,11 @@ static void install_detector_color_filter(SkPaint* drawPaint) { // This detector detects that image filter phase of the pixel pipeline receives the correct value. static void install_detector_image_filter(SkPaint* drawPaint) { - auto colorFilter(make_detector_color_filter()); - SkImageFilter* imageFilter = - SkColorFilterImageFilter::Create(colorFilter.get(), drawPaint->getImageFilter()); - drawPaint->setImageFilter(imageFilter)->unref(); + sk_sp colorFilter(make_detector_color_filter()); + sk_sp imageFilter( + SkColorFilterImageFilter::Make(std::move(colorFilter), + sk_ref_sp(drawPaint->getImageFilter()))); + drawPaint->setImageFilter(std::move(imageFilter)); } static void no_detector_install(SkPaint*) { diff --git a/gm/tablecolorfilter.cpp b/gm/tablecolorfilter.cpp index a644bd1053..26a3c2c4f1 100644 --- a/gm/tablecolorfilter.cpp +++ b/gm/tablecolorfilter.cpp @@ -163,19 +163,19 @@ protected: paint.setColorFilter(nullptr); for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) { - auto colorFilter1(gColorFilterMakers[i]()); - SkAutoTUnref imageFilter1(SkColorFilterImageFilter::Create( - colorFilter1.get(), nullptr, nullptr)); + sk_sp colorFilter1(gColorFilterMakers[i]()); + sk_sp imageFilter1(SkColorFilterImageFilter::Make( + std::move(colorFilter1), nullptr)); // Move down to the next line and draw it // each draw being at xOffset of the previous one y += yOffset; x = 0; for (unsigned j = 1; j < SK_ARRAY_COUNT(gColorFilterMakers); ++j) { - auto colorFilter2(gColorFilterMakers[j]()); - SkAutoTUnref imageFilter2(SkColorFilterImageFilter::Create( - colorFilter2.get(), imageFilter1, nullptr)); - paint.setImageFilter(imageFilter2); + sk_sp colorFilter2(gColorFilterMakers[j]()); + sk_sp imageFilter2(SkColorFilterImageFilter::Make( + std::move(colorFilter2), imageFilter1, nullptr)); + paint.setImageFilter(std::move(imageFilter2)); canvas->drawBitmap(bm, x, y, &paint); x += xOffset; } diff --git a/gm/testimagefilters.cpp b/gm/testimagefilters.cpp index ab277716d7..0174fc1d5c 100644 --- a/gm/testimagefilters.cpp +++ b/gm/testimagefilters.cpp @@ -31,7 +31,7 @@ static sk_sp make1() { static sk_sp make2() { sk_sp cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); - return sk_sp(SkColorFilterImageFilter::Create(cf.get())); + return SkColorFilterImageFilter::Make(std::move(cf), nullptr); } static sk_sp make3() { @@ -62,7 +62,7 @@ static sk_sp make6() { sk_sp compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner))); sk_sp cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode)); - sk_sp blue(SkColorFilterImageFilter::Create(cf.get())); + sk_sp blue(SkColorFilterImageFilter::Make(std::move(cf), nullptr)); return SkMergeImageFilter::Make(std::move(compose), std::move(blue)); } @@ -75,7 +75,7 @@ static sk_sp make7() { sk_sp compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner))); sk_sp cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode)); - sk_sp blue(SkColorFilterImageFilter::Create(cf.get())); + sk_sp blue(SkColorFilterImageFilter::Make(std::move(cf), nullptr)); return SkMergeImageFilter::Make(std::move(compose), std::move(blue)); } diff --git a/gm/tileimagefilter.cpp b/gm/tileimagefilter.cpp index c0cca3c895..fa5bb68bd5 100644 --- a/gm/tileimagefilter.cpp +++ b/gm/tileimagefilter.cpp @@ -91,12 +91,11 @@ protected: SkIntToScalar(fBitmap->height())); SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2), SkIntToScalar(fBitmap->height() * 2)); - SkAutoTUnref tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr)); - auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); + sk_sp tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr)); + sk_sp cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); - SkAutoTUnref cfif(SkColorFilterImageFilter::Create(cf.get(), tile.get())); SkPaint paint; - paint.setImageFilter(cfif); + paint.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), std::move(tile))); canvas->save(); canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); canvas->clipRect(dstRect); @@ -114,11 +113,12 @@ protected: SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(5, 5, 40, 40)); sk_sp greenCF = SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode); - SkAutoTUnref green(SkColorFilterImageFilter::Create(greenCF.get(), nullptr, - &cropRect)); - tile.reset(SkTileImageFilter::Create(srcRect, dstRect, green)); + sk_sp green(SkColorFilterImageFilter::Make(std::move(greenCF), + nullptr, + &cropRect)); + tile.reset(SkTileImageFilter::Create(srcRect, dstRect, green.get())); paint.setColor(SK_ColorRED); - paint.setImageFilter(tile); + paint.setImageFilter(std::move(tile)); canvas->drawRect(dstRect, paint); } private: diff --git a/include/effects/SkColorFilterImageFilter.h b/include/effects/SkColorFilterImageFilter.h index ebe263930d..5ed051c0de 100644 --- a/include/effects/SkColorFilterImageFilter.h +++ b/include/effects/SkColorFilterImageFilter.h @@ -14,12 +14,23 @@ class SkColorFilter; class SK_API SkColorFilterImageFilter : public SkImageFilter { public: - static SkImageFilter* Create(SkColorFilter* cf, SkImageFilter* input = NULL, - const CropRect* cropRect = NULL); + static sk_sp Make(sk_sp cf, + sk_sp input, + const CropRect* cropRect = NULL); SK_TO_STRING_OVERRIDE() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorFilterImageFilter) +#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR + static SkImageFilter* Create(SkColorFilter* cf, + SkImageFilter* input = NULL, + const CropRect* cropRect = NULL) { + return Make(sk_ref_sp(cf), + sk_ref_sp(input), + cropRect).release(); + } +#endif + protected: void flatten(SkWriteBuffer&) const override; sk_sp onFilterImage(SkSpecialImage* source, const Context&, @@ -28,8 +39,8 @@ protected: bool affectsTransparentBlack() const override; private: - SkColorFilterImageFilter(SkColorFilter* cf, - SkImageFilter* input, + SkColorFilterImageFilter(sk_sp cf, + sk_sp input, const CropRect* cropRect); sk_sp fColorFilter; diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index 5d433b5748..2be6c31889 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -564,19 +564,15 @@ static sk_sp make_image_filter(bool canBeNull) { break; case COLOR: { sk_sp cf(make_color_filter()); - sk_sp subFilter(make_image_filter()); - filter = cf ? sk_sp(SkColorFilterImageFilter::Create(cf.get(), - subFilter.get())) + filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_filter()) : nullptr; break; } case LUT3D: { int cubeDimension; sk_sp lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1))); - sk_sp cf(SkColorCubeFilter::Make(lut3D, cubeDimension)); - sk_sp subFilter(make_image_filter()); - filter = cf ? sk_sp(SkColorFilterImageFilter::Create(cf.get(), - subFilter.get())) + sk_sp cf(SkColorCubeFilter::Make(std::move(lut3D), cubeDimension)); + filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_filter()) : nullptr; break; } diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp index 1fdc668f9b..8d412cc2f5 100644 --- a/src/effects/SkColorFilterImageFilter.cpp +++ b/src/effects/SkColorFilterImageFilter.cpp @@ -14,8 +14,9 @@ #include "SkSpecialSurface.h" #include "SkWriteBuffer.h" -SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter* input, - const CropRect* cropRect) { +sk_sp SkColorFilterImageFilter::Make(sk_sp cf, + sk_sp input, + const CropRect* cropRect) { if (!cf) { return nullptr; } @@ -24,27 +25,31 @@ SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter if (input && input->isColorFilterNode(&inputCF)) { // This is an optimization, as it collapses the hierarchy by just combining the two // colorfilters into a single one, which the new imagefilter will wrap. - sk_sp newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf), + sk_sp newCF(SkColorFilter::MakeComposeFilter(cf,// can't move bc of fallthru sk_sp(inputCF))); if (newCF) { - return new SkColorFilterImageFilter(newCF.get(), input->getInput(0), cropRect); + return sk_sp(new SkColorFilterImageFilter(std::move(newCF), + sk_ref_sp(input->getInput(0)), + cropRect)); } } - return new SkColorFilterImageFilter(cf, input, cropRect); + return sk_sp(new SkColorFilterImageFilter(std::move(cf), + std::move(input), + cropRect)); } -SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, - SkImageFilter* input, +SkColorFilterImageFilter::SkColorFilterImageFilter(sk_sp cf, + sk_sp input, const CropRect* cropRect) - : INHERITED(1, &input, cropRect) - , fColorFilter(SkRef(cf)) { + : INHERITED(&input, 1, cropRect) + , fColorFilter(std::move(cf)) { } sk_sp SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) { SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); sk_sp cf(buffer.readColorFilter()); - return sk_sp(Create(cf.get(), common.getInput(0).get(), &common.cropRect())); + return Make(std::move(cf), common.getInput(0), &common.cropRect()); } void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 49455c9481..42613a35c5 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -164,7 +164,7 @@ public: SkXfermode::kSrcIn_Mode)); this->addFilter("color filter", - SkColorFilterImageFilter::Create(cf.get(), input.get(), cropRect)); + SkColorFilterImageFilter::Make(cf, input, cropRect).release()); } { @@ -333,30 +333,33 @@ static sk_sp make_small_image() { return surface->makeImageSnapshot(); } -static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) { +static sk_sp make_scale(float amount, sk_sp input) { SkScalar s = amount; SkScalar matrix[20] = { s, 0, 0, 0, 0, 0, s, 0, 0, 0, 0, 0, s, 0, 0, 0, 0, 0, s, 0 }; - auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); - return SkColorFilterImageFilter::Create(filter.get(), input); + sk_sp filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); + return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); } -static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) { +static sk_sp make_grayscale(sk_sp input, + const SkImageFilter::CropRect* cropRect) { 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; - auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); - return SkColorFilterImageFilter::Create(filter.get(), input, cropRect); + sk_sp filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); + return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect); } -static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) { - auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); - return SkColorFilterImageFilter::Create(filter.get(), input, cropRect); +static sk_sp make_blue(sk_sp input, + const SkImageFilter::CropRect* cropRect) { + sk_sp filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, + SkXfermode::kSrcIn_Mode)); + return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect); } static sk_sp create_empty_special_surface(GrContext* context, @@ -395,8 +398,8 @@ static sk_sp create_empty_special_image(GrContext* context, DEF_TEST(ImageFilter, reporter) { { // Check that two non-clipping color-matrice-filters concatenate into a single filter. - SkAutoTUnref halfBrightness(make_scale(0.5f)); - SkAutoTUnref quarterBrightness(make_scale(0.5f, halfBrightness)); + sk_sp halfBrightness(make_scale(0.5f, nullptr)); + sk_sp quarterBrightness(make_scale(0.5f, std::move(halfBrightness))); REPORTER_ASSERT(reporter, nullptr == quarterBrightness->getInput(0)); SkColorFilter* cf; REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf)); @@ -407,8 +410,8 @@ DEF_TEST(ImageFilter, reporter) { { // Check that a clipping color-matrice-filter followed by a color-matrice-filters // concatenates into a single filter, but not a matrixfilter (due to clamping). - SkAutoTUnref doubleBrightness(make_scale(2.0f)); - SkAutoTUnref halfBrightness(make_scale(0.5f, doubleBrightness)); + sk_sp doubleBrightness(make_scale(2.0f, nullptr)); + sk_sp halfBrightness(make_scale(0.5f, std::move(doubleBrightness))); REPORTER_ASSERT(reporter, nullptr == halfBrightness->getInput(0)); SkColorFilter* cf; REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf)); @@ -419,25 +422,25 @@ DEF_TEST(ImageFilter, reporter) { { // Check that a color filter image filter without a crop rect can be // expressed as a color filter. - SkAutoTUnref gray(make_grayscale(nullptr, nullptr)); + sk_sp gray(make_grayscale(nullptr, nullptr)); REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr)); } { // Check that a colorfilterimage filter without a crop rect but with an input // that is another colorfilterimage can be expressed as a colorfilter (composed). - SkAutoTUnref mode(make_blue(nullptr, nullptr)); - SkAutoTUnref gray(make_grayscale(mode, nullptr)); + sk_sp mode(make_blue(nullptr, nullptr)); + sk_sp gray(make_grayscale(std::move(mode), nullptr)); REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr)); } { // Test that if we exceed the limit of what ComposeColorFilter can combine, we still // can build the DAG and won't assert if we call asColorFilter. - SkAutoTUnref filter(make_blue(nullptr, nullptr)); + sk_sp filter(make_blue(nullptr, nullptr)); const int kWayTooManyForComposeColorFilter = 100; for (int i = 0; i < kWayTooManyForComposeColorFilter; ++i) { - filter.reset(make_blue(filter, nullptr)); + filter = make_blue(filter, nullptr); // the first few of these will succeed, but after we hit the internal limit, // it will then return false. (void)filter->asColorFilter(nullptr); @@ -448,7 +451,7 @@ DEF_TEST(ImageFilter, reporter) { // Check that a color filter image filter with a crop rect cannot // be expressed as a color filter. SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); - SkAutoTUnref grayWithCrop(make_grayscale(nullptr, &cropRect)); + sk_sp grayWithCrop(make_grayscale(nullptr, &cropRect)); REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(nullptr)); } @@ -459,17 +462,19 @@ DEF_TEST(ImageFilter, reporter) { blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; SkScalar redToGreenMatrix[20] = { 0 }; redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1; - auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix)); - SkAutoTUnref filter1(SkColorFilterImageFilter::Create(blueToRed.get())); - auto redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix)); - SkAutoTUnref filter2(SkColorFilterImageFilter::Create(redToGreen.get(), filter1.get())); + sk_sp blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix)); + sk_sp filter1(SkColorFilterImageFilter::Make(std::move(blueToRed), + nullptr)); + sk_sp redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix)); + sk_sp filter2(SkColorFilterImageFilter::Make(std::move(redToGreen), + std::move(filter1))); SkBitmap result; result.allocN32Pixels(kBitmapSize, kBitmapSize); SkPaint paint; paint.setColor(SK_ColorBLUE); - paint.setImageFilter(filter2.get()); + paint.setImageFilter(std::move(filter2)); SkCanvas canvas(result); canvas.clear(0x0); SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize)); @@ -714,8 +719,8 @@ static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy, SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nullptr); sk_sp green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode)); SkASSERT(green->affectsTransparentBlack()); - sk_sp greenFilter(SkColorFilterImageFilter::Create(green.get(), - failFilter.get())); + sk_sp greenFilter(SkColorFilterImageFilter::Make(std::move(green), + std::move(failFilter))); SkIPoint offset; sk_sp result(greenFilter->filterImage(source.get(), ctx, &offset)); REPORTER_ASSERT(reporter, nullptr != result.get()); @@ -795,12 +800,14 @@ static void draw_saveLayer_picture(int width, int height, int tileSize, SkMatrix matrix; matrix.setTranslate(SkIntToScalar(50), 0); - auto cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode)); - SkAutoTUnref cfif(SkColorFilterImageFilter::Create(cf.get())); - SkAutoTUnref imageFilter(SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality, cfif.get())); + sk_sp cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode)); + sk_sp cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr)); + sk_sp imageFilter(SkImageFilter::CreateMatrixFilter(matrix, + kNone_SkFilterQuality, + cfif.get())); SkPaint paint; - paint.setImageFilter(imageFilter.get()); + paint.setImageFilter(std::move(imageFilter)); SkPictureRecorder recorder; SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50)); SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width), @@ -1220,11 +1227,11 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) { SkRTreeFactory factory; SkPictureRecorder recorder; - auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode)); - SkAutoTUnref imageFilter( - SkColorFilterImageFilter::Create(green.get())); + sk_sp green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, + SkXfermode::kSrc_Mode)); + sk_sp imageFilter(SkColorFilterImageFilter::Make(green, nullptr)); SkPaint imageFilterPaint; - imageFilterPaint.setImageFilter(imageFilter.get()); + imageFilterPaint.setImageFilter(std::move(imageFilter)); SkPaint colorFilterPaint; colorFilterPaint.setColorFilter(green); @@ -1342,18 +1349,22 @@ static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re bitmap.allocN32Pixels(1, 1); bitmap.eraseARGB(255, 255, 255, 255); - auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode)); - SkAutoTUnref greenFilter(SkColorFilterImageFilter::Create(green.get())); + sk_sp green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, + SkXfermode::kSrcIn_Mode)); + sk_sp greenFilter(SkColorFilterImageFilter::Make(green, nullptr)); SkImageFilter::CropRect cropRect(SkRect::MakeEmpty()); - SkAutoTUnref croppedOut( - SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect)); + sk_sp croppedOut(SkColorFilterImageFilter::Make(green, nullptr, &cropRect)); // Check that an xfermode image filter whose input has been cropped out still draws the other // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning. auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode); - auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, croppedOut, nullptr)); - auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, greenFilter, nullptr)); - auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, croppedOut, nullptr)); + auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, + greenFilter.get(), croppedOut.get(), nullptr)); + auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, + croppedOut.get(), greenFilter.get(), nullptr)); + auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, + croppedOut.get(), + croppedOut.get(), nullptr)); SkPaint paint; paint.setImageFilter(xfermodeNoFg); @@ -1512,7 +1523,7 @@ static void test_partial_crop_rect(SkImageFilter::Proxy* proxy, SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::kHasHeight_CropEdge); - SkAutoTUnref filter(make_grayscale(nullptr, &cropRect)); + sk_sp filter(make_grayscale(nullptr, &cropRect)); SkIPoint offset; SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr); @@ -1564,7 +1575,7 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; sk_sp greenCF(SkColorFilter::MakeMatrixFilterRowMajor255(greenMatrix)); - sk_sp green(SkColorFilterImageFilter::Create(greenCF.get())); + sk_sp green(SkColorFilterImageFilter::Make(greenCF, nullptr)); REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack()); REPORTER_ASSERT(reporter, !green->canComputeFastBounds()); @@ -1580,13 +1591,15 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { allOne[i] = 255; } - auto identityCF(SkTableColorFilter::MakeARGB(identity, identity, identity, allOne)); - SkAutoTUnref identityFilter(SkColorFilterImageFilter::Create(identityCF.get())); + sk_sp identityCF(SkTableColorFilter::MakeARGB(identity, identity, + identity, allOne)); + sk_sp identityFilter(SkColorFilterImageFilter::Make(identityCF, nullptr)); REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack()); REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds()); - auto forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity, identity, identity)); - SkAutoTUnref forceOpaque(SkColorFilterImageFilter::Create(forceOpaqueCF.get())); + sk_sp forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity, + identity, identity)); + sk_sp forceOpaque(SkColorFilterImageFilter::Make(forceOpaqueCF, nullptr)); REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack()); REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds()); } diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index a57a1b2fb2..f6ed59e81a 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -278,11 +278,11 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) { // optimize away SkScalar blueToRedMatrix[20] = { 0 }; blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; - auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix)); - SkAutoTUnref filter(SkColorFilterImageFilter::Create(blueToRed.get())); + sk_sp blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix)); + sk_sp filter(SkColorFilterImageFilter::Make(std::move(blueToRed), nullptr)); SkPaint complexPaint; - complexPaint.setImageFilter(filter); + complexPaint.setImageFilter(std::move(filter)); sk_sp pict, child; SkRTreeFactory bbhFactory;