2013-04-24 19:36:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-08-05 15:25:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/utils/SkRandom.h"
|
2013-04-24 19:36:44 +00:00
|
|
|
|
|
|
|
#define FILTER_WIDTH_SMALL 32
|
|
|
|
#define FILTER_HEIGHT_SMALL 32
|
|
|
|
#define FILTER_WIDTH_LARGE 256
|
|
|
|
#define FILTER_HEIGHT_LARGE 256
|
2014-08-11 20:55:34 +00:00
|
|
|
#define BLUR_SIGMA_MINI 0.5f
|
2013-11-25 19:44:07 +00:00
|
|
|
#define BLUR_SIGMA_SMALL 1.0f
|
|
|
|
#define BLUR_SIGMA_LARGE 10.0f
|
2014-01-13 08:16:45 +00:00
|
|
|
#define BLUR_SIGMA_HUGE 80.0f
|
2013-04-24 19:36:44 +00:00
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2015-10-30 20:17:20 +00:00
|
|
|
// When 'cropped' is set we apply a cropRect to the blurImageFilter. The crop rect is an inset of
|
|
|
|
// the source's natural dimensions. This is intended to exercise blurring a larger source bitmap
|
|
|
|
// to a smaller destination bitmap.
|
|
|
|
|
|
|
|
// When 'expanded' is set we apply a cropRect to the input of the blurImageFilter (a noOp
|
|
|
|
// offsetImageFilter). The crop rect in this case is an inset of the source's natural dimensions.
|
|
|
|
// An additional crop rect is applied to the blurImageFilter that is just the natural dimensions
|
|
|
|
// of the source (not inset). This is intended to exercise blurring a smaller source bitmap to a
|
|
|
|
// larger destination.
|
|
|
|
|
2021-01-24 16:39:58 +00:00
|
|
|
static sk_sp<SkImage> make_checkerboard(int width, int height) {
|
2016-04-04 11:31:25 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(width, height);
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
canvas.clear(0x00000000);
|
|
|
|
SkPaint darkPaint;
|
|
|
|
darkPaint.setColor(0xFF804020);
|
|
|
|
SkPaint lightPaint;
|
|
|
|
lightPaint.setColor(0xFF244484);
|
|
|
|
for (int y = 0; y < height; y += 16) {
|
|
|
|
for (int x = 0; x < width; x += 16) {
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-24 16:39:58 +00:00
|
|
|
return bm.asImage();
|
2016-04-04 11:31:25 +00:00
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class BlurImageFilterBench : public Benchmark {
|
2013-04-24 19:36:44 +00:00
|
|
|
public:
|
2015-10-30 20:17:20 +00:00
|
|
|
BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cropped,
|
|
|
|
bool expanded)
|
|
|
|
: fIsSmall(small)
|
|
|
|
, fIsCropped(cropped)
|
|
|
|
, fIsExpanded(expanded)
|
|
|
|
, fInitialized(false)
|
|
|
|
, fSigmaX(sigmaX)
|
|
|
|
, fSigmaY(sigmaY) {
|
|
|
|
fName.printf("blur_image_filter_%s%s%s_%.2f_%.2f",
|
|
|
|
fIsSmall ? "small" : "large",
|
|
|
|
fIsCropped ? "_cropped" : "",
|
|
|
|
fIsExpanded ? "_expanded" : "",
|
|
|
|
SkScalarToFloat(sigmaX), SkScalarToFloat(sigmaY));
|
|
|
|
SkASSERT(!fIsExpanded || fIsCropped); // never want expansion w/o cropping
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-24 19:36:44 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2013-04-24 19:36:44 +00:00
|
|
|
if (!fInitialized) {
|
2016-04-04 11:31:25 +00:00
|
|
|
fCheckerboard = make_checkerboard(fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE,
|
|
|
|
fIsSmall ? FILTER_HEIGHT_SMALL : FILTER_HEIGHT_LARGE);
|
2013-04-24 19:36:44 +00:00
|
|
|
fInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2019-08-05 15:25:23 +00:00
|
|
|
static const int kX = 0;
|
|
|
|
static const int kY = 0;
|
2021-01-24 16:39:58 +00:00
|
|
|
const SkIRect bmpRect = SkIRect::MakeXYWH(kX, kY, fCheckerboard->width(),
|
|
|
|
fCheckerboard->height());
|
2019-08-05 15:25:23 +00:00
|
|
|
const SkIRect bmpRectInset = bmpRect.makeInset(10, 10);
|
2015-10-30 20:17:20 +00:00
|
|
|
|
2017-10-09 19:45:33 +00:00
|
|
|
sk_sp<SkImageFilter> input = fIsExpanded
|
2019-08-05 15:25:23 +00:00
|
|
|
? SkImageFilters::Offset(0, 0, nullptr, &bmpRectInset)
|
2016-04-04 11:31:25 +00:00
|
|
|
: nullptr;
|
2015-06-30 14:42:42 +00:00
|
|
|
|
2019-08-05 15:25:23 +00:00
|
|
|
const SkIRect* crop =
|
|
|
|
fIsExpanded ? &bmpRect : fIsCropped ? &bmpRectInset : nullptr;
|
2016-04-04 11:31:25 +00:00
|
|
|
SkPaint paint;
|
2019-08-05 15:25:23 +00:00
|
|
|
paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, std::move(input), crop));
|
2021-01-24 16:39:58 +00:00
|
|
|
SkSamplingOptions sampling;
|
2013-09-10 19:23:38 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2021-01-24 16:39:58 +00:00
|
|
|
canvas->drawImage(fCheckerboard, kX, kY, sampling, &paint);
|
2013-09-10 19:23:38 +00:00
|
|
|
}
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
SkString fName;
|
|
|
|
bool fIsSmall;
|
2015-06-30 14:42:42 +00:00
|
|
|
bool fIsCropped;
|
2015-10-30 20:17:20 +00:00
|
|
|
bool fIsExpanded;
|
2013-04-24 19:36:44 +00:00
|
|
|
bool fInitialized;
|
2021-01-24 16:39:58 +00:00
|
|
|
sk_sp<SkImage> fCheckerboard;
|
2013-04-24 19:36:44 +00:00
|
|
|
SkScalar fSigmaX, fSigmaY;
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2013-04-24 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
2015-10-30 20:17:20 +00:00
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, false, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, true, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, false, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, true, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, false, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, false, false, false);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, false, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, true, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, false, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, true, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, false, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, false, true, false);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, false, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, true, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, false, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, true, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, false, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, false, true, true);)
|