2014-04-10 16:16:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkImage.h"
|
2019-08-05 15:25:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/Resources.h"
|
2014-04-10 16:16:13 +00:00
|
|
|
|
|
|
|
// Exercise a blur filter connected to 5 inputs of the same merge filter.
|
|
|
|
// This bench shows an improvement in performance once cacheing of re-used
|
|
|
|
// nodes is implemented, since the DAG is no longer flattened to a tree.
|
2014-06-19 19:32:29 +00:00
|
|
|
class ImageFilterDAGBench : public Benchmark {
|
2014-04-10 16:16:13 +00:00
|
|
|
public:
|
2014-07-01 15:43:42 +00:00
|
|
|
ImageFilterDAGBench() {}
|
2014-04-10 16:16:13 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-04-10 16:16:13 +00:00
|
|
|
return "image_filter_dag";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2016-03-30 20:34:16 +00:00
|
|
|
const SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400));
|
|
|
|
|
2019-08-05 15:25:23 +00:00
|
|
|
// Set up the filters once, we're not interested in measuring allocation time here
|
|
|
|
sk_sp<SkImageFilter> blur(SkImageFilters::Blur(20.0f, 20.0f, nullptr));
|
|
|
|
sk_sp<SkImageFilter> inputs[kNumInputs];
|
|
|
|
for (int i = 0; i < kNumInputs; ++i) {
|
|
|
|
inputs[i] = blur;
|
|
|
|
}
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(SkImageFilters::Merge(inputs, kNumInputs));
|
|
|
|
|
|
|
|
// Only measure the filter computations done in drawRect()
|
|
|
|
// TODO (michaelludwig) - This benchmark, and the ones defined below, allocate their filters
|
|
|
|
// outside of the loop. This means that repeatedly drawing with the same filter will hit
|
|
|
|
// the global image filter cache inside the loop. Raster backend uses this cache so will see
|
|
|
|
// artificially improved performance. Ganesh will not because it uses a cache per filter
|
|
|
|
// call, so only within-DAG cache hits are measured (as desired). skbug:9297 wants to move
|
|
|
|
// raster backend to the same pattern, which will make the benchmark executions fair again.
|
2014-07-01 15:43:42 +00:00
|
|
|
for (int j = 0; j < loops; j++) {
|
|
|
|
canvas->drawRect(rect, paint);
|
2014-04-10 16:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-03-30 20:34:16 +00:00
|
|
|
static const int kNumInputs = 5;
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2014-04-10 16:16:13 +00:00
|
|
|
};
|
|
|
|
|
2016-09-21 16:46:57 +00:00
|
|
|
class ImageMakeWithFilterDAGBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
ImageMakeWithFilterDAGBench() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return "image_make_with_filter_dag";
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDelayedSetup() override {
|
2017-12-08 15:21:31 +00:00
|
|
|
fImage = GetResourceAsImage("images/mandrill_512.png");
|
2016-09-21 16:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
|
|
|
SkIRect subset = SkIRect::MakeSize(fImage->dimensions());
|
|
|
|
SkIPoint offset = SkIPoint::Make(0, 0);
|
|
|
|
SkIRect discardSubset;
|
2019-08-05 15:25:23 +00:00
|
|
|
// makeWithFilter will only use the GPU backend if the image is already a texture
|
2019-08-14 17:19:04 +00:00
|
|
|
sk_sp<SkImage> image = fImage->makeTextureImage(canvas->getGrContext());
|
2019-08-05 15:25:23 +00:00
|
|
|
if (!image) {
|
|
|
|
image = fImage;
|
|
|
|
}
|
2016-09-21 16:46:57 +00:00
|
|
|
|
2019-08-05 15:25:23 +00:00
|
|
|
// Set up the filters once so the allocation cost isn't included per-loop
|
|
|
|
sk_sp<SkImageFilter> blur(SkImageFilters::Blur(20.0f, 20.0f, nullptr));
|
|
|
|
sk_sp<SkImageFilter> inputs[kNumInputs];
|
|
|
|
for (int i = 0; i < kNumInputs; ++i) {
|
|
|
|
inputs[i] = blur;
|
|
|
|
}
|
|
|
|
sk_sp<SkImageFilter> mergeFilter = SkImageFilters::Merge(inputs, kNumInputs);
|
|
|
|
|
|
|
|
// But measure makeWithFilter() per loop since that's the focus of this benchmark
|
2016-09-21 16:46:57 +00:00
|
|
|
for (int j = 0; j < loops; j++) {
|
|
|
|
image = image->makeWithFilter(mergeFilter.get(), subset, subset, &discardSubset,
|
|
|
|
&offset);
|
|
|
|
SkASSERT(image && image->dimensions() == fImage->dimensions());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int kNumInputs = 5;
|
|
|
|
sk_sp<SkImage> fImage;
|
|
|
|
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-10-26 13:55:47 +00:00
|
|
|
// Exercise a blur filter connected to both inputs of an SkDisplacementMapEffect.
|
|
|
|
|
|
|
|
class ImageFilterDisplacedBlur : public Benchmark {
|
|
|
|
public:
|
|
|
|
ImageFilterDisplacedBlur() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return "image_filter_displaced_blur";
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2019-08-05 15:25:23 +00:00
|
|
|
// Setup filter once
|
|
|
|
sk_sp<SkImageFilter> blur(SkImageFilters::Blur(4.0f, 4.0f, nullptr));
|
|
|
|
SkScalar scale = 2;
|
2016-04-15 14:17:36 +00:00
|
|
|
|
2019-08-05 15:25:23 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(SkImageFilters::DisplacementMap(SkColorChannel::kR, SkColorChannel::kR,
|
|
|
|
scale, blur, blur));
|
2016-04-15 14:17:36 +00:00
|
|
|
|
2019-08-05 15:25:23 +00:00
|
|
|
SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400));
|
|
|
|
|
|
|
|
// As before, measure just the filter computation time inside the loops
|
|
|
|
for (int j = 0; j < loops; j++) {
|
2015-10-26 13:55:47 +00:00
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2017-09-11 16:12:56 +00:00
|
|
|
// Exercise an Xfermode kSrcIn filter compositing two inputs which have a small intersection.
|
|
|
|
class ImageFilterXfermodeIn : public Benchmark {
|
|
|
|
public:
|
|
|
|
ImageFilterXfermodeIn() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override { return "image_filter_xfermode_in"; }
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2019-08-05 15:25:23 +00:00
|
|
|
// Allocate filters once to avoid measuring instantiation time
|
|
|
|
auto blur = SkImageFilters::Blur(20.0f, 20.0f, nullptr);
|
|
|
|
auto offset1 = SkImageFilters::Offset(100.0f, 100.0f, blur);
|
|
|
|
auto offset2 = SkImageFilters::Offset(-100.0f, -100.0f, blur);
|
|
|
|
auto xfermode =
|
|
|
|
SkImageFilters::Xfermode(SkBlendMode::kSrcIn, offset1, offset2, nullptr);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(xfermode);
|
|
|
|
|
|
|
|
// Measure only the filter time
|
2017-09-11 16:12:56 +00:00
|
|
|
for (int j = 0; j < loops; j++) {
|
|
|
|
canvas->drawRect(SkRect::MakeWH(200.0f, 200.0f), paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2014-04-10 16:16:13 +00:00
|
|
|
DEF_BENCH(return new ImageFilterDAGBench;)
|
2016-09-21 16:46:57 +00:00
|
|
|
DEF_BENCH(return new ImageMakeWithFilterDAGBench;)
|
2015-10-26 13:55:47 +00:00
|
|
|
DEF_BENCH(return new ImageFilterDisplacedBlur;)
|
2017-09-11 16:12:56 +00:00
|
|
|
DEF_BENCH(return new ImageFilterXfermodeIn;)
|