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