From 5605b56afa5bd89f3148b397318b616fccfd4004 Mon Sep 17 00:00:00 2001 From: robertphillips Date: Tue, 5 Apr 2016 11:50:42 -0700 Subject: Update SkColorFilterImageFilter to sk_sp TBR=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1858813002 Review URL: https://codereview.chromium.org/1858813002 --- bench/ColorFilterBench.cpp | 148 ++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 82 deletions(-) (limited to 'bench/ColorFilterBench.cpp') 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); } } -- cgit v1.2.3