sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "bench/Benchmark.h" |
| 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/core/SkShader.h" |
| 10 | #include "include/effects/SkPerlinNoiseShader.h" |
sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 11 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 12 | class PerlinNoiseBench : public Benchmark { |
sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 13 | SkISize fSize; |
| 14 | |
| 15 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 16 | PerlinNoiseBench() { |
sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 17 | fSize = SkISize::Make(80, 80); |
| 18 | } |
| 19 | |
| 20 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 21 | const char* onGetName() override { |
sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 22 | return "perlinnoise"; |
| 23 | } |
| 24 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 25 | void onDraw(int loops, SkCanvas* canvas) override { |
Florin Malita | 14d54c2 | 2017-05-18 11:52:59 -0400 | [diff] [blame] | 26 | this->test(loops, canvas, 0, 0, 0.1f, 0.1f, 3, 0, false); |
sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 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 | |
Florin Malita | 14d54c2 | 2017-05-18 11:52:59 -0400 | [diff] [blame] | 41 | void test(int loops, SkCanvas* canvas, int x, int y, |
sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 42 | float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, |
| 43 | bool stitchTiles) { |
sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 44 | SkPaint paint; |
Florin Malita | 14d54c2 | 2017-05-18 11:52:59 -0400 | [diff] [blame] | 45 | paint.setShader(SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, |
| 46 | numOctaves, seed, |
| 47 | stitchTiles ? &fSize : nullptr)); |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 48 | for (int i = 0; i < loops; i++) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 49 | this->drawClippedRect(canvas, x, y, paint); |
| 50 | } |
sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 51 | } |
| 52 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 53 | typedef Benchmark INHERITED; |
sugoi@google.com | 4775cba | 2013-04-17 13:46:56 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /////////////////////////////////////////////////////////////////////////////// |
| 57 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 58 | DEF_BENCH( return new PerlinNoiseBench(); ) |