| 1 |
/* |
| 2 |
* Copyright 2013 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
#include "bench/Benchmark.h" |
| 8 |
#include "include/core/SkCanvas.h" |
| 9 |
#include "include/core/SkShader.h" |
| 10 |
#include "include/effects/SkPerlinNoiseShader.h" |
| 11 |
|
| 12 |
class PerlinNoiseBench : public Benchmark { |
| 13 |
SkISize fSize; |
| 14 |
|
| 15 |
public: |
| 16 |
PerlinNoiseBench() { |
| 17 |
fSize = SkISize::Make(80, 80); |
| 18 |
} |
| 19 |
|
| 20 |
protected: |
| 21 |
const char* onGetName() override { |
| 22 |
return "perlinnoise"; |
| 23 |
} |
| 24 |
|
| 25 |
void onDraw(int loops, SkCanvas* canvas) override { |
| 26 |
this->test(loops, canvas, 0, 0, 0.1f, 0.1f, 3, 0, false); |
| 27 |
} |
| 28 |
|
| 29 |
private: |
| 30 |
void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) { |
| 31 |
canvas->save(); |
| 32 |
canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), |
| 33 |
SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height()))); |
| 34 |
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), |
| 35 |
SkIntToScalar(fSize.width()), |
| 36 |
SkIntToScalar(fSize.height())); |
| 37 |
canvas->drawRect(r, paint); |
| 38 |
canvas->restore(); |
| 39 |
} |
| 40 |
|
| 41 |
void test(int loops, SkCanvas* canvas, int x, int y, |
| 42 |
float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, |
| 43 |
bool stitchTiles) { |
| 44 |
SkPaint paint; |
| 45 |
paint.setShader(SkShaders::MakeFractalNoise( |
| 46 |
baseFrequencyX, baseFrequencyY, numOctaves, seed, stitchTiles ? &fSize : nullptr)); |
| 47 |
for (int i = 0; i < loops; i++) { |
| 48 |
this->drawClippedRect(canvas, x, y, paint); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
using INHERITED = Benchmark; |
| 53 |
}; |
| 54 |
|
| 55 |
/////////////////////////////////////////////////////////////////////////////// |
| 56 |
|
| 57 |
DEF_BENCH( return new PerlinNoiseBench(); ) |