commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame^] | 7 | #include "Benchmark.h" |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 8 | #include "SkCanvas.h" |
| 9 | #include "SkPathUtils.h" |
| 10 | #include "SkRandom.h" |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 11 | #include "SkString.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame^] | 12 | #include "SkTime.h" |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 13 | |
| 14 | #define H 16 |
| 15 | #define W 16 |
| 16 | #define STRIDE 2 |
| 17 | |
| 18 | //this function is redefined for sample, test, and bench. is there anywhere |
skia.committer@gmail.com | 0d55dd7 | 2013-07-02 07:00:59 +0000 | [diff] [blame] | 19 | // I can put it to avoid code duplcation? |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 20 | static void fillRandomBits( int chars, char* bits ){ |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 21 | SkRandom rand(SkTime::GetMSecs()); |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 22 | |
| 23 | for (int i = 0; i < chars; ++i){ |
| 24 | bits[i] = rand.nextU(); |
| 25 | } |
skia.committer@gmail.com | 0d55dd7 | 2013-07-02 07:00:59 +0000 | [diff] [blame] | 26 | } |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 27 | |
| 28 | static void path_proc(char* bits, SkPath* path) { |
| 29 | SkPathUtils::BitsToPath_Path(path, bits, H, W, STRIDE); |
| 30 | } |
| 31 | |
| 32 | static void region_proc(char* bits, SkPath* path) { |
| 33 | SkPathUtils::BitsToPath_Region(path, bits, H, W, STRIDE); |
| 34 | } |
| 35 | |
| 36 | /// Emulates the mix of rects blitted by gmail during scrolling |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame^] | 37 | class PathUtilsBench : public Benchmark { |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 38 | typedef void (*Proc)(char*, SkPath*); |
| 39 | |
| 40 | Proc fProc; |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 41 | SkString fName; |
| 42 | char* bits[H * STRIDE]; |
skia.committer@gmail.com | 0d55dd7 | 2013-07-02 07:00:59 +0000 | [diff] [blame] | 43 | |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 44 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 45 | PathUtilsBench(Proc proc, const char name[]) { |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 46 | fProc = proc; |
| 47 | fName.printf("pathUtils_%s", name); |
skia.committer@gmail.com | 0d55dd7 | 2013-07-02 07:00:59 +0000 | [diff] [blame] | 48 | |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 49 | |
| 50 | } |
| 51 | |
| 52 | protected: |
| 53 | virtual const char* onGetName() { return fName.c_str(); } |
| 54 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 55 | virtual void onDraw(const int loops, SkCanvas* canvas) { |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 56 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 57 | for (int i = 0; i < loops; ++i){ |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 58 | //create a random 16x16 bitmap |
| 59 | fillRandomBits(H * STRIDE, (char*) &bits); |
skia.committer@gmail.com | 0d55dd7 | 2013-07-02 07:00:59 +0000 | [diff] [blame] | 60 | |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 61 | //use passed function pointer to handle it |
| 62 | SkPath path; |
| 63 | fProc( (char*) &bits, &path); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame^] | 68 | typedef Benchmark INHERITED; |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 71 | DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (path_proc, "path")); ) |
| 72 | DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (region_proc, "region")); ) |