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
|
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:
|
2013-09-13 19:52:27 +00:00
|
|
|
BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small) :
|
|
|
|
fIsSmall(small), fInitialized(false), fSigmaX(sigmaX), fSigmaY(sigmaY) {
|
2013-04-24 19:36:44 +00:00
|
|
|
fName.printf("blur_image_filter_%s_%.2f_%.2f", fIsSmall ? "small" : "large",
|
|
|
|
SkScalarToFloat(sigmaX), SkScalarToFloat(sigmaY));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onPreDraw() SK_OVERRIDE {
|
|
|
|
if (!fInitialized) {
|
|
|
|
make_checkerboard();
|
|
|
|
fInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2013-04-24 19:36:44 +00:00
|
|
|
SkPaint paint;
|
2014-03-10 10:51:58 +00:00
|
|
|
paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref();
|
2013-09-10 19:23:38 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
canvas->drawBitmap(fCheckerboard, 0, 0, &paint);
|
|
|
|
}
|
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;
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-11-08 20:49:04 +00:00
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false);)
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, false);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, false);)
|
2014-01-13 08:16:45 +00:00
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true);)
|
|
|
|
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, false);)
|