OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 static SkPicture* rerecord(const SkPicture& src, bool skr) { | 39 static SkPicture* rerecord(const SkPicture& src, bool skr) { |
40 SkTileGridFactory::TileGridInfo info; | 40 SkTileGridFactory::TileGridInfo info; |
41 info.fTileInterval.set(FLAGS_tile, FLAGS_tile); | 41 info.fTileInterval.set(FLAGS_tile, FLAGS_tile); |
42 info.fMargin.setEmpty(); | 42 info.fMargin.setEmpty(); |
43 info.fOffset.setZero(); | 43 info.fOffset.setZero(); |
44 SkTileGridFactory factory(info); | 44 SkTileGridFactory factory(info); |
45 | 45 |
46 SkPictureRecorder recorder; | 46 SkPictureRecorder recorder; |
47 src.draw(skr ? recorder.EXPERIMENTAL_beginRecording(src.cullRect().width(), | 47 src.playback(skr ? recorder.EXPERIMENTAL_beginRecording(src.cullRect().width
(), |
48 src.cullRect().height(),
| 48 src.cullRect().heigh
t(), |
49 &factory) | 49 &factory) |
50 : recorder. DEPRECATED_beginRecording(src.cullRect().width(), | 50 : recorder. DEPRECATED_beginRecording(src.cullRect().width
(), |
51 src.cullRect().height(),
| 51 src.cullRect().heigh
t(), |
52 &factory)); | 52 &factory)); |
53 return recorder.endRecording(); | 53 return recorder.endRecording(); |
54 } | 54 } |
55 | 55 |
56 static void bench(SkPMColor* scratch, const SkPicture& src, const char* name) { | 56 static void bench(SkPMColor* scratch, const SkPicture& src, const char* name) { |
57 SkAutoTUnref<const SkPicture> picture(rerecord(src, FLAGS_skr)); | 57 SkAutoTUnref<const SkPicture> picture(rerecord(src, FLAGS_skr)); |
58 | 58 |
59 SkAutoTDelete<SkCanvas> canvas( | 59 SkAutoTDelete<SkCanvas> canvas( |
60 SkCanvas::NewRasterDirectN32(SkScalarCeilToInt(src.cullRect().width()), | 60 SkCanvas::NewRasterDirectN32(SkScalarCeilToInt(src.cullRect().width()), |
61 SkScalarCeilToInt(src.cullRect().height()), | 61 SkScalarCeilToInt(src.cullRect().height()), |
62 scratch, | 62 scratch, |
63 SkScalarCeilToInt(src.cullRect().width()) *
sizeof(SkPMColor))); | 63 SkScalarCeilToInt(src.cullRect().width()) *
sizeof(SkPMColor))); |
64 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); | 64 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); |
65 | 65 |
66 // Draw once to warm any caches. The first sample otherwise can be very noi
sy. | 66 // Draw once to warm any caches. The first sample otherwise can be very noi
sy. |
67 picture->draw(canvas.get()); | 67 picture->playback(canvas.get()); |
68 | 68 |
69 WallTimer timer; | 69 WallTimer timer; |
70 const double scale = timescale(); | 70 const double scale = timescale(); |
71 SkAutoTMalloc<double> samples(FLAGS_samples); | 71 SkAutoTMalloc<double> samples(FLAGS_samples); |
72 for (int i = 0; i < FLAGS_samples; i++) { | 72 for (int i = 0; i < FLAGS_samples; i++) { |
73 // We assume timer overhead (typically, ~30ns) is insignificant | 73 // We assume timer overhead (typically, ~30ns) is insignificant |
74 // compared to draw runtime (at least ~100us, usually several ms). | 74 // compared to draw runtime (at least ~100us, usually several ms). |
75 timer.start(); | 75 timer.start(); |
76 picture->draw(canvas.get()); | 76 picture->playback(canvas.get()); |
77 timer.end(); | 77 timer.end(); |
78 samples[i] = timer.fWall * scale; | 78 samples[i] = timer.fWall * scale; |
79 } | 79 } |
80 | 80 |
81 Stats stats(samples.get(), FLAGS_samples); | 81 Stats stats(samples.get(), FLAGS_samples); |
82 if (FLAGS_verbose == 0) { | 82 if (FLAGS_verbose == 0) { |
83 printf("%g\t%s\n", stats.min, name); | 83 printf("%g\t%s\n", stats.min, name); |
84 } else if (FLAGS_verbose == 1) { | 84 } else if (FLAGS_verbose == 1) { |
85 // Get a rough idea of how noisy the measurements were. | 85 // Get a rough idea of how noisy the measurements were. |
86 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; | 86 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 bench(scratch.get(), *src, filename.c_str()); | 140 bench(scratch.get(), *src, filename.c_str()); |
141 } | 141 } |
142 return failed ? 1 : 0; | 142 return failed ? 1 : 0; |
143 } | 143 } |
144 | 144 |
145 #if !defined SK_BUILD_FOR_IOS | 145 #if !defined SK_BUILD_FOR_IOS |
146 int main(int argc, char * const argv[]) { | 146 int main(int argc, char * const argv[]) { |
147 return tool_main(argc, (char**) argv); | 147 return tool_main(argc, (char**) argv); |
148 } | 148 } |
149 #endif | 149 #endif |
OLD | NEW |