| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBenchmark.h" | 7 #include "Benchmark.h" |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkPathUtils.h" | 9 #include "SkPathUtils.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| 11 #include "SkString.h" |
| 11 #include "SkTime.h" | 12 #include "SkTime.h" |
| 12 #include "SkString.h" | |
| 13 | 13 |
| 14 #define H 16 | 14 #define H 16 |
| 15 #define W 16 | 15 #define W 16 |
| 16 #define STRIDE 2 | 16 #define STRIDE 2 |
| 17 | 17 |
| 18 //this function is redefined for sample, test, and bench. is there anywhere | 18 //this function is redefined for sample, test, and bench. is there anywhere |
| 19 // I can put it to avoid code duplcation? | 19 // I can put it to avoid code duplcation? |
| 20 static void fillRandomBits( int chars, char* bits ){ | 20 static void fillRandomBits( int chars, char* bits ){ |
| 21 SkRandom rand(SkTime::GetMSecs()); | 21 SkRandom rand(SkTime::GetMSecs()); |
| 22 | 22 |
| 23 for (int i = 0; i < chars; ++i){ | 23 for (int i = 0; i < chars; ++i){ |
| 24 bits[i] = rand.nextU(); | 24 bits[i] = rand.nextU(); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 static void path_proc(char* bits, SkPath* path) { | 28 static void path_proc(char* bits, SkPath* path) { |
| 29 SkPathUtils::BitsToPath_Path(path, bits, H, W, STRIDE); | 29 SkPathUtils::BitsToPath_Path(path, bits, H, W, STRIDE); |
| 30 } | 30 } |
| 31 | 31 |
| 32 static void region_proc(char* bits, SkPath* path) { | 32 static void region_proc(char* bits, SkPath* path) { |
| 33 SkPathUtils::BitsToPath_Region(path, bits, H, W, STRIDE); | 33 SkPathUtils::BitsToPath_Region(path, bits, H, W, STRIDE); |
| 34 } | 34 } |
| 35 | 35 |
| 36 /// Emulates the mix of rects blitted by gmail during scrolling | 36 /// Emulates the mix of rects blitted by gmail during scrolling |
| 37 class PathUtilsBench : public SkBenchmark { | 37 class PathUtilsBench : public Benchmark { |
| 38 typedef void (*Proc)(char*, SkPath*); | 38 typedef void (*Proc)(char*, SkPath*); |
| 39 | 39 |
| 40 Proc fProc; | 40 Proc fProc; |
| 41 SkString fName; | 41 SkString fName; |
| 42 char* bits[H * STRIDE]; | 42 char* bits[H * STRIDE]; |
| 43 | 43 |
| 44 public: | 44 public: |
| 45 PathUtilsBench(Proc proc, const char name[]) { | 45 PathUtilsBench(Proc proc, const char name[]) { |
| 46 fProc = proc; | 46 fProc = proc; |
| 47 fName.printf("pathUtils_%s", name); | 47 fName.printf("pathUtils_%s", name); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 58 //create a random 16x16 bitmap | 58 //create a random 16x16 bitmap |
| 59 fillRandomBits(H * STRIDE, (char*) &bits); | 59 fillRandomBits(H * STRIDE, (char*) &bits); |
| 60 | 60 |
| 61 //use passed function pointer to handle it | 61 //use passed function pointer to handle it |
| 62 SkPath path; | 62 SkPath path; |
| 63 fProc( (char*) &bits, &path); | 63 fProc( (char*) &bits, &path); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 typedef SkBenchmark INHERITED; | 68 typedef Benchmark INHERITED; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (path_proc, "path")); ) | 71 DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (path_proc, "path")); ) |
| 72 DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (region_proc, "region")); ) | 72 DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (region_proc, "region")); ) |
| OLD | NEW |