| 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 <ctype.h> | 8 #include <ctype.h> |
| 9 | 9 |
| 10 #include "Benchmark.h" | 10 #include "Benchmark.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 return loops; | 106 return loops; |
| 107 } | 107 } |
| 108 | 108 |
| 109 #if SK_SUPPORT_GPU | 109 #if SK_SUPPORT_GPU |
| 110 static int gpu_bench(SkGLContextHelper* gl, | 110 static int gpu_bench(SkGLContextHelper* gl, |
| 111 Benchmark* bench, | 111 Benchmark* bench, |
| 112 SkCanvas* canvas, | 112 SkCanvas* canvas, |
| 113 double* samples) { | 113 double* samples) { |
| 114 // Make sure we're done with whatever came before. | 114 // Make sure we're done with whatever came before. |
| 115 SK_GL(*gl, Finish); | 115 SK_GL(*gl, Finish()); |
| 116 | 116 |
| 117 // First, figure out how many loops it'll take to get a frame up to FLAGS_gp
uMs. | 117 // First, figure out how many loops it'll take to get a frame up to FLAGS_gp
uMs. |
| 118 int loops = 1; | 118 int loops = 1; |
| 119 double elapsed = 0; | 119 double elapsed = 0; |
| 120 do { | 120 do { |
| 121 loops *= 2; | 121 loops *= 2; |
| 122 // If the GPU lets frames lag at all, we need to make sure we're timing | 122 // If the GPU lets frames lag at all, we need to make sure we're timing |
| 123 // _this_ round, not still timing last round. We force this by looping | 123 // _this_ round, not still timing last round. We force this by looping |
| 124 // more times than any reasonable GPU will allow frames to lag. | 124 // more times than any reasonable GPU will allow frames to lag. |
| 125 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { | 125 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
| 126 elapsed = time(loops, bench, canvas, gl); | 126 elapsed = time(loops, bench, canvas, gl); |
| 127 } | 127 } |
| 128 } while (elapsed < FLAGS_gpuMs); | 128 } while (elapsed < FLAGS_gpuMs); |
| 129 | 129 |
| 130 // We've overshot at least a little. Scale back linearly. | 130 // We've overshot at least a little. Scale back linearly. |
| 131 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); | 131 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); |
| 132 | 132 |
| 133 // Might as well make sure we're not still timing our calibration. | 133 // Might as well make sure we're not still timing our calibration. |
| 134 SK_GL(*gl, Finish); | 134 SK_GL(*gl, Finish()); |
| 135 | 135 |
| 136 // Pretty much the same deal as the calibration: do some warmup to make | 136 // Pretty much the same deal as the calibration: do some warmup to make |
| 137 // sure we're timing steady-state pipelined frames. | 137 // sure we're timing steady-state pipelined frames. |
| 138 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { | 138 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
| 139 time(loops, bench, canvas, gl); | 139 time(loops, bench, canvas, gl); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Now, actually do the timing! | 142 // Now, actually do the timing! |
| 143 for (int i = 0; i < FLAGS_samples; i++) { | 143 for (int i = 0; i < FLAGS_samples; i++) { |
| 144 samples[i] = time(loops, bench, canvas, gl) / loops; | 144 samples[i] = time(loops, bench, canvas, gl) / loops; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 287 } |
| 288 | 288 |
| 289 return 0; | 289 return 0; |
| 290 } | 290 } |
| 291 | 291 |
| 292 #if !defined SK_BUILD_FOR_IOS | 292 #if !defined SK_BUILD_FOR_IOS |
| 293 int main(int argc, char * const argv[]) { | 293 int main(int argc, char * const argv[]) { |
| 294 return tool_main(argc, (char**) argv); | 294 return tool_main(argc, (char**) argv); |
| 295 } | 295 } |
| 296 #endif | 296 #endif |
| OLD | NEW |