aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/ColorFilterBench.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-04-05 11:50:42 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-05 11:50:42 -0700
commit5605b56afa5bd89f3148b397318b616fccfd4004 (patch)
tree67be71f4ab5e83d081c1531daeba3caf7dafeb4c /bench/ColorFilterBench.cpp
parent235cbf23c4836f87a4d53ac48345942ff605a739 (diff)
Update SkColorFilterImageFilter to sk_sp
Diffstat (limited to 'bench/ColorFilterBench.cpp')
-rw-r--r--bench/ColorFilterBench.cpp148
1 files changed, 66 insertions, 82 deletions
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<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);
}
}