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.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-04-24 19:36:44 +00:00
|
|
|
#include "SkBlurImageFilter.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class BlurImageFilterBench : public Benchmark {
|
2013-04-24 19:36:44 +00:00
|
|
|
public:
|
2015-06-30 14:42:42 +00:00
|
|
|
BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cropped) :
|
|
|
|
fIsSmall(small), fIsCropped(cropped), fInitialized(false), fSigmaX(sigmaX), fSigmaY(sigmaY) {
|
|
|
|
fName.printf("blur_image_filter_%s%s_%.2f_%.2f", fIsSmall ? "small" : "large",
|
|
|
|
fIsCropped ? "_cropped" : "", SkScalarToFloat(sigmaX), SkScalarToFloat(sigmaY));
|
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) {
|
|
|
|
make_checkerboard();
|
|
|
|
fInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2013-04-24 19:36:44 +00:00
|
|
|
SkPaint paint;
|
2015-06-30 14:42:42 +00:00
|
|
|
static const SkScalar kX = 0;
|
|
|
|
static const SkScalar kY = 0;
|
|
|
|
const SkRect bmpRect = SkRect::MakeXYWH(kX, kY,
|
|
|
|
SkIntToScalar(fCheckerboard.width()),
|
|
|
|
SkIntToScalar(fCheckerboard.height()));
|
|
|
|
const SkImageFilter::CropRect cropRect =
|
|
|
|
SkImageFilter::CropRect(bmpRect.makeInset(10.f, 10.f));
|
2015-08-27 14:41:13 +00:00
|
|
|
const SkImageFilter::CropRect* crop = fIsCropped ? &cropRect : nullptr;
|
2015-06-30 14:42:42 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY, nullptr, crop))->unref();
|
2013-09-10 19:23:38 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2015-06-30 14:42:42 +00:00
|
|
|
canvas->drawBitmap(fCheckerboard, kX, kY, &paint);
|
2013-09-10 19:23:38 +00:00
|
|
|
}
|
2013-04-24 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void make_checkerboard() {
|
|
|
|
const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE;
|
|
|
|
const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE;
|
2014-06-10 02:52:07 +00:00
|
|
|
fCheckerboard.allocN32Pixels(w, h);
|
|
|
|
SkCanvas canvas(fCheckerboard);
|
2013-04-24 19:36:44 +00:00
|
|
|
canvas.clear(0x00000000);
|
|
|
|
SkPaint darkPaint;
|
|
|
|
darkPaint.setColor(0xFF804020);
|
|
|
|
SkPaint lightPaint;
|
|
|
|
lightPaint.setColor(0xFF244484);
|
|
|
|
for (int y = 0; y < h; y += 16) {
|
|
|
|
for (int x = 0; x < w; 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString fName;
|
|
|
|
bool fIsSmall;
|
2015-06-30 14:42:42 +00:00
|
|
|
bool fIsCropped;
|
2013-04-24 19:36:44 +00:00
|
|
|
bool fInitialized;
|
|
|
|
SkBitmap fCheckerboard;
|
|
|
|
SkScalar fSigmaX, fSigmaY;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-04-24 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
2015-06-30 14:42:42 +00:00
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, false, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, false, false);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, false, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, false, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, false, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, false, true);)
|