2013-04-17 13:46:56 +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/SkCanvas.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/effects/SkPerlinNoiseShader.h"
|
2013-04-17 13:46:56 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class PerlinNoiseBench : public Benchmark {
|
2013-04-17 13:46:56 +00:00
|
|
|
SkISize fSize;
|
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PerlinNoiseBench() {
|
2013-04-17 13:46:56 +00:00
|
|
|
fSize = SkISize::Make(80, 80);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-17 13:46:56 +00:00
|
|
|
return "perlinnoise";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2017-05-18 15:52:59 +00:00
|
|
|
this->test(loops, canvas, 0, 0, 0.1f, 0.1f, 3, 0, false);
|
2013-04-17 13:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
|
|
|
|
SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height())));
|
|
|
|
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
|
|
|
|
SkIntToScalar(fSize.width()),
|
|
|
|
SkIntToScalar(fSize.height()));
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2017-05-18 15:52:59 +00:00
|
|
|
void test(int loops, SkCanvas* canvas, int x, int y,
|
2013-04-17 13:46:56 +00:00
|
|
|
float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed,
|
|
|
|
bool stitchTiles) {
|
|
|
|
SkPaint paint;
|
2017-05-18 15:52:59 +00:00
|
|
|
paint.setShader(SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY,
|
|
|
|
numOctaves, seed,
|
|
|
|
stitchTiles ? &fSize : nullptr));
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-09-10 19:23:38 +00:00
|
|
|
this->drawClippedRect(canvas, x, y, paint);
|
|
|
|
}
|
2013-04-17 13:46:56 +00:00
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-04-17 13:46:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new PerlinNoiseBench(); )
|