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

Unified Diff: bench/ColorFilterBench.cpp

Issue 1858813002: Update SkColorFilterImageFilter 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 | « no previous file | bench/ImageFilterCollapse.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/ColorFilterBench.cpp
diff --git a/bench/ColorFilterBench.cpp b/bench/ColorFilterBench.cpp
index c4ba1e5dcb435e709aa103a9a5d54479c8290dd1..30bd3161a0566395d837e856d0b482ec00093454 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<SkImageFilter> make_brightness(float amount, sk_sp<SkImageFilter> 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<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+ return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
+}
+
+static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> 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<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+ return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
+}
+
+static sk_sp<SkImageFilter> make_mode_blue(sk_sp<SkImageFilter> input) {
+ sk_sp<SkColorFilter> 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<SkImageFilter> dim(make_brightness(-brightness));
- SkAutoTUnref<SkImageFilter> bright(make_brightness(brightness, dim));
- paint.setImageFilter(bright);
+ sk_sp<SkImageFilter> 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<SkImageFilter> brightness(make_brightness(0.9f));
- SkAutoTUnref<SkImageFilter> grayscale(make_grayscale(brightness));
- paint.setImageFilter(grayscale);
+ sk_sp<SkImageFilter> 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<SkImageFilter> grayscale(make_grayscale());
- SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f, grayscale));
- paint.setImageFilter(brightness);
+ sk_sp<SkImageFilter> 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<SkImageFilter> blue(make_mode_blue());
- SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f, blue));
- paint.setImageFilter(brightness);
+ sk_sp<SkImageFilter> 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<SkImageFilter> brightness(make_brightness(1.0f));
- SkAutoTUnref<SkImageFilter> blue(make_mode_blue(brightness));
- paint.setImageFilter(blue);
+ sk_sp<SkImageFilter> 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<SkImageFilter> 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<SkImageFilter> 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<SkImageFilter> grayscale(make_grayscale());
- paint.setImageFilter(grayscale);
+ paint.setImageFilter(make_grayscale(nullptr));
canvas->drawRect(r, paint);
}
}
« no previous file with comments | « no previous file | bench/ImageFilterCollapse.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698