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 | */ |
| 7 | #include "SkBenchmark.h" |
| 8 | #include "SkCanvas.h" |
| 9 | #include "SkPathUtils.h" |
| 10 | #include "SkRandom.h" |
| 11 | #include "SkTime.h" |
| 12 | #include "SkString.h" |
| 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 ){ |
robertphillips@google.com | d3976a1 | 2013-07-02 00:16:57 +0000 | [diff] [blame] | 21 | SkMWCRandom 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 |
| 37 | class PathUtilsBench : public SkBenchmark { |
| 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 | enum { N = SkBENCHLOOP(20) }; |
| 45 | |
| 46 | public: |
| 47 | PathUtilsBench(void* param, Proc proc, const char name[]) : INHERITED(param) { |
| 48 | fProc = proc; |
| 49 | fName.printf("pathUtils_%s", name); |
skia.committer@gmail.com | 0d55dd7 | 2013-07-02 07:00:59 +0000 | [diff] [blame] | 50 | |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 51 | |
| 52 | } |
| 53 | |
| 54 | protected: |
| 55 | virtual const char* onGetName() { return fName.c_str(); } |
| 56 | |
| 57 | virtual void onDraw(SkCanvas* canvas) { |
| 58 | |
| 59 | for (int i = 0; i < N; ++i){ |
| 60 | //create a random 16x16 bitmap |
| 61 | fillRandomBits(H * STRIDE, (char*) &bits); |
skia.committer@gmail.com | 0d55dd7 | 2013-07-02 07:00:59 +0000 | [diff] [blame] | 62 | |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 63 | //use passed function pointer to handle it |
| 64 | SkPath path; |
| 65 | fProc( (char*) &bits, &path); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | typedef SkBenchmark INHERITED; |
| 71 | }; |
| 72 | |
skia.committer@gmail.com | 0d55dd7 | 2013-07-02 07:00:59 +0000 | [diff] [blame] | 73 | static SkBenchmark* PU_path(void* p) { return SkNEW_ARGS(PathUtilsBench, (p, path_proc, "path")); } |
| 74 | static SkBenchmark* PU_region(void* p) { return SkNEW_ARGS(PathUtilsBench, (p, region_proc, "region")); } |
commit-bot@chromium.org | 064779a | 2013-07-01 17:50:29 +0000 | [diff] [blame] | 75 | |
| 76 | static BenchRegistry PU_Path(PU_path); |
| 77 | static BenchRegistry PU_Region(PU_region); |