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.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-04-17 13:46:56 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPerlinNoiseShader.h"
|
|
|
|
|
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:
|
|
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
|
|
|
return "perlinnoise";
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
|
|
|
this->test(loops, canvas, 0, 0, SkPerlinNoiseShader::kFractalNoise_Type,
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
void test(const int loops, SkCanvas* canvas, int x, int y, SkPerlinNoiseShader::Type type,
|
2013-04-17 13:46:56 +00:00
|
|
|
float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed,
|
|
|
|
bool stitchTiles) {
|
|
|
|
SkShader* shader = (type == SkPerlinNoiseShader::kFractalNoise_Type) ?
|
|
|
|
SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves,
|
|
|
|
seed, stitchTiles ? &fSize : NULL) :
|
2014-04-01 16:09:37 +00:00
|
|
|
SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves,
|
2013-04-17 13:46:56 +00:00
|
|
|
seed, stitchTiles ? &fSize : NULL);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setShader(shader)->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
|
|
|
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(); )
|